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 f5dd84df..446a8fd5 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 @@ -21,6 +21,7 @@ import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.ListItemType; +import one.nem.lacerta.utils.LacertaLogger; @AndroidEntryPoint public class LacertaSelectDirDialog extends DialogFragment { @@ -28,6 +29,9 @@ public class LacertaSelectDirDialog extends DialogFragment { @Inject LacertaLibrary lacertaLibrary; + @Inject + LacertaLogger logger; + private SelectDirDialogItemAdapter adapter; private RecyclerView recyclerView; @@ -83,14 +87,29 @@ public class LacertaSelectDirDialog extends DialogFragment { lacertaLibrary.getFolderList(targetDirId).thenAccept(libraryItemPage -> { getActivity().runOnUiThread(() -> { int currentCount = adapter.getItemCount(); - if (targetDirId == null) { // When root folder + String currentDirId = adapter.getCurrentId(); + if (currentDirId == null && libraryItemPage.getPageId() != null) { + // Rootから推移してきた場合 adapter.setListItems(libraryItemPage); adapter.notifyItemRangeRemoved(0, currentCount); adapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size()); - } else { // When child folder + } else if (libraryItemPage.getPageId() == null) { + // Rootに推移した場合 + adapter.setListItems(libraryItemPage); + adapter.notifyItemRangeRemoved(0, currentCount); + adapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size()); + } else if (currentDirId != null && libraryItemPage.getPageId() != null) { + // 通常の遷移 adapter.setListItems(libraryItemPage); adapter.notifyItemRangeRemoved(1, currentCount); adapter.notifyItemRangeInserted(1, libraryItemPage.getListItems().size()); + } else { + // その他の遷移(安全側に倒すため全アイテム更新) + logger.warn("LacertaSelectDirDialog", "Unknown transition."); + logger.warn("LacertaSelectDirDialog", "currentDirId: " + currentDirId + ", libraryItemPage.getPageId(): " + libraryItemPage.getPageId()); + adapter.setListItems(libraryItemPage); + adapter.notifyItemRangeRemoved(0, currentCount); + adapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size()); } }); }); 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 dca3de3e..4cbe7d8e 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 @@ -58,6 +58,10 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter