From da78f5eef163db5bb9ee6d2a8b33fb46e0d87e03 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 02:00:32 +0900 Subject: [PATCH] =?UTF-8?q?Adapter=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=AB?= =?UTF-8?q?=E8=BF=BD=E5=BE=93,=20StreamAPI=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../viewer/ViewerContainerFragment.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 d8032868..be70a03d 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 @@ -20,6 +20,7 @@ import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; import java.util.ArrayList; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -120,18 +121,19 @@ public class ViewerContainerFragment extends Fragment { logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); lacertaLibrary.getCombinedDocumentToxiList(documentId).thenAccept(combinedDocumentToxiList -> { logger.debug("ViewerContainerFragment", "combinedDocumentToxiList: " + combinedDocumentToxiList.size()); - for (ToxiDocumentModel toxiDocumentModel : combinedDocumentToxiList) { - logger.debug("ViewerContainerFragment", "titleCache: " + toxiDocumentModel.getTitleCache()); - viewerViewPagerAdapter - .addFragment(ViewerBodyFragment.newInstance(toxiDocumentModel.getChildDocumentId(), toxiDocumentModel.getTitleCache()), - toxiDocumentModel.getTitleCache()); - } + ArrayList pageIdList = combinedDocumentToxiList.stream().map(ToxiDocumentModel::getChildDocumentId).collect(Collectors.toCollection(ArrayList::new)); + ArrayList pageTitleList = combinedDocumentToxiList.stream().map(ToxiDocumentModel::getTitleCache).collect(Collectors.toCollection(ArrayList::new)); + viewerViewPagerAdapter.setFragmentTargetIdList(pageIdList); + viewerViewPagerAdapter.setFragmentTitleList(pageTitleList); viewerViewPagerAdapter.notifyItemRangeChanged(0, combinedDocumentToxiList.size()); }); } else { logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); tabLayout.setVisibility(View.GONE); - viewerViewPagerAdapter.addFragment(ViewerBodyFragment.newInstance(documentId, documentName), documentName); + ArrayList pageIdList = new ArrayList<>(); + ArrayList pageTitleList = new ArrayList<>(); + pageIdList.add(documentId); + pageTitleList.add(documentName); viewerViewPagerAdapter.notifyItemRangeChanged(0, 1); } @@ -144,7 +146,7 @@ public class ViewerContainerFragment extends Fragment { ImageButton imageButton = customView.findViewById(R.id.tab_modify); imageButton.setOnClickListener(v -> { - Toast.makeText(getContext(), "Working!, Index:" + position, Toast.LENGTH_SHORT).show(); + }); tab.setCustomView(customView);