mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
parent
0c27cf6b24
commit
c3e1825542
|
@ -4,10 +4,8 @@ import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.viewpager2.widget.ViewPager2;
|
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -51,12 +49,6 @@ public class ViewerBodyFragment extends Fragment {
|
||||||
private String documentName;
|
private String documentName;
|
||||||
private String revisionId;
|
private String revisionId;
|
||||||
|
|
||||||
private SharedViewModel sharedViewModel;
|
|
||||||
|
|
||||||
private RecyclerView recyclerView;
|
|
||||||
|
|
||||||
private int maxPage = 0;
|
|
||||||
|
|
||||||
public ViewerBodyFragment() {
|
public ViewerBodyFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@ -102,33 +94,9 @@ public class ViewerBodyFragment extends Fragment {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
logger.debug("ViewerBodyFragment", "ViewerBodyFragment.onViewCreated");
|
logger.debug("ViewerBodyFragment", "ViewerBodyFragment.onViewCreated");
|
||||||
|
|
||||||
this.recyclerView = view.findViewById(R.id.recycler_view);
|
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
|
||||||
sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
|
||||||
|
|
||||||
ViewPager2 viewPager2 = getActivity().findViewById(R.id.view_pager);
|
|
||||||
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
super.onPageSelected(position);
|
|
||||||
sharedViewModel.setCurrentFragmentPosition(position);
|
|
||||||
|
|
||||||
if (maxPage > 0 && position >= maxPage) {
|
|
||||||
// out of range
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
recyclerView.scrollToPosition(position);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("ViewerBodyFragment", "recyclerView.scrollToPosition");
|
|
||||||
logger.error("ViewerBodyFragment", e.getMessage());
|
|
||||||
logger.e_code("8beec84b-1f7d-4e1e-9364-9fcf00f3509a");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ViewerBodyAdapter viewerBodyAdapter = new ViewerBodyAdapter(new ItemClickListener() {
|
ViewerBodyAdapter viewerBodyAdapter = new ViewerBodyAdapter(new ItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(String fileName) {
|
public void onItemClick(String fileName) {
|
||||||
|
@ -161,19 +129,9 @@ public class ViewerBodyFragment extends Fragment {
|
||||||
loadDocument(viewerBodyAdapter, documentId, revisionId);
|
loadDocument(viewerBodyAdapter, documentId, revisionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
logger.debug("ViewerBodyFragment", "ViewerBodyFragment.onResume");
|
|
||||||
|
|
||||||
this.sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
|
||||||
this.recyclerView.scrollToPosition(sharedViewModel.getCurrentFragmentPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
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).thenAccept(document -> {
|
||||||
this.maxPage = document.getPages().size();
|
|
||||||
getActivity().runOnUiThread(() -> {
|
getActivity().runOnUiThread(() -> {
|
||||||
adapter.setPages(document.getPages());
|
adapter.setPages(document.getPages());
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
|
|
@ -224,18 +224,6 @@ public class ViewerContainerFragment extends Fragment {
|
||||||
|
|
||||||
tab.setCustomView(customView);
|
tab.setCustomView(customView);
|
||||||
}).attach();
|
}).attach();
|
||||||
|
|
||||||
// Sync position between pages
|
|
||||||
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
logger.debug("ViewerContainerFragment", "onPageSelected: " + position);
|
|
||||||
super.onPageSelected(position);
|
|
||||||
if (hasCombined) {
|
|
||||||
toolbar.setTitle(viewerViewPagerAdapter.getFragmentTitle(position));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameCombinedDocument(String parentId, String childId, String current, int position) { // TODO-rca: 無理やりpositionを渡してるのでなんとかする
|
private void renameCombinedDocument(String parentId, String childId, String current, int position) { // TODO-rca: 無理やりpositionを渡してるのでなんとかする
|
||||||
|
|
Loading…
Reference in New Issue
Block a user