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);