This commit is contained in:
ろむねこ 2024-01-25 14:50:27 +09:00
parent 58f9d81555
commit 5f89955d80
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
3 changed files with 26 additions and 3 deletions

View File

@ -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());
}
});
});

View File

@ -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;

View File

@ -136,7 +136,7 @@ public class LacertaLibraryImpl implements LacertaLibrary {
if (targetDirId == null) { // When root folder
folderEntities = database.folderDao().findRootFolders();
libraryItemPage.setParentId(null);
libraryItemPage.setPageId(targetDirId);
libraryItemPage.setPageId(null);
libraryItemPage.setPageTitle("ライブラリ");
} else {
folderEntities = database.folderDao().findByParentId(targetDirId);