フォルダを作成できるように

This commit is contained in:
ろむねこ 2024-01-22 11:55:38 +09:00
parent b2c6085933
commit 81fa259985
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 38 additions and 4 deletions

View File

@ -157,12 +157,11 @@ public class LacertaLibraryImpl implements LacertaLibrary {
} else {
publicPath = new PublicPath().resolve(parentFolderEntity.publicPath);
}
publicPath = publicPath.resolve(name);
FolderEntity folderEntity = new FolderEntity();
folderEntity.id = UUID.randomUUID().toString();
folderEntity.name = name;
folderEntity.publicPath = publicPath.toString();
folderEntity.publicPath = publicPath.getStringPath();
database.folderDao().insert(folderEntity);
return folderEntity.id;
});

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@ -51,6 +52,10 @@ public class LibraryTopFragment extends Fragment {
@Inject
LacertaLogger logger;
ListItemAdapter listItemAdapter;
int currentTotalItemCount = 0;
public LibraryTopFragment() {
// Required empty public constructor
}
@ -83,7 +88,7 @@ public class LibraryTopFragment extends Fragment {
RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view);
ListItemAdapter listItemAdapter = new ListItemAdapter(documentId -> {
this.listItemAdapter = new ListItemAdapter(documentId -> {
Toast.makeText(getContext(), documentId, Toast.LENGTH_SHORT).show();
});
recyclerView.setAdapter(listItemAdapter);
@ -92,8 +97,9 @@ public class LibraryTopFragment extends Fragment {
lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> {
logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size());
listItemAdapter.setLibraryItemPage(libraryItemPage);
this.currentTotalItemCount = libraryItemPage.getListItems().size();
getActivity().runOnUiThread(() -> {
listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1);
listItemAdapter.notifyItemRangeInserted(0, this.currentTotalItemCount - 1);
});
});
}
@ -103,4 +109,33 @@ public class LibraryTopFragment extends Fragment {
inflater.inflate(R.menu.dir_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
// Selected
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.menu_item_create_new_folder) {
lacertaLibrary.createFolder(null, "New Folder").thenAccept(folderId -> {
logger.debug("LibraryTopFragment", "folderId: " + folderId);
});
// Refresh
updateItem();
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
private void updateItem() {
lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> {
logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size());
getActivity().runOnUiThread(() -> {
listItemAdapter.notifyItemRangeRemoved(0, this.currentTotalItemCount - 1);
});
listItemAdapter.setLibraryItemPage(libraryItemPage);
getActivity().runOnUiThread(() -> {
listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1);
});
this.currentTotalItemCount = libraryItemPage.getListItems().size();
});
}
}