From b7822945fd2d703ec0be4eaf396927fa3f3a538b Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 28 Jan 2024 12:49:06 +0900 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E6=95=B0=E5=87=A6=E7=90=86,=20LoadDoc?= =?UTF-8?q?ument=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/viewer/ViewerBodyFragment.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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 5549adb0..4e702a7d 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 @@ -3,10 +3,13 @@ package one.nem.lacerta.component.viewer; import android.os.Bundle; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import javax.inject.Inject; @@ -14,6 +17,7 @@ import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.utils.LacertaLogger; +import one.nem.lacerta.vcs.LacertaVcs; import one.nem.lacerta.vcs.factory.LacertaVcsFactory; /** @@ -67,6 +71,11 @@ public class ViewerBodyFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (getArguments() != null) { + documentId = getArguments().getString("documentId"); + documentName = getArguments().getString("documentName"); + revisionId = getArguments().getString("revisionId"); + } } @Override @@ -75,4 +84,38 @@ public class ViewerBodyFragment extends Fragment { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_viewer_body, container, false); } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + logger.debug("ViewerBodyFragment", "ViewerBodyFragment.onViewCreated"); + + RecyclerView recyclerView = view.findViewById(R.id.recycler_view); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + + ViewerBodyAdapter viewerBodyAdapter = new ViewerBodyAdapter(fileName -> { + Toast.makeText(getContext(), fileName, Toast.LENGTH_SHORT).show(); + // TODO-rca: なにか処理をもたせる + }); + recyclerView.setAdapter(viewerBodyAdapter); + } + + private void loadDocument(ViewerBodyAdapter adapter, String documentId, String revisionId) { + if (revisionId == null) { // load latest revision + document.getDocument(documentId).thenAccept(document -> { + getActivity().runOnUiThread(() -> { + adapter.setPages(document.getPages()); + adapter.notifyDataSetChanged(); + }); + }); + } else { // load specified revision + LacertaVcs vcs = lacertaVcsFactory.create(documentId); + document.getDocumentPageListByFileNameList(documentId, vcs.getDocumentPagePathListRev(revisionId).join()).thenAccept(documentPageList -> { + getActivity().runOnUiThread(() -> { + adapter.setPages(documentPageList); + adapter.notifyDataSetChanged(); + }); + }); + } + } } \ No newline at end of file