RevDialog実装WIP

This commit is contained in:
r-ca 2024-01-27 16:01:03 +09:00
parent ffeb701b40
commit 3cfd54faf0
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
5 changed files with 96 additions and 7 deletions

View File

@ -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();
}
}

View File

@ -0,0 +1,6 @@
package one.nem.lacerta.component.common;
public interface LacertaSelectRevDialogInternalListener {
void onItemSelected(String revId);
}

View File

@ -2,6 +2,7 @@ package one.nem.lacerta.component.common;
public interface LacertaSelectRevDialogListener { public interface LacertaSelectRevDialogListener {
void onPositiveButtonClick(String rev); void onItemSelected(String revId);
void onNegativeButtonClick();
void onDialogCanceled();
} }

View File

@ -17,9 +17,9 @@ public class SelectRevDialogItemAdapter extends RecyclerView.Adapter<SelectRevDi
ArrayList<VcsRevModel> revList; ArrayList<VcsRevModel> revList;
LacertaSelectRevDialogListener listener; LacertaSelectRevDialogInternalListener listener;
public SelectRevDialogItemAdapter(LacertaSelectRevDialogListener listener) { public SelectRevDialogItemAdapter(LacertaSelectRevDialogInternalListener listener) {
this.listener = listener; this.listener = listener;
} }

View File

@ -21,6 +21,7 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.component.common.LacertaSelectDirDialog; import one.nem.lacerta.component.common.LacertaSelectDirDialog;
import one.nem.lacerta.component.common.LacertaSelectDirDialogListener; 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.Document;
import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.ListItemType; import one.nem.lacerta.model.ListItemType;
@ -176,9 +177,12 @@ public class ViewerListFragment extends Fragment {
toolbar.setOnMenuItemClickListener(item -> { toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.action_open_vcs_rev_list) { if (item.getItemId() == R.id.action_open_vcs_rev_list) {
// Open vcs rev list // Open vcs rev list
getParentFragmentManager().beginTransaction() // getParentFragmentManager().beginTransaction()
.replace(R.id.nav_host_fragment, ViewerVcsRevListFragment.newInstance(documentId, documentName)) // .replace(R.id.nav_host_fragment, ViewerVcsRevListFragment.newInstance(documentId, documentName))
.commit(); // .commit();
LacertaSelectRevDialog lacertaSelectRevDialog = new LacertaSelectRevDialog();
lacertaSelectRevDialog.show(getParentFragmentManager(), "select_rev_dialog");
return true; return true;
} else if (item.getItemId() == R.id.action_rename) { } else if (item.getItemId() == R.id.action_rename) {