This commit is contained in:
r-ca committed 2024-01-25 14:50:27 +09:00
1 parent 58f9d81555
commit 5f89955d80
3 files changed
+26 -3

No files matched your search

@@ -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());
}
});
});
@@ -58,6 +58,10 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
return this.libraryItemPage == null ? 0 : this.libraryItemPage.getListItems().size();
}
public String getCurrentId() {
return this.libraryItemPage == null ? null : this.libraryItemPage.getPageId();
}
public static class SelectDirDialogItemViewHolder extends RecyclerView.ViewHolder {
TextView title;