mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-02 11:37:37 +00:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
1a1dfe1be2
38 files changed
+409
-63
No files matched your search
@@ -12,6 +12,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import one.nem.lacerta.component.viewer.model.RevSelectListener;
|
||||
import one.nem.lacerta.model.VcsRevModel;
|
||||
import one.nem.lacerta.utils.FeatureSwitch;
|
||||
|
||||
@@ -19,11 +20,14 @@ public class RevAdapter extends RecyclerView.Adapter<RevAdapter.RevViewHolder>{
|
||||
|
||||
private ArrayList<VcsRevModel> revModels;
|
||||
|
||||
private RevSelectListener revSelectListener;
|
||||
|
||||
public RevAdapter(ArrayList<VcsRevModel> revModels) {
|
||||
this.revModels = revModels;
|
||||
}
|
||||
|
||||
public RevAdapter() {
|
||||
public RevAdapter(RevSelectListener revSelectListener) {
|
||||
this.revSelectListener = revSelectListener;
|
||||
}
|
||||
|
||||
public void setRevModels(ArrayList<VcsRevModel> revModels) {
|
||||
@@ -52,6 +56,13 @@ public class RevAdapter extends RecyclerView.Adapter<RevAdapter.RevViewHolder>{
|
||||
}
|
||||
holder.revId.setText("RevID: " + revModel.getId());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
revSelectListener.onRevSelect(revModel.getId());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+50
-19
@@ -1,12 +1,10 @@
|
||||
package one.nem.lacerta.component.viewer;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -16,24 +14,24 @@ import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.lacerta.data.Document;
|
||||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
import one.nem.lacerta.model.document.page.Page;
|
||||
import one.nem.lacerta.utils.FeatureSwitch;
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
import one.nem.lacerta.vcs.LacertaVcs;
|
||||
import one.nem.lacerta.vcs.factory.LacertaVcsFactory;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link ComponentViewerTopFragment#newInstance} factory method to
|
||||
* Use the {@link ViewerListFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
public class ComponentViewerTopFragment extends Fragment {
|
||||
public class ViewerListFragment extends Fragment {
|
||||
|
||||
@Inject
|
||||
Document document;
|
||||
@@ -41,17 +39,21 @@ public class ComponentViewerTopFragment extends Fragment {
|
||||
@Inject
|
||||
LacertaLogger logger;
|
||||
|
||||
@Inject
|
||||
LacertaVcsFactory lacertaVcsFactory;
|
||||
|
||||
private static final String TAG = "ComponentViewerTopFragment";
|
||||
|
||||
private String documentId;
|
||||
private String documentName;
|
||||
private String revisionId;
|
||||
|
||||
public ComponentViewerTopFragment() {
|
||||
public ViewerListFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
public static ComponentViewerTopFragment newInstance(String documentId, String documentName) {
|
||||
ComponentViewerTopFragment fragment = new ComponentViewerTopFragment();
|
||||
public static ViewerListFragment newInstance(String documentId, String documentName) {
|
||||
ViewerListFragment fragment = new ViewerListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("documentId", documentId);
|
||||
args.putString("documentName", documentName);
|
||||
@@ -59,12 +61,23 @@ public class ComponentViewerTopFragment extends Fragment {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public static ViewerListFragment newInstance(String documentId, String documentName, String revisionId) {
|
||||
ViewerListFragment fragment = new ViewerListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("documentId", documentId);
|
||||
args.putString("documentName", documentName);
|
||||
args.putString("revisionId", revisionId);
|
||||
fragment.setArguments(args);
|
||||
return 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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,16 +98,34 @@ public class ComponentViewerTopFragment extends Fragment {
|
||||
});
|
||||
recyclerView.setAdapter(viewerBodyAdapter);
|
||||
|
||||
if (FeatureSwitch.Viewer.showProgressBarWhenLoading) view.findViewById(R.id.loading_progress_bar).setVisibility(View.VISIBLE);
|
||||
document.getDocument(documentId).thenAccept(documentDetail -> {
|
||||
ArrayList<Page> pages = documentDetail.getPages();
|
||||
logger.debug(TAG, "pages.size(): " + pages.size());
|
||||
viewerBodyAdapter.setPages(pages);
|
||||
getActivity().runOnUiThread(() -> {
|
||||
viewerBodyAdapter.notifyItemRangeChanged(0, pages.size());
|
||||
if (FeatureSwitch.Viewer.showProgressBarWhenLoading) view.findViewById(R.id.loading_progress_bar).setVisibility(View.GONE);
|
||||
if (revisionId == null) {
|
||||
logger.debug(TAG, "revisionId is empty, loading latest revision");
|
||||
if (FeatureSwitch.Viewer.showProgressBarWhenLoading) view.findViewById(R.id.loading_progress_bar).setVisibility(View.VISIBLE);
|
||||
document.getDocument(documentId).thenAccept(documentDetail -> {
|
||||
ArrayList<Page> pages = documentDetail.getPages();
|
||||
logger.debug(TAG, "pages.size(): " + pages.size());
|
||||
viewerBodyAdapter.setPages(pages);
|
||||
getActivity().runOnUiThread(() -> {
|
||||
viewerBodyAdapter.notifyItemRangeChanged(0, pages.size());
|
||||
if (FeatureSwitch.Viewer.showProgressBarWhenLoading) view.findViewById(R.id.loading_progress_bar).setVisibility(View.GONE);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
logger.debug(TAG, "revisionId: " + revisionId);
|
||||
if (FeatureSwitch.Viewer.showProgressBarWhenLoading) view.findViewById(R.id.loading_progress_bar).setVisibility(View.VISIBLE);
|
||||
LacertaVcs lacertaVcs = lacertaVcsFactory.create(documentId);
|
||||
lacertaVcs.getDocumentPagePathListRev(revisionId).thenAccept(documentPathList -> {
|
||||
logger.debug(TAG, "documentPathList.size(): " + documentPathList.size());
|
||||
document.getDocumentPageListByFileNameList(documentId, documentPathList).thenAccept(pages -> {
|
||||
logger.debug(TAG, "pages.size(): " + pages.size());
|
||||
viewerBodyAdapter.setPages(pages);
|
||||
getActivity().runOnUiThread(() -> {
|
||||
viewerBodyAdapter.notifyItemRangeChanged(0, pages.size());
|
||||
if (FeatureSwitch.Viewer.showProgressBarWhenLoading) view.findViewById(R.id.loading_progress_bar).setVisibility(View.GONE);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -123,7 +154,7 @@ public class ComponentViewerTopFragment extends Fragment {
|
||||
if (item.getItemId() == R.id.action_open_vcs_rev_list) {
|
||||
// Open vcs rev list
|
||||
getParentFragmentManager().beginTransaction()
|
||||
.replace(R.id.nav_host_fragment, ViewerVcsRevListFragment.newInstance(documentId))
|
||||
.replace(R.id.nav_host_fragment, ViewerVcsRevListFragment.newInstance(documentId, documentName))
|
||||
.commit();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_rename) {
|
||||
+1
-8
@@ -2,7 +2,6 @@ package one.nem.lacerta.component.viewer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
@@ -10,12 +9,6 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -62,7 +55,7 @@ public class ViewerMainActivity extends AppCompatActivity {
|
||||
|
||||
// Navigation
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.nav_host_fragment, ComponentViewerTopFragment.newInstance(documentId, documentName))
|
||||
.replace(R.id.nav_host_fragment, ViewerListFragment.newInstance(documentId, documentName))
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -34,15 +34,17 @@ public class ViewerVcsRevListFragment extends Fragment {
|
||||
LacertaVcs lacertaVcs;
|
||||
|
||||
private String documentId;
|
||||
private String documentName;
|
||||
|
||||
public ViewerVcsRevListFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
public static ViewerVcsRevListFragment newInstance(String documentId) {
|
||||
public static ViewerVcsRevListFragment newInstance(String documentId, String documentName) {
|
||||
ViewerVcsRevListFragment fragment = new ViewerVcsRevListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("documentId", documentId);
|
||||
args.putString("documentName", documentName);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
@@ -66,17 +68,22 @@ public class ViewerVcsRevListFragment extends Fragment {
|
||||
// Init arg
|
||||
if (getArguments() != null) {
|
||||
this.documentId = getArguments().getString("documentId");
|
||||
logger.debug("ViewerVcsRevListFragment", "documentId: " + documentId);
|
||||
logger.debug("ViewerVcsRevListFragment", "documentId: " + this.documentId);
|
||||
}
|
||||
|
||||
// Init vcs
|
||||
lacertaVcs = lacertaVcsFactory.create(documentId);
|
||||
lacertaVcs = lacertaVcsFactory.create(this.documentId);
|
||||
|
||||
// Init view
|
||||
RecyclerView recyclerView = view.findViewById(R.id.rev_list);
|
||||
|
||||
// Init adapter
|
||||
RevAdapter revAdapter = new RevAdapter();
|
||||
RevAdapter revAdapter = new RevAdapter(revisionId -> {
|
||||
logger.debug("ViewerVcsRevListFragment", "Selected revisionId: " + revisionId);
|
||||
getParentFragmentManager().beginTransaction()
|
||||
.replace(R.id.nav_host_fragment, ViewerListFragment.newInstance(this.documentId, this.documentName, revisionId))
|
||||
.commit();
|
||||
});
|
||||
|
||||
// Set adapter
|
||||
recyclerView.setAdapter(revAdapter);
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package one.nem.lacerta.component.viewer.model;
|
||||
|
||||
public interface RevSelectListener {
|
||||
void onRevSelect(String revisionId);
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="one.nem.lacerta.component.viewer.ComponentViewerTopFragment"
|
||||
android:name="one.nem.lacerta.component.viewer.ViewerListFragment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:defaultNavHost="true"
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/component_viewer_navigation"
|
||||
app:startDestination="@id/componentViewerTopFragment">
|
||||
app:startDestination="@id/viewerListFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/componentViewerTopFragment"
|
||||
android:name="one.nem.lacerta.component.viewer.ComponentViewerTopFragment"
|
||||
android:id="@+id/viewerListFragment"
|
||||
android:name="one.nem.lacerta.component.viewer.ViewerListFragment"
|
||||
android:label="ComponentViewerTopFragment" >
|
||||
<action
|
||||
android:id="@+id/action_componentViewerTopFragment_to_viewerVcsRevListFragment"
|
||||
|
||||
Reference in new issue
Block a user