バージョンを遡れない不具合を修正

This commit is contained in:
ろむねこ 2024-01-29 13:20:44 +09:00
parent 2fcab4e931
commit 0fe0f5dd00
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 55 additions and 48 deletions

View File

@ -14,6 +14,8 @@ import android.widget.Toast;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
@ -124,26 +126,41 @@ public class ViewerBodyFragment extends Fragment {
builder.show(); builder.show();
} }
}); });
recyclerView.setAdapter(viewerBodyAdapter);
getActivity().runOnUiThread(() -> {
recyclerView.setAdapter(viewerBodyAdapter);
viewerBodyAdapter.notifyDataSetChanged();
});
loadDocument(viewerBodyAdapter, documentId, revisionId); loadDocument(viewerBodyAdapter, documentId, revisionId);
} }
private void loadDocument(ViewerBodyAdapter adapter, String documentId, String revisionId) { private void loadDocument(ViewerBodyAdapter adapter, String documentId, String revisionId) {
if (revisionId == null) { // load latest revision if (revisionId == null) { // load latest revision
document.getDocument(documentId).thenAccept(document -> { document.getDocument(documentId).thenApply(document -> {
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
adapter.setPages(document.getPages()); adapter.setPages(document.getPages());
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
}); });
return null;
}); });
} else { // load specified revision } else { // load specified revision
LacertaVcs vcs = lacertaVcsFactory.create(documentId); 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<String> fileNameList = vcs.getDocumentPagePathListRev(revisionId).join();
document.getDocumentPageListByFileNameList(documentId, fileNameList).thenApply(documentPageList -> {
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
adapter.setPages(documentPageList); adapter.setPages(documentPageList);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
}); });
return null;
}); });
} }
} }

View File

@ -145,54 +145,44 @@ public class ViewerContainerFragment extends Fragment {
if (this.revId != null) { // Revが指定されている場合 if (this.revId != null) { // Revが指定されている場合
LacertaVcs lacertaVcs = lacertaVcsFactory.create(documentId); 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<String>(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする
viewerViewPagerAdapter.setFragmentTitleList(new ArrayList<String>(){{add(documentName);}}); // TODO-rca: 読みにくいので直接追加できるようにする
viewerViewPagerAdapter.setFragmentRevisionList(new ArrayList<String>(){{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<String>(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする viewerViewPagerAdapter.setFragmentTargetIdList(new ArrayList<String>(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする
viewerViewPagerAdapter.setFragmentTitleList(new ArrayList<String>(){{add(documentName);}}); viewerViewPagerAdapter.setFragmentTitleList(new ArrayList<String>(){{add(documentName);}}); // TODO-rca: 読みにくいので直接追加できるようにする
viewerViewPagerAdapter.setFragmentRevisionList(new ArrayList<String>(){{add(revId);}}); // TODO-rca: 読みにくいので直接追加できるようにする
viewerViewPagerAdapter.notifyItemRangeChanged(0, 1); 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<String>(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする
viewerViewPagerAdapter.setFragmentTitleList(new ArrayList<String>(){{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 // Attach tab layout to view pager
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> { new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
View customView = LayoutInflater.from(getContext()).inflate(R.layout.viewer_custom_tab, null); View customView = LayoutInflater.from(getContext()).inflate(R.layout.viewer_custom_tab, null);