mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 09:43:15 +00:00
commit
2b9a68b6f5
|
@ -54,4 +54,6 @@ dependencies {
|
|||
|
||||
implementation project(':model')
|
||||
|
||||
implementation project(':vcs')
|
||||
|
||||
}
|
|
@ -3,7 +3,9 @@ package one.nem.lacerta.component.viewer;
|
|||
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;
|
||||
|
||||
|
@ -67,6 +69,10 @@ public class ComponentViewerTopFragment extends Fragment {
|
|||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_component_viewer_top, container, false);
|
||||
|
||||
// Toolbar
|
||||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
toolbarSetup(toolbar, true, "Revision List");
|
||||
|
||||
RecyclerView recyclerView = view.findViewById(R.id.body_recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
ViewerBodyAdapter viewerBodyAdapter = new ViewerBodyAdapter(fileName -> {
|
||||
|
@ -85,4 +91,39 @@ public class ComponentViewerTopFragment extends Fragment {
|
|||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* ToolbarをInitする
|
||||
*
|
||||
* @param toolbar Toolbar
|
||||
* @param showBackButton 戻るボタンを表示するか
|
||||
* @param title タイトル
|
||||
*/
|
||||
private void toolbarSetup(Toolbar toolbar, boolean showBackButton, String title) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
if (showBackButton) {
|
||||
toolbar.setNavigationIcon(one.nem.lacerta.shared.ui.R.drawable.arrow_back_24px);
|
||||
toolbar.setNavigationOnClickListener(v -> {
|
||||
//this.libraryItemPage = lacertaLibrary.getLibraryPage(this.libraryItemPage.getParentId(), 10).join();
|
||||
// Back
|
||||
Navigation.findNavController(requireView()).popBackStack();
|
||||
});
|
||||
} else {
|
||||
toolbar.setNavigationIcon(null);
|
||||
}
|
||||
toolbar.setTitle(title);
|
||||
toolbar.inflateMenu(R.menu.viewer_menu);
|
||||
toolbar.setOnMenuItemClickListener(item -> {
|
||||
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))
|
||||
.commit();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package one.nem.lacerta.component.viewer;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import one.nem.lacerta.model.VcsRevModel;
|
||||
import one.nem.lacerta.utils.FeatureSwitch;
|
||||
|
||||
public class RevAdapter extends RecyclerView.Adapter<RevAdapter.RevViewHolder>{
|
||||
|
||||
private ArrayList<VcsRevModel> revModels;
|
||||
|
||||
public RevAdapter(ArrayList<VcsRevModel> revModels) {
|
||||
this.revModels = revModels;
|
||||
}
|
||||
|
||||
public RevAdapter() {
|
||||
}
|
||||
|
||||
public void setRevModels(ArrayList<VcsRevModel> revModels) {
|
||||
this.revModels = revModels;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RevAdapter.RevViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewer_rev_list_item, parent, false);
|
||||
return new RevAdapter.RevViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RevAdapter.RevViewHolder holder, int position) {
|
||||
VcsRevModel revModel = revModels.get(position);
|
||||
holder.title.setText(revModel.getCommitMessage());
|
||||
if (FeatureSwitch.Vcs.disableBranchDisplay) {
|
||||
// holder.detail.setText(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(revModel.getCreatedAt().toInstant()));
|
||||
holder.detail.setText("DateTimePlaceholder");
|
||||
} else {
|
||||
// holder.detail.setText(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(revModel.getCreatedAt().toInstant()) + " " + revModel.getBranchName());
|
||||
holder.detail.setText("DateTimePlaceholder" + " " + revModel.getBranchName());
|
||||
}
|
||||
holder.revId.setText("RevID: " + revModel.getId());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (revModels == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return revModels.size();
|
||||
}
|
||||
}
|
||||
|
||||
class RevViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView title;
|
||||
|
||||
TextView detail;
|
||||
|
||||
TextView revId;
|
||||
|
||||
public RevViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
title = itemView.findViewById(R.id.rev_item_title);
|
||||
detail = itemView.findViewById(R.id.rev_item_detail);
|
||||
revId = itemView.findViewById(R.id.rev_item_id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,8 +58,9 @@ public class ViewerMainActivity extends AppCompatActivity {
|
|||
finish();
|
||||
}
|
||||
|
||||
// Navigation
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.nav_host_fragment, ComponentViewerTopFragment.newInstance(documentId))
|
||||
.commitNow();
|
||||
.commit();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
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 javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
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 ViewerVcsRevListFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
public class ViewerVcsRevListFragment extends Fragment {
|
||||
|
||||
@Inject
|
||||
LacertaVcsFactory lacertaVcsFactory;
|
||||
|
||||
@Inject
|
||||
LacertaLogger logger;
|
||||
|
||||
LacertaVcs lacertaVcs;
|
||||
|
||||
private String documentId;
|
||||
|
||||
public ViewerVcsRevListFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
public static ViewerVcsRevListFragment newInstance(String documentId) {
|
||||
ViewerVcsRevListFragment fragment = new ViewerVcsRevListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("documentId", documentId);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_viewer_vcs_rev_list, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// Init arg
|
||||
if (getArguments() != null) {
|
||||
this.documentId = getArguments().getString("documentId");
|
||||
logger.debug("ViewerVcsRevListFragment", "documentId: " + documentId);
|
||||
}
|
||||
|
||||
// Init vcs
|
||||
lacertaVcs = lacertaVcsFactory.create(documentId);
|
||||
|
||||
// Init view
|
||||
RecyclerView recyclerView = view.findViewById(R.id.rev_list);
|
||||
|
||||
// Init adapter
|
||||
RevAdapter revAdapter = new RevAdapter();
|
||||
|
||||
// Set adapter
|
||||
recyclerView.setAdapter(revAdapter);
|
||||
|
||||
// Set layout manager
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
lacertaVcs.getRevisionHistory().thenAccept(revModels -> {
|
||||
logger.debug("ViewerVcsRevListFragment", "revModels.size(): " + revModels.size());
|
||||
getActivity().runOnUiThread(() -> {
|
||||
revAdapter.setRevModels(revModels);
|
||||
revAdapter.notifyDataSetChanged();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ViewerVcsRevListFragment">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rev_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="16dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/item_text_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rev_item_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="Placeholder Title"
|
||||
android:textColor="@color/colorOnSurface"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rev_item_detail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:text="2023/01/01 00:00:00 - hogehoge"
|
||||
android:textColor="@color/colorOnSurfaceSecondary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rev_item_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rev_item_id"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:text="dd76a029-51f1-40f7-b316-a0c74bbfebb1(Example)"
|
||||
android:textColor="@color/colorOnSurfaceSecondary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rev_item_detail" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
7
component/viewer/src/main/res/menu/viewer_menu.xml
Normal file
7
component/viewer/src/main/res/menu/viewer_menu.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/action_open_vcs_rev_list"
|
||||
android:title="Open VCS Rev List" />
|
||||
|
||||
</menu>
|
|
@ -1,11 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/componentViewerTopFragment"
|
||||
android:name="one.nem.lacerta.component.viewer.ComponentViewerTopFragment"
|
||||
android:label="ComponentViewerTopFragment" />
|
||||
android:label="ComponentViewerTopFragment" >
|
||||
<action
|
||||
android:id="@+id/action_componentViewerTopFragment_to_viewerVcsRevListFragment"
|
||||
app:destination="@id/viewerVcsRevListFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/viewerVcsRevListFragment"
|
||||
android:name="one.nem.lacerta.component.viewer.ViewerVcsRevListFragment"
|
||||
android:label="fragment_viewer_vcs_rev_list"
|
||||
tools:layout="@layout/fragment_viewer_vcs_rev_list" />
|
||||
</navigation>
|
80
model/src/main/java/one/nem/lacerta/model/VcsRevModel.java
Normal file
80
model/src/main/java/one/nem/lacerta/model/VcsRevModel.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
package one.nem.lacerta.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class VcsRevModel {
|
||||
|
||||
String id;
|
||||
|
||||
String documentId;
|
||||
|
||||
String branchName;
|
||||
|
||||
String commitMessage;
|
||||
|
||||
Date createdAt;
|
||||
|
||||
ArrayList<String> logIds;
|
||||
|
||||
public VcsRevModel(String id, String documentId, String branchName, String commitMessage, Date createdAt, ArrayList<String> logIds) {
|
||||
this.id = id;
|
||||
this.documentId = documentId;
|
||||
this.branchName = branchName;
|
||||
this.commitMessage = commitMessage;
|
||||
this.createdAt = createdAt;
|
||||
this.logIds = logIds;
|
||||
}
|
||||
|
||||
// Empty constructor
|
||||
public VcsRevModel() {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDocumentId() {
|
||||
return documentId;
|
||||
}
|
||||
|
||||
public String getBranchName() {
|
||||
return branchName;
|
||||
}
|
||||
|
||||
public String getCommitMessage() {
|
||||
return commitMessage;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public ArrayList<String> getLogIds() {
|
||||
return logIds;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setDocumentId(String documentId) {
|
||||
this.documentId = documentId;
|
||||
}
|
||||
|
||||
public void setBranchName(String branchName) {
|
||||
this.branchName = branchName;
|
||||
}
|
||||
|
||||
public void setCommitMessage(String commitMessage) {
|
||||
this.commitMessage = commitMessage;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public void setLogIds(ArrayList<String> logIds) {
|
||||
this.logIds = logIds;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,10 @@ public class FeatureSwitch {
|
|||
public static boolean enableDebugMenu = false;
|
||||
}
|
||||
|
||||
public static class Vcs {
|
||||
public static boolean disableBranchDisplay = true;
|
||||
}
|
||||
|
||||
public static class Setting {
|
||||
public static boolean showDisplayMenu = false;
|
||||
public static boolean showDataMenu = false;
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package one.nem.lacerta.vcs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import one.nem.lacerta.model.VcsRevModel;
|
||||
|
||||
public interface LacertaVcs {
|
||||
|
||||
// Actions
|
||||
|
@ -13,6 +18,8 @@ public interface LacertaVcs {
|
|||
|
||||
public void generateRevisionAtCurrent(String message);
|
||||
|
||||
public CompletableFuture<ArrayList<VcsRevModel>> getRevisionHistory();
|
||||
|
||||
|
||||
// debug
|
||||
public void printLog();
|
||||
|
|
|
@ -3,11 +3,13 @@ package one.nem.lacerta.vcs.impl;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.lacerta.model.VcsRevModel;
|
||||
import one.nem.lacerta.source.database.LacertaDatabase;
|
||||
import one.nem.lacerta.source.database.entity.VcsLogEntity;
|
||||
import one.nem.lacerta.source.database.entity.VcsRevEntity;
|
||||
|
@ -122,6 +124,27 @@ public class LacertaVcsImpl implements LacertaVcs {
|
|||
logger.debug(TAG, "New revision inserted: " + vcsRevEntity.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ArrayList<VcsRevModel>> getRevisionHistory() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
logger.debug(TAG, "getRevisionHistoryByDocumentId");
|
||||
ArrayList<VcsRevModel> vcsRevModels = new ArrayList<>();
|
||||
|
||||
List<VcsRevEntity> vcsRevEntities = database.vcsRevDao().findByDocumentId(this.documentId);
|
||||
vcsRevEntities.forEach(vcsRevEntity -> {
|
||||
VcsRevModel vcsRevModel = new VcsRevModel();
|
||||
vcsRevModel.setId(vcsRevEntity.id);
|
||||
vcsRevModel.setDocumentId(vcsRevEntity.documentId);
|
||||
vcsRevModel.setBranchName(vcsRevEntity.branchName);
|
||||
vcsRevModel.setCommitMessage(vcsRevEntity.commitMessage);
|
||||
vcsRevModel.setLogIds(vcsRevEntity.logIds);
|
||||
vcsRevModels.add(vcsRevModel);
|
||||
});
|
||||
|
||||
return vcsRevModels;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printLog() {
|
||||
logger.debug(TAG, "printLog");
|
||||
|
|
Loading…
Reference in New Issue
Block a user