From 0210bcaeb6b8a8a24aacbcac4e4c9f67255fcbad Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 28 Jan 2024 14:07:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB=E3=82=92?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/component/viewer/ViewerContainerFragment.java | 6 +++++- .../lacerta/component/viewer/ViewerViewPagerAdapter.java | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java index c868d27f..220e23fe 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java @@ -13,6 +13,7 @@ import android.widget.Toast; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; @@ -102,6 +103,10 @@ public class ViewerContainerFragment extends Fragment { ViewerViewPagerAdapter viewerViewPagerAdapter = new ViewerViewPagerAdapter(requireActivity()); viewPager.setAdapter(viewerViewPagerAdapter); + // Init tab layout + TabLayout tabLayout = view.findViewById(R.id.tab_layout); + new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(viewerViewPagerAdapter.getTabTitle(position))).attach(); + // Init toolbar Toolbar toolbar = view.findViewById(R.id.toolbar); initToolbar(toolbar, true, documentName); @@ -119,7 +124,6 @@ public class ViewerContainerFragment extends Fragment { }); } else { logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); - TabLayout tabLayout = view.findViewById(R.id.tab_layout); tabLayout.setVisibility(View.GONE); viewerViewPagerAdapter.addFragment(ViewerBodyFragment.newInstance(documentId, documentName), documentName); } diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java index cdf742b0..e3f998fe 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java @@ -1,6 +1,7 @@ package one.nem.lacerta.component.viewer; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -35,4 +36,9 @@ public class ViewerViewPagerAdapter extends FragmentStateAdapter { public int getItemCount() { return fragmentArrayList == null ? 0 : fragmentArrayList.size(); } + + @Nullable + public CharSequence getTabTitle(int position) { + return fragmentTitleList.get(position); + } }