LibraryItemPageを使用するように変更, 戻るアクションを実装

This commit is contained in:
ろむねこ 2024-01-25 14:28:36 +09:00
parent 04bd081d99
commit 0128cecfae
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
5 changed files with 47 additions and 24 deletions

View File

@ -46,9 +46,16 @@ public class LacertaSelectDirDialog extends DialogFragment {
this.recyclerView = view.findViewById(R.id.select_dir_recycler_view); this.recyclerView = view.findViewById(R.id.select_dir_recycler_view);
this.current_dir_text_view = view.findViewById(R.id.current_dir_text_view); this.current_dir_text_view = view.findViewById(R.id.current_dir_text_view);
this.adapter = new SelectDirDialogItemAdapter((name, itemId) -> { this.adapter = new SelectDirDialogItemAdapter(new LacertaSelectDirDialogEventListener() {
Toast.makeText(getContext(), "Called:" + name, Toast.LENGTH_SHORT).show(); @Override
showRecyclerViewItem(itemId); public void onDirSelected(String name, String itemId) {
showRecyclerViewItem(itemId);
}
@Override
public void onBackSelected(String parentId) {
showRecyclerViewItem(parentId);
}
}); });
this.recyclerView.setAdapter(this.adapter); this.recyclerView.setAdapter(this.adapter);
@ -63,8 +70,8 @@ public class LacertaSelectDirDialog extends DialogFragment {
return builder.create(); return builder.create();
} }
private void showRecyclerViewItem(String parent) { private void showRecyclerViewItem(String targetDirId) {
lacertaLibrary.getPublicPath(parent, ListItemType.ITEM_TYPE_FOLDER).thenAccept(publicPath -> { lacertaLibrary.getPublicPath(targetDirId, ListItemType.ITEM_TYPE_FOLDER).thenAccept(publicPath -> {
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
if (publicPath != null) { if (publicPath != null) {
current_dir_text_view.setText("/" + publicPath.getStringPath()); // TODO-rca: PublicPathの実装を修正する 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(() -> { getActivity().runOnUiThread(() -> {
int currentCount = adapter.getItemCount(); int currentCount = adapter.getItemCount();
adapter.notifyItemRangeRemoved(0, currentCount); adapter.notifyItemRangeRemoved(1, currentCount); // Backボタンを除くすべてのアイテムを削除
adapter.setListItems(listItems); adapter.setListItems(libraryItemPage);
adapter.notifyItemRangeInserted(0, listItems.size()); adapter.notifyItemRangeInserted(1, libraryItemPage.getListItems().size());
}); });
}); });
} }

View File

@ -2,5 +2,5 @@ package one.nem.lacerta.component.common;
public interface LacertaSelectDirDialogEventListener { public interface LacertaSelectDirDialogEventListener {
void onDirSelected(String name, String itemId); void onDirSelected(String name, String itemId);
void onBackSelected(); void onBackSelected(String parentId);
} }

View File

@ -10,23 +10,23 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import one.nem.lacerta.model.LibraryItemPage;
import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItem;
import one.nem.lacerta.model.ListItemType; import one.nem.lacerta.model.ListItemType;
public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.SelectDirDialogItemViewHolder> { public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.SelectDirDialogItemViewHolder> {
ArrayList<ListItem> listItems;
private LibraryItemPage libraryItemPage;
LacertaSelectDirDialogEventListener listener; LacertaSelectDirDialogEventListener listener;
public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) { public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) {
this.listener = listener; this.listener = listener;
} }
public void setListItems(ArrayList<ListItem> listItems) { public void setListItems(LibraryItemPage libraryItemPage) {
// 戻るアクションを追加 this.libraryItemPage = libraryItemPage;
this.listItems.add(0, new ListItem("戻る", " ", ListItemType.ITEM_TYPE_ACTION_BACK, null)); this.libraryItemPage.getListItems().add(0, new ListItem("戻る", " ", ListItemType.ITEM_TYPE_ACTION_BACK, null));
this.listItems.addAll(listItems);
} }
@NonNull @NonNull
@ -38,11 +38,11 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
@Override @Override
public void onBindViewHolder(SelectDirDialogItemViewHolder holder, int position) { public void onBindViewHolder(SelectDirDialogItemViewHolder holder, int position) {
ListItem listItem = listItems.get(position); ListItem listItem = libraryItemPage.getListItems().get(position);
holder.title.setText(listItem.getTitle()); holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription()); holder.description.setText(listItem.getDescription());
if(listItem.getItemType() == ListItemType.ITEM_TYPE_ACTION_BACK) { if(listItem.getItemType() == ListItemType.ITEM_TYPE_ACTION_BACK) {
holder.itemView.setOnClickListener(v -> listener.onBackSelected()); holder.itemView.setOnClickListener(v -> listener.onBackSelected(this.libraryItemPage.getParentId()));
} else { } else {
holder.itemView.setOnClickListener(v -> listener.onDirSelected(listItem.getTitle(), listItem.getItemId())); holder.itemView.setOnClickListener(v -> listener.onDirSelected(listItem.getTitle(), listItem.getItemId()));
} }
@ -50,7 +50,7 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
@Override @Override
public int getItemCount() { public int getItemCount() {
return listItems == null ? 0 : listItems.size(); return this.libraryItemPage == null ? 0 : this.libraryItemPage.getListItems().size();
} }
public static class SelectDirDialogItemViewHolder extends RecyclerView.ViewHolder { public static class SelectDirDialogItemViewHolder extends RecyclerView.ViewHolder {

View File

@ -21,7 +21,7 @@ public interface LacertaLibrary {
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit, int offset); CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit, int offset);
// Get Folder List // Get Folder List
CompletableFuture<ArrayList<ListItem>> getFolderList(String parentId); CompletableFuture<LibraryItemPage> getFolderList(String parentId);
// Create Folder // Create Folder
CompletableFuture<String> createFolder(String parentId, String name); CompletableFuture<String> createFolder(String parentId, String name);

View File

@ -128,13 +128,26 @@ public class LacertaLibraryImpl implements LacertaLibrary {
} }
@Override @Override
public CompletableFuture<ArrayList<ListItem>> getFolderList(String parentId) { public CompletableFuture<LibraryItemPage> getFolderList(String targetDirId) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
LibraryItemPage libraryItemPage = new LibraryItemPage();
List<FolderEntity> folderEntities; List<FolderEntity> folderEntities;
if (parentId == null) { // When root folder if (targetDirId == null) { // When root folder
folderEntities = database.folderDao().findRootFolders(); folderEntities = database.folderDao().findRootFolders();
libraryItemPage.setParentId(null);
libraryItemPage.setPageId(targetDirId);
libraryItemPage.setPageTitle("ライブラリ");
} else { } 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<ListItem> listItems = new ArrayList<>(); ArrayList<ListItem> listItems = new ArrayList<>();
@ -148,7 +161,10 @@ public class LacertaLibraryImpl implements LacertaLibrary {
listItems.add(listItem); listItems.add(listItem);
} }
return listItems;
libraryItemPage.setListItems(listItems);
return libraryItemPage;
}); });
} }