mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-22 16:03:15 +00:00
LibraryItemPageを使用するように変更, 戻るアクションを実装
This commit is contained in:
parent
04bd081d99
commit
0128cecfae
|
@ -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();
|
||||
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());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<SelectDirDialogItemAdapter.SelectDirDialogItemViewHolder> {
|
||||
|
||||
ArrayList<ListItem> listItems;
|
||||
|
||||
private LibraryItemPage libraryItemPage;
|
||||
LacertaSelectDirDialogEventListener listener;
|
||||
|
||||
public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setListItems(ArrayList<ListItem> 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<SelectDirDi
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(SelectDirDialogItemViewHolder holder, int position) {
|
||||
ListItem listItem = listItems.get(position);
|
||||
ListItem listItem = libraryItemPage.getListItems().get(position);
|
||||
holder.title.setText(listItem.getTitle());
|
||||
holder.description.setText(listItem.getDescription());
|
||||
if(listItem.getItemType() == ListItemType.ITEM_TYPE_ACTION_BACK) {
|
||||
holder.itemView.setOnClickListener(v -> 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<SelectDirDi
|
|||
|
||||
@Override
|
||||
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 {
|
||||
|
|
|
@ -21,7 +21,7 @@ public interface LacertaLibrary {
|
|||
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit, int offset);
|
||||
|
||||
// Get Folder List
|
||||
CompletableFuture<ArrayList<ListItem>> getFolderList(String parentId);
|
||||
CompletableFuture<LibraryItemPage> getFolderList(String parentId);
|
||||
|
||||
// Create Folder
|
||||
CompletableFuture<String> createFolder(String parentId, String name);
|
||||
|
|
|
@ -128,13 +128,26 @@ public class LacertaLibraryImpl implements LacertaLibrary {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ArrayList<ListItem>> getFolderList(String parentId) {
|
||||
public CompletableFuture<LibraryItemPage> getFolderList(String targetDirId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
LibraryItemPage libraryItemPage = new LibraryItemPage();
|
||||
|
||||
List<FolderEntity> 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<ListItem> listItems = new ArrayList<>();
|
||||
|
@ -148,7 +161,10 @@ public class LacertaLibraryImpl implements LacertaLibrary {
|
|||
listItems.add(listItem);
|
||||
}
|
||||
|
||||
return listItems;
|
||||
|
||||
libraryItemPage.setListItems(listItems);
|
||||
|
||||
return libraryItemPage;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user