From eeeef90ec23ad57cfc9bedbf06817f7847c96532 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 28 Jan 2024 13:28:13 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AE=E3=83=AA=E3=83=8D=E3=83=BC=E3=83=A0=E3=81=A0?= =?UTF-8?q?=E3=81=91=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../viewer/ViewerContainerFragment.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java index d51a015e..7944b743 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java @@ -11,9 +11,14 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Toast; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.document.page.Page; import one.nem.lacerta.model.pref.ToxiDocumentModel; @@ -35,6 +40,9 @@ public class ViewerContainerFragment extends Fragment { @Inject LacertaLibrary lacertaLibrary; + @Inject + Document document; + // Variables private String documentId; private String documentName; @@ -133,7 +141,7 @@ public class ViewerContainerFragment extends Fragment { Toast.makeText(getContext(), "Work in progress", Toast.LENGTH_SHORT).show(); return true; } else if (item.getItemId() == R.id.action_rename) { - Toast.makeText(getContext(), "Work in progress", Toast.LENGTH_SHORT).show(); + renameDocument(); return true; } else if (item.getItemId() == R.id.action_delete) { Toast.makeText(getContext(), "Work in progress", Toast.LENGTH_SHORT).show(); @@ -147,4 +155,31 @@ public class ViewerContainerFragment extends Fragment { }); }); } + + private void renameDocument() { + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); + builder.setTitle("ファイル名の変更"); + builder.setMessage("ファイル名を入力してください"); + + View view = LayoutInflater.from(getContext()).inflate(one.nem.lacerta.shared.ui.R.layout.lacerta_dialog_edit_text_layout, null); + TextInputEditText textInputEditText = view.findViewById(one.nem.lacerta.shared.ui.R.id.custom_edit_text); + TextInputLayout textInputLayout = view.findViewById(one.nem.lacerta.shared.ui.R.id.custom_text_input_layout); + textInputEditText.setText(documentName); + textInputLayout.setHint("ファイル名"); + builder.setView(view); + + builder.setPositiveButton("変更", (dialog, which) -> { + document.renameDocument(documentId, textInputEditText.getText().toString()).thenAccept(aVoid -> { + getActivity().runOnUiThread(() -> { + this.documentName = textInputEditText.getText().toString(); + // TODO-rca: Toolbarのタイトルも変更する + }); + }); + }); + builder.setNegativeButton("キャンセル", (dialog, which) -> { + dialog.cancel(); + }); + + builder.show(); + } } \ No newline at end of file