From 6e0c473c66ca98ad5f918ab0631eaf1cacdde108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 18:24:53 +0900 Subject: [PATCH] =?UTF-8?q?setupToolbar=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/library/LibraryPageFragment.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java index 957cd947..95e970ca 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java @@ -63,6 +63,7 @@ public class LibraryPageFragment extends Fragment { public LibraryPageFragment() { // Required empty public constructor } + public static LibraryPageFragment newInstance(String folderId) { LibraryPageFragment fragment = new LibraryPageFragment(); Bundle args = new Bundle(); @@ -169,6 +170,49 @@ public class LibraryPageFragment extends Fragment { } } }); + + } + + private void toolbarSetup(Toolbar toolbar, boolean showBackButton, String title, String subtitle) { + if (showBackButton) { + toolbar.setNavigationIcon(one.nem.lacerta.shared.ui.R.drawable.arrow_back_24px); + toolbar.setNavigationOnClickListener(v -> { + getParentFragmentManager().popBackStack(); + }); + } else { + toolbar.setNavigationIcon(null); + } + toolbar.setTitle(title); + if (subtitle != null) toolbar.setSubtitle(subtitle); + toolbar.inflateMenu(R.menu.dir_menu); + toolbar.setOnMenuItemClickListener(item -> { + if (item.getItemId() == R.id.menu_item_create_new_folder) { + createFolder(); + return true; + } else { + return false; + } + }); + } + + private void createFolder() { + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle("フォルダの作成"); + builder.setMessage("フォルダ名を入力してください"); + final android.widget.EditText input = new android.widget.EditText(getContext()); + input.setText("フォルダ名"); + builder.setView(input); + builder.setPositiveButton("作成", (dialog, which) -> { + lacertaLibrary.createFolder(null, input.getText().toString()).thenAccept(folderId -> { + logger.debug("LibraryTopFragment", "folderId: " + folderId); + }); + // Refresh + updateItem(); + }); + builder.setNegativeButton("キャンセル", (dialog, which) -> { + dialog.cancel(); + }); + builder.show(); } @Override