From 92167656fcfa0fa1454279489360674fcd464028 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 28 Jan 2024 13:12:03 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=86=E3=83=8A=E3=83=95?= =?UTF-8?q?=E3=83=A9=E3=82=B0=E3=83=A1=E3=83=B3=E3=83=88=E5=87=A6=E7=90=86?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../viewer/ViewerContainerFragment.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) 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 2f4ae1f3..c97d6e00 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 @@ -3,32 +3,61 @@ package one.nem.lacerta.component.viewer; import android.os.Bundle; import androidx.fragment.app.Fragment; +import androidx.viewpager2.widget.ViewPager2; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.data.LacertaLibrary; +import one.nem.lacerta.model.pref.ToxiDocumentModel; +import one.nem.lacerta.utils.LacertaLogger; + /** * A simple {@link Fragment} subclass. * Use the {@link ViewerContainerFragment#newInstance} factory method to * create an instance of this fragment. */ +@AndroidEntryPoint public class ViewerContainerFragment extends Fragment { + // Inject + + @Inject + LacertaLogger logger; + + @Inject + LacertaLibrary lacertaLibrary; + // Variables private String documentId; private String documentName; + private boolean hasCombined = false; public ViewerContainerFragment() { // Required empty public constructor } + public static ViewerContainerFragment newInstance(String documentId, String documentName, boolean hasCombined) { + ViewerContainerFragment fragment = new ViewerContainerFragment(); + Bundle args = new Bundle(); + fragment.setArguments(args); + args.putString("documentId", documentId); + args.putString("documentName", documentName); + args.putBoolean("hasCombined", hasCombined); + return fragment; + } + public static ViewerContainerFragment newInstance(String documentId, String documentName) { ViewerContainerFragment fragment = new ViewerContainerFragment(); Bundle args = new Bundle(); fragment.setArguments(args); args.putString("documentId", documentId); args.putString("documentName", documentName); + args.putBoolean("hasCombined", false); return fragment; } @@ -47,4 +76,26 @@ public class ViewerContainerFragment extends Fragment { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_viewer_container, container, false); } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + // Init view pager + ViewPager2 viewPager = view.findViewById(R.id.view_pager); + + // Init view pager adapter + ViewerViewPagerAdapter viewerViewPagerAdapter = new ViewerViewPagerAdapter(requireActivity()); + viewPager.setAdapter(viewerViewPagerAdapter); + + if (this.hasCombined) { + lacertaLibrary.getCombinedDocumentToxiList(documentId).thenAccept(combinedDocumentToxiList -> { + for (ToxiDocumentModel toxiDocumentModel : combinedDocumentToxiList) { + viewerViewPagerAdapter + .addFragment(ViewerBodyFragment.newInstance(toxiDocumentModel.getChildDocumentId(), toxiDocumentModel.getTitleCache()), + toxiDocumentModel.getTitleCache()); + } + }); + } + } } \ No newline at end of file