From 81fa259985ec2082abb73105449fe0bf935a3efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:55:38 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/data/impl/LacertaLibraryImpl.java | 3 +- .../feature/library/LibraryTopFragment.java | 39 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java index 7d7f7aaa..f2e87da9 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java @@ -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; }); diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java index 8dd366d8..7d35c9cb 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java @@ -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(); + }); + } }