diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialog.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialog.java new file mode 100644 index 00000000..2989e9b5 --- /dev/null +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialog.java @@ -0,0 +1,78 @@ +package one.nem.lacerta.component.common; + +import android.app.Dialog; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Toast; + +import androidx.fragment.app.DialogFragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + +public class LacertaSelectRevDialog extends DialogFragment { + + String title; + String message; + String negativeButtonText; + + LacertaSelectRevDialogListener listener; + + public LacertaSelectRevDialog setTitle(String title) { + this.title = title; + return this; + } + + public LacertaSelectRevDialog setMessage(String message) { + this.message = message; + return this; + } + + public LacertaSelectRevDialog setNegativeButtonText(String negativeButtonText) { + this.negativeButtonText = negativeButtonText; + return this; + } + + public LacertaSelectRevDialog setListener(LacertaSelectRevDialogListener listener) { + this.listener = listener; + return this; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + super.onCreateDialog(savedInstanceState); + + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity()); + LayoutInflater inflater = requireActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.lacerta_dialog_select_rev, null); + + int height = (int) (getResources().getDisplayMetrics().heightPixels * 0.4); + view.setMinimumHeight(height); + + RecyclerView recyclerView = view.findViewById(R.id.select_rev_recycler_view); + + SelectRevDialogItemAdapter adapter = new SelectRevDialogItemAdapter(revId -> { + if (listener != null) { + listener.onItemSelected(revId); + } + dismiss(); + }); + + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + + builder.setView(view); + builder.setTitle(title == null ? "Select Rev" : title); + builder.setMessage(message == null ? "Select Rev" : message); + builder.setNegativeButton(negativeButtonText, (dialog, which) -> { + if (listener != null) { + listener.onDialogCanceled(); + dismiss(); + } + }); + + return builder.create(); + } +} diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogInternalListener.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogInternalListener.java new file mode 100644 index 00000000..7988bd22 --- /dev/null +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogInternalListener.java @@ -0,0 +1,6 @@ +package one.nem.lacerta.component.common; + +public interface LacertaSelectRevDialogInternalListener { + + void onItemSelected(String revId); +} diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogListener.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogListener.java index 5d4bce26..3a7f808d 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogListener.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectRevDialogListener.java @@ -2,6 +2,7 @@ package one.nem.lacerta.component.common; public interface LacertaSelectRevDialogListener { - void onPositiveButtonClick(String rev); - void onNegativeButtonClick(); + void onItemSelected(String revId); + + void onDialogCanceled(); } diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/SelectRevDialogItemAdapter.java b/component/common/src/main/java/one/nem/lacerta/component/common/SelectRevDialogItemAdapter.java index 217bd929..47991374 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/SelectRevDialogItemAdapter.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/SelectRevDialogItemAdapter.java @@ -17,9 +17,9 @@ public class SelectRevDialogItemAdapter extends RecyclerView.Adapter revList; - LacertaSelectRevDialogListener listener; + LacertaSelectRevDialogInternalListener listener; - public SelectRevDialogItemAdapter(LacertaSelectRevDialogListener listener) { + public SelectRevDialogItemAdapter(LacertaSelectRevDialogInternalListener listener) { this.listener = listener; } diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerListFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerListFragment.java index 51e94931..269e9193 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerListFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerListFragment.java @@ -21,6 +21,7 @@ import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.component.common.LacertaSelectDirDialog; import one.nem.lacerta.component.common.LacertaSelectDirDialogListener; +import one.nem.lacerta.component.common.LacertaSelectRevDialog; import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.ListItemType; @@ -176,9 +177,12 @@ public class ViewerListFragment extends Fragment { 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, documentName)) - .commit(); +// getParentFragmentManager().beginTransaction() +// .replace(R.id.nav_host_fragment, ViewerVcsRevListFragment.newInstance(documentId, documentName)) +// .commit(); + + LacertaSelectRevDialog lacertaSelectRevDialog = new LacertaSelectRevDialog(); + lacertaSelectRevDialog.show(getParentFragmentManager(), "select_rev_dialog"); return true; } else if (item.getItemId() == R.id.action_rename) {