From ba0133a047deb61cffb68527ad12f716137ce604 Mon Sep 17 00:00:00 2001 From: onurays Date: Mon, 10 Feb 2020 23:03:37 +0300 Subject: [PATCH] Reason input for redacting event is added. --- .../home/room/detail/RoomDetailFragment.kt | 28 +++++++++++++----- .../main/res/layout/dialog_delete_event.xml | 29 +++++++++++++++++++ vector/src/main/res/values/strings_riotX.xml | 5 +++- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 733d474067..2f33a0e5ba 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -61,6 +61,7 @@ import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import com.github.piasy.biv.BigImageViewer import com.github.piasy.biv.loader.ImageLoader +import com.google.android.material.checkbox.MaterialCheckBox import com.google.android.material.snackbar.Snackbar import com.google.android.material.textfield.TextInputEditText import com.jakewharton.rxbinding3.widget.textChanges @@ -793,6 +794,24 @@ class RoomDetailFragment @Inject constructor( .show() } + private fun promptReasonToDeleteEvent(eventId: String) { + val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null) + val reasonCheckBox = layout.findViewById(R.id.deleteEventReasonCheck) + val reasonInput = layout.findViewById(R.id.deleteEventReasonInput) + + reasonCheckBox.setOnCheckedChangeListener { _, isChecked -> reasonInput.isEnabled = isChecked } + + AlertDialog.Builder(requireActivity()) + .setView(layout) + .setTitle(R.string.delete_event_dialog_title) + .setPositiveButton(R.string.remove) { _, _ -> + val reason = if (reasonCheckBox.isChecked) reasonInput.text.toString().takeIf { it.isNotBlank() } else null + roomDetailViewModel.handle(RoomDetailAction.RedactAction(eventId, reason)) + } + .setNegativeButton(R.string.cancel, null) + .show() + } + private fun displayRoomDetailActionResult(result: Async) { when (result) { is Fail -> { @@ -1108,14 +1127,7 @@ class RoomDetailFragment @Inject constructor( showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT) } is EventSharedAction.Delete -> { - val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null) - AlertDialog.Builder(requireActivity()) - .setView(layout) - .setPositiveButton(R.string.delete) { _, _ -> - roomDetailViewModel.handle(RoomDetailAction.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason))) - } - .setNegativeButton(R.string.cancel, null) - .show() + promptReasonToDeleteEvent(action.eventId) } is EventSharedAction.Share -> { // TODO current data communication is too limited diff --git a/vector/src/main/res/layout/dialog_delete_event.xml b/vector/src/main/res/layout/dialog_delete_event.xml index 9a508c055e..eee3cc9df5 100644 --- a/vector/src/main/res/layout/dialog_delete_event.xml +++ b/vector/src/main/res/layout/dialog_delete_event.xml @@ -18,4 +18,33 @@ android:text="@string/delete_event_dialog_content" app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 28cf0dc948..914d3a1ddf 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -20,7 +20,10 @@ - Delete message? + Confirm Removal + Are you sure you wish to remove (delete) this event? Note that if you delete a room name or topic change, it could undo the change. + Include a reason + Reason for redacting