From 0fe0f5dd001c37505c2710b806ca576cde42feb8 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, 29 Jan 2024 13:20:44 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E9=81=A1=E3=82=8C=E3=81=AA=E3=81=84=E4=B8=8D=E5=85=B7?= =?UTF-8?q?=E5=90=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/viewer/ViewerBodyFragment.java | 23 +++++- .../viewer/ViewerContainerFragment.java | 80 ++++++++----------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java index f52576d4..db302a17 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java @@ -14,6 +14,8 @@ import android.widget.Toast; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import java.util.ArrayList; + import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; @@ -124,26 +126,41 @@ public class ViewerBodyFragment extends Fragment { builder.show(); } }); - recyclerView.setAdapter(viewerBodyAdapter); + + getActivity().runOnUiThread(() -> { + recyclerView.setAdapter(viewerBodyAdapter); + viewerBodyAdapter.notifyDataSetChanged(); + }); loadDocument(viewerBodyAdapter, documentId, revisionId); } private void loadDocument(ViewerBodyAdapter adapter, String documentId, String revisionId) { if (revisionId == null) { // load latest revision - document.getDocument(documentId).thenAccept(document -> { + document.getDocument(documentId).thenApply(document -> { getActivity().runOnUiThread(() -> { adapter.setPages(document.getPages()); adapter.notifyDataSetChanged(); }); + return null; }); } else { // load specified revision LacertaVcs vcs = lacertaVcsFactory.create(documentId); - document.getDocumentPageListByFileNameList(documentId, vcs.getDocumentPagePathListRev(revisionId).join()).thenAccept(documentPageList -> { +// document.getDocumentPageListByFileNameList(documentId, vcs.getDocumentPagePathListRev(revisionId).join()).thenApply(documentPageList -> { +// getActivity().runOnUiThread(() -> { +// adapter.setPages(documentPageList); +// adapter.notifyDataSetChanged(); +// }); +// return null; +// }); + + ArrayList fileNameList = vcs.getDocumentPagePathListRev(revisionId).join(); + document.getDocumentPageListByFileNameList(documentId, fileNameList).thenApply(documentPageList -> { getActivity().runOnUiThread(() -> { adapter.setPages(documentPageList); adapter.notifyDataSetChanged(); }); + return null; }); } } 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 c6647cb4..5e16662b 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 @@ -145,54 +145,44 @@ public class ViewerContainerFragment extends Fragment { if (this.revId != null) { // Revが指定されている場合 LacertaVcs lacertaVcs = lacertaVcsFactory.create(documentId); - lacertaVcs.getDocumentPagePathListRev(this.revId).thenApply(pagePathList -> { - logger.debug("ViewerContainerFragment", "pagePathList: " + pagePathList.size()); - document.getDocumentPageListByFileNameList(this.documentId, pagePathList).thenApply(pageList -> { - logger.debug("ViewerContainerFragment", "pageList: " + pageList.size()); - // 暫定: 履歴を遡って表示している場合は結合を無視する(処理自体は単純だけどUI側の対応をする時間がないので) - tabLayout.setVisibility(View.GONE); - viewerViewPagerAdapter.setFragmentTargetIdList(new ArrayList(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする - viewerViewPagerAdapter.setFragmentTitleList(new ArrayList(){{add(documentName);}}); // TODO-rca: 読みにくいので直接追加できるようにする - - viewerViewPagerAdapter.setFragmentRevisionList(new ArrayList(){{add(revId);}}); // TODO-rca: 読みにくいので直接追加できるようにする - viewerViewPagerAdapter.notifyItemRangeChanged(0, pageList.size()); - toolbar.setSubtitle("リビジョン: " + revId); - return null; - }); - return null; - }); - } - - // Get document page - if (this.hasCombined) { // 結合親の場合 - // バージョンを遡る操作を非表示 - toolbar.getMenu().findItem(R.id.action_open_vcs_rev_list).setVisible(false); - logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); - lacertaLibrary.getCombinedDocumentToxiList(documentId).thenAccept(combinedDocumentToxiList -> { - logger.debug("ViewerContainerFragment", "combinedDocumentToxiList: " + combinedDocumentToxiList.size()); - - viewerViewPagerAdapter.setFragmentTargetIdList( - combinedDocumentToxiList.stream().map(ToxiDocumentModel::getChildDocumentId).collect(Collectors.toCollection(ArrayList::new))); - viewerViewPagerAdapter.setFragmentTitleList( - combinedDocumentToxiList.stream().map(ToxiDocumentModel::getTitleCache).collect(Collectors.toCollection(ArrayList::new))); - - viewerViewPagerAdapter.notifyItemRangeChanged(0, combinedDocumentToxiList.size()); - toolbar.setSubtitle("結合ドキュメント"); - }); - } else { // それ以外の場合 - logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); - tabLayout.setVisibility(View.GONE); viewerViewPagerAdapter.setFragmentTargetIdList(new ArrayList(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする - viewerViewPagerAdapter.setFragmentTitleList(new ArrayList(){{add(documentName);}}); + viewerViewPagerAdapter.setFragmentTitleList(new ArrayList(){{add(documentName);}}); // TODO-rca: 読みにくいので直接追加できるようにする + viewerViewPagerAdapter.setFragmentRevisionList(new ArrayList(){{add(revId);}}); // TODO-rca: 読みにくいので直接追加できるようにする viewerViewPagerAdapter.notifyItemRangeChanged(0, 1); + tabLayout.setVisibility(View.GONE); + toolbar.setSubtitle("リビジョン: " + revId); + } else { + // Get document page + if (this.hasCombined) { // 結合親の場合 + // バージョンを遡る操作を非表示 + toolbar.getMenu().findItem(R.id.action_open_vcs_rev_list).setVisible(false); + logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); + lacertaLibrary.getCombinedDocumentToxiList(documentId).thenAccept(combinedDocumentToxiList -> { + logger.debug("ViewerContainerFragment", "combinedDocumentToxiList: " + combinedDocumentToxiList.size()); + + viewerViewPagerAdapter.setFragmentTargetIdList( + combinedDocumentToxiList.stream().map(ToxiDocumentModel::getChildDocumentId).collect(Collectors.toCollection(ArrayList::new))); + viewerViewPagerAdapter.setFragmentTitleList( + combinedDocumentToxiList.stream().map(ToxiDocumentModel::getTitleCache).collect(Collectors.toCollection(ArrayList::new))); + + viewerViewPagerAdapter.notifyItemRangeChanged(0, combinedDocumentToxiList.size()); + toolbar.setSubtitle("結合ドキュメント"); + }); + } else { // それ以外の場合 + logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); + tabLayout.setVisibility(View.GONE); + viewerViewPagerAdapter.setFragmentTargetIdList(new ArrayList(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする + viewerViewPagerAdapter.setFragmentTitleList(new ArrayList(){{add(documentName);}}); + viewerViewPagerAdapter.notifyItemRangeChanged(0, 1); + } + + // サブタイトルとしてパスを表示(暫定) + lacertaLibrary.getPublicPath(documentId, ListItemType.ITEM_TYPE_DOCUMENT).thenAccept(publicPath -> { + logger.debug("ViewerContainerFragment", "publicPath: " + publicPath); + toolbar.setSubtitle("/" + publicPath.parent().getStringPath()); + }); + } - - // サブタイトルとしてパスを表示(暫定) - lacertaLibrary.getPublicPath(documentId, ListItemType.ITEM_TYPE_DOCUMENT).thenAccept(publicPath -> { - logger.debug("ViewerContainerFragment", "publicPath: " + publicPath); - toolbar.setSubtitle("/" + publicPath.parent().getStringPath()); - }); - // Attach tab layout to view pager new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> { View customView = LayoutInflater.from(getContext()).inflate(R.layout.viewer_custom_tab, null);