Merge pull request #977 from vector-im/feature/event_deletion_dialog
Show confirmation dialog before deleting a message
This commit is contained in:
commit
7ccc1c559c
@ -5,7 +5,7 @@ Features ✨:
|
|||||||
-
|
-
|
||||||
|
|
||||||
Improvements 🙌:
|
Improvements 🙌:
|
||||||
-
|
- Show confirmation dialog before deleting a message (#967)
|
||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
-
|
-
|
||||||
|
@ -61,6 +61,7 @@ import com.airbnb.mvrx.fragmentViewModel
|
|||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import com.github.piasy.biv.BigImageViewer
|
import com.github.piasy.biv.BigImageViewer
|
||||||
import com.github.piasy.biv.loader.ImageLoader
|
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.snackbar.Snackbar
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
@ -786,6 +787,26 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun promptReasonToDeleteEvent(eventId: String) {
|
||||||
|
val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null)
|
||||||
|
val reasonCheckBox = layout.findViewById<MaterialCheckBox>(R.id.deleteEventReasonCheck)
|
||||||
|
val reasonInput = layout.findViewById<TextInputEditText>(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 = reasonInput.text.toString()
|
||||||
|
.takeIf { reasonCheckBox.isChecked }
|
||||||
|
?.takeIf { it.isNotBlank() }
|
||||||
|
roomDetailViewModel.handle(RoomDetailAction.RedactAction(eventId, reason))
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun displayRoomDetailActionFailure(result: RoomDetailViewEvents.ActionFailure) {
|
private fun displayRoomDetailActionFailure(result: RoomDetailViewEvents.ActionFailure) {
|
||||||
AlertDialog.Builder(requireActivity())
|
AlertDialog.Builder(requireActivity())
|
||||||
.setTitle(R.string.dialog_title_error)
|
.setTitle(R.string.dialog_title_error)
|
||||||
@ -1098,7 +1119,7 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
|
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
|
||||||
}
|
}
|
||||||
is EventSharedAction.Delete -> {
|
is EventSharedAction.Delete -> {
|
||||||
roomDetailViewModel.handle(RoomDetailAction.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason)))
|
promptReasonToDeleteEvent(action.eventId)
|
||||||
}
|
}
|
||||||
is EventSharedAction.Share -> {
|
is EventSharedAction.Share -> {
|
||||||
// TODO current data communication is too limited
|
// TODO current data communication is too limited
|
||||||
|
50
vector/src/main/res/layout/dialog_delete_event.xml
Normal file
50
vector/src/main/res/layout/dialog_delete_event.xml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/layout_root"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="?dialogPreferredPadding"
|
||||||
|
android:paddingLeft="?dialogPreferredPadding"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="?dialogPreferredPadding"
|
||||||
|
android:paddingRight="?dialogPreferredPadding"
|
||||||
|
android:paddingBottom="12dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/deleteEventConfirmationText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/delete_event_dialog_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<com.google.android.material.checkbox.MaterialCheckBox
|
||||||
|
android:id="@+id/deleteEventReasonCheck"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:checked="true"
|
||||||
|
android:text="@string/delete_event_dialog_reason_checkbox"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/deleteEventConfirmationText"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"/>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
style="@style/VectorTextInputLayout"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/delete_event_dialog_reason_hint"
|
||||||
|
app:counterEnabled="true"
|
||||||
|
app:counterMaxLength="240"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/deleteEventReasonCheck"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/deleteEventReasonInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/event_redacted_by_user_reason"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -19,6 +19,13 @@
|
|||||||
|
|
||||||
<!-- END Strings added by Benoit -->
|
<!-- END Strings added by Benoit -->
|
||||||
|
|
||||||
|
<!-- BEGIN Strings added by Onuray -->
|
||||||
|
<string name="delete_event_dialog_title">Confirm Removal</string>
|
||||||
|
<string name="delete_event_dialog_content">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.</string>
|
||||||
|
<string name="delete_event_dialog_reason_checkbox">Include a reason</string>
|
||||||
|
<string name="delete_event_dialog_reason_hint">Reason for redacting</string>
|
||||||
|
<!-- END Strings added by Onuray -->
|
||||||
|
|
||||||
|
|
||||||
<!-- BEGIN Strings added by Others -->
|
<!-- BEGIN Strings added by Others -->
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user