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 index 74736547..bee4308d 100644 --- 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 @@ -1,14 +1,18 @@ 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{ @@ -29,23 +33,48 @@ public class RevAdapter extends RecyclerView.Adapter{ @NonNull @Override public RevAdapter.RevViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return null; + 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() { - return 0; + 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 index f859747e..237c1564 100644 --- 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 @@ -3,45 +3,46 @@ 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 { - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; + @Inject + LacertaVcsFactory lacertaVcsFactory; - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; + @Inject + LacertaLogger logger; + + LacertaVcs lacertaVcs; + + private String documentId; public ViewerVcsRevListFragment() { // Required empty public constructor } - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment ViewerVcsRevListFragment. - */ - // TODO: Rename and change types and number of parameters - public static ViewerVcsRevListFragment newInstance(String param1, String param2) { + public static ViewerVcsRevListFragment newInstance(String documentId) { ViewerVcsRevListFragment fragment = new ViewerVcsRevListFragment(); Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); + args.putString("documentId", documentId); fragment.setArguments(args); return fragment; } @@ -49,10 +50,6 @@ public class ViewerVcsRevListFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } } @Override @@ -61,4 +58,38 @@ public class ViewerVcsRevListFragment extends Fragment { // 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 index 019260c9..c6de6685 100644 --- 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 @@ -5,10 +5,8 @@ android:layout_height="match_parent" tools:context=".ViewerVcsRevListFragment"> - - - + android:layout_height="match_parent" /> \ 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 index c3e56be3..bd938d79 100644 --- a/component/viewer/src/main/res/layout/viewer_rev_list_item.xml +++ b/component/viewer/src/main/res/layout/viewer_rev_list_item.xml @@ -15,7 +15,7 @@ app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toBottomOf="@+id/rev_item_title" /> + app:layout_constraintTop_toBottomOf="@+id/rev_item_detail" /> 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/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/impl/LacertaVcsImpl.java b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java index e04c7e49..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 @@ -133,6 +133,7 @@ public class LacertaVcsImpl implements LacertaVcs { 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);