diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java index 58d02f06..7e07448b 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java @@ -46,9 +46,16 @@ public class LacertaSelectDirDialog extends DialogFragment { this.recyclerView = view.findViewById(R.id.select_dir_recycler_view); this.current_dir_text_view = view.findViewById(R.id.current_dir_text_view); - this.adapter = new SelectDirDialogItemAdapter((name, itemId) -> { - Toast.makeText(getContext(), "Called:" + name, Toast.LENGTH_SHORT).show(); - showRecyclerViewItem(itemId); + this.adapter = new SelectDirDialogItemAdapter(new LacertaSelectDirDialogEventListener() { + @Override + public void onDirSelected(String name, String itemId) { + showRecyclerViewItem(itemId); + } + + @Override + public void onBackSelected(String parentId) { + showRecyclerViewItem(parentId); + } }); this.recyclerView.setAdapter(this.adapter); @@ -63,8 +70,8 @@ public class LacertaSelectDirDialog extends DialogFragment { return builder.create(); } - private void showRecyclerViewItem(String parent) { - lacertaLibrary.getPublicPath(parent, ListItemType.ITEM_TYPE_FOLDER).thenAccept(publicPath -> { + private void showRecyclerViewItem(String targetDirId) { + lacertaLibrary.getPublicPath(targetDirId, ListItemType.ITEM_TYPE_FOLDER).thenAccept(publicPath -> { getActivity().runOnUiThread(() -> { if (publicPath != null) { current_dir_text_view.setText("/" + publicPath.getStringPath()); // TODO-rca: PublicPathの実装を修正する @@ -73,12 +80,12 @@ public class LacertaSelectDirDialog extends DialogFragment { } }); }); - lacertaLibrary.getFolderList(parent).thenAccept(listItems -> { + lacertaLibrary.getFolderList(targetDirId).thenAccept(libraryItemPage -> { getActivity().runOnUiThread(() -> { int currentCount = adapter.getItemCount(); - adapter.notifyItemRangeRemoved(0, currentCount); - adapter.setListItems(listItems); - adapter.notifyItemRangeInserted(0, listItems.size()); + adapter.notifyItemRangeRemoved(1, currentCount); // Backボタンを除くすべてのアイテムを削除 + adapter.setListItems(libraryItemPage); + adapter.notifyItemRangeInserted(1, libraryItemPage.getListItems().size()); }); }); } diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialogEventListener.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialogEventListener.java index 27641e7c..31954b32 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialogEventListener.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialogEventListener.java @@ -2,5 +2,5 @@ package one.nem.lacerta.component.common; public interface LacertaSelectDirDialogEventListener { void onDirSelected(String name, String itemId); - void onBackSelected(); + void onBackSelected(String parentId); } diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java b/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java index 1a34fa22..fea64c0f 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java @@ -10,23 +10,23 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; +import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItemType; public class SelectDirDialogItemAdapter extends RecyclerView.Adapter { - ArrayList listItems; + + private LibraryItemPage libraryItemPage; LacertaSelectDirDialogEventListener listener; public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) { this.listener = listener; } - public void setListItems(ArrayList listItems) { - // 戻るアクションを追加 - this.listItems.add(0, new ListItem("戻る", " ", ListItemType.ITEM_TYPE_ACTION_BACK, null)); - - this.listItems.addAll(listItems); + public void setListItems(LibraryItemPage libraryItemPage) { + this.libraryItemPage = libraryItemPage; + this.libraryItemPage.getListItems().add(0, new ListItem("戻る", " ", ListItemType.ITEM_TYPE_ACTION_BACK, null)); } @NonNull @@ -38,11 +38,11 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter listener.onBackSelected()); + holder.itemView.setOnClickListener(v -> listener.onBackSelected(this.libraryItemPage.getParentId())); } else { holder.itemView.setOnClickListener(v -> listener.onDirSelected(listItem.getTitle(), listItem.getItemId())); } @@ -50,7 +50,7 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter getLibraryPage(String pageId, int limit, int offset); // Get Folder List - CompletableFuture> getFolderList(String parentId); + CompletableFuture getFolderList(String parentId); // Create Folder CompletableFuture createFolder(String parentId, String name); 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 139cf2bf..ac2d08f0 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 @@ -128,13 +128,26 @@ public class LacertaLibraryImpl implements LacertaLibrary { } @Override - public CompletableFuture> getFolderList(String parentId) { + public CompletableFuture getFolderList(String targetDirId) { return CompletableFuture.supplyAsync(() -> { + LibraryItemPage libraryItemPage = new LibraryItemPage(); + List folderEntities; - if (parentId == null) { // When root folder + if (targetDirId == null) { // When root folder folderEntities = database.folderDao().findRootFolders(); + libraryItemPage.setParentId(null); + libraryItemPage.setPageId(targetDirId); + libraryItemPage.setPageTitle("ライブラリ"); } else { - folderEntities = database.folderDao().findByParentId(parentId); + folderEntities = database.folderDao().findByParentId(targetDirId); + FolderEntity folderEntity = database.folderDao().findById(targetDirId); + if (folderEntity == null) { + logger.warn("LacertaLibraryImpl", targetDirId + " is not found."); + return null; + } + libraryItemPage.setParentId(folderEntity.parentId); + libraryItemPage.setPageId(folderEntity.id); + libraryItemPage.setPageTitle(folderEntity.name); } ArrayList listItems = new ArrayList<>(); @@ -148,7 +161,10 @@ public class LacertaLibraryImpl implements LacertaLibrary { listItems.add(listItem); } - return listItems; + + libraryItemPage.setListItems(listItems); + + return libraryItemPage; }); }