diff --git a/component/viewer/build.gradle b/component/viewer/build.gradle index cf2bb069..93006a1e 100644 --- a/component/viewer/build.gradle +++ b/component/viewer/build.gradle @@ -54,4 +54,6 @@ dependencies { implementation project(':model') + implementation project(':vcs') + } \ No newline at end of file diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ComponentViewerTopFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ComponentViewerTopFragment.java index 89ba6954..e3f71bb7 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ComponentViewerTopFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ComponentViewerTopFragment.java @@ -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; + } + }); + }); + } } \ No newline at end of file diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/RevAdapter.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/RevAdapter.java new file mode 100644 index 00000000..bee4308d --- /dev/null +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/RevAdapter.java @@ -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{ + + private ArrayList revModels; + + public RevAdapter(ArrayList revModels) { + this.revModels = revModels; + } + + public RevAdapter() { + } + + public void setRevModels(ArrayList 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); + } + } +} \ No newline at end of file diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerMainActivity.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerMainActivity.java index e6fcdb43..6ef85637 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerMainActivity.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerMainActivity.java @@ -58,8 +58,9 @@ public class ViewerMainActivity extends AppCompatActivity { finish(); } + // Navigation getSupportFragmentManager().beginTransaction() .replace(R.id.nav_host_fragment, ComponentViewerTopFragment.newInstance(documentId)) - .commitNow(); + .commit(); } } \ No newline at end of file diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerVcsRevListFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerVcsRevListFragment.java new file mode 100644 index 00000000..237c1564 --- /dev/null +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerVcsRevListFragment.java @@ -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(); + }); + }); + } +} \ No newline at end of file diff --git a/component/viewer/src/main/res/layout/fragment_viewer_vcs_rev_list.xml b/component/viewer/src/main/res/layout/fragment_viewer_vcs_rev_list.xml new file mode 100644 index 00000000..c6de6685 --- /dev/null +++ b/component/viewer/src/main/res/layout/fragment_viewer_vcs_rev_list.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/component/viewer/src/main/res/layout/viewer_rev_list_item.xml b/component/viewer/src/main/res/layout/viewer_rev_list_item.xml new file mode 100644 index 00000000..bd938d79 --- /dev/null +++ b/component/viewer/src/main/res/layout/viewer_rev_list_item.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/component/viewer/src/main/res/menu/viewer_menu.xml b/component/viewer/src/main/res/menu/viewer_menu.xml new file mode 100644 index 00000000..cc8a206d --- /dev/null +++ b/component/viewer/src/main/res/menu/viewer_menu.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/component/viewer/src/main/res/navigation/component_viewer_navigation.xml b/component/viewer/src/main/res/navigation/component_viewer_navigation.xml index 0c821755..a8cd6b96 100644 --- a/component/viewer/src/main/res/navigation/component_viewer_navigation.xml +++ b/component/viewer/src/main/res/navigation/component_viewer_navigation.xml @@ -1,11 +1,21 @@ + android:label="ComponentViewerTopFragment" > + + + \ No newline at end of file diff --git a/model/src/main/java/one/nem/lacerta/model/VcsRevModel.java b/model/src/main/java/one/nem/lacerta/model/VcsRevModel.java new file mode 100644 index 00000000..a819179c --- /dev/null +++ b/model/src/main/java/one/nem/lacerta/model/VcsRevModel.java @@ -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 logIds; + + public VcsRevModel(String id, String documentId, String branchName, String commitMessage, Date createdAt, ArrayList 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 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 logIds) { + this.logIds = logIds; + } +} diff --git a/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java b/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java index 5d8dbc57..718c1aa8 100644 --- a/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java +++ b/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java @@ -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; diff --git a/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java b/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java index 1f5d31ea..664c45e1 100644 --- a/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java +++ b/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java @@ -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> getRevisionHistory(); + // debug public void printLog(); diff --git a/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java index 89cd8d2d..63da3858 100644 --- a/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java +++ b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java @@ -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> getRevisionHistory() { + return CompletableFuture.supplyAsync(() -> { + logger.debug(TAG, "getRevisionHistoryByDocumentId"); + ArrayList vcsRevModels = new ArrayList<>(); + + List 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");