From 87099ae6939ceb647053ff0ea83b357b9cde7e8a Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 23 Jan 2024 03:22:01 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AC=E3=82=A4=E3=82=A2=E3=82=A6=E3=83=88,?= =?UTF-8?q?=20ToolBar=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/feature/home/HomeTopFragment.java | 29 +++++++++++++++---- .../src/main/res/layout/fragment_home_top.xml | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java index a5d26c13..396c1dba 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java @@ -17,6 +17,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; +import androidx.navigation.Navigation; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -71,7 +72,6 @@ public class HomeTopFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_home_top, container, false); - setHasOptionsMenu(true); return view; } @@ -81,6 +81,8 @@ public class HomeTopFragment extends Fragment { RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view); + Toolbar toolbar = view.findViewById(R.id.home_toolbar); + toolbarSetup(toolbar, false, "ホーム"); ListItemAdapter listItemAdapter = new ListItemAdapter(documentId -> { Log.d("HomeTopFragment", "onViewCreated: " + documentId); @@ -99,10 +101,27 @@ public class HomeTopFragment extends Fragment { }); } - @Override - public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { - inflater.inflate(R.menu.drawer_menu, menu); - super.onCreateOptionsMenu(menu, inflater); + /** + * ToolbarをInitする + * + * @param toolbar Toolbar + * @param showBackButton 戻るボタンを表示するか + * @param title タイトル + */ + private void toolbarSetup(Toolbar toolbar, boolean showBackButton, String title) { + getActivity().runOnUiThread(() -> { + if (showBackButton) { + toolbar.setNavigationIcon(one.nem.lacerta.shared.ui.R.drawable.arrow_back_24px); + toolbar.setNavigationOnClickListener(v -> { + //this.libraryItemPage = lacertaLibrary.getLibraryPage(this.libraryItemPage.getParentId(), 10).join(); + // Back + Navigation.findNavController(requireView()).popBackStack(); + }); + } else { + toolbar.setNavigationIcon(null); + } + toolbar.setTitle(title); + }); } } diff --git a/feature/home/src/main/res/layout/fragment_home_top.xml b/feature/home/src/main/res/layout/fragment_home_top.xml index 3fc0b723..e3b70845 100644 --- a/feature/home/src/main/res/layout/fragment_home_top.xml +++ b/feature/home/src/main/res/layout/fragment_home_top.xml @@ -29,7 +29,7 @@ app:layout_scrollFlags="scroll|exitUntilCollapsed">