Reason input for redacting event is added.

This commit is contained in:
onurays 2020-02-10 23:03:37 +03:00
parent 1bc1c8ec4a
commit ba0133a047
3 changed files with 53 additions and 9 deletions

View File

@ -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<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 = 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<RoomDetailAction>) {
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

View File

@ -18,4 +18,33 @@
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>

View File

@ -20,7 +20,10 @@
<!-- END Strings added by Benoit -->
<!-- BEGIN Strings added by Onuray -->
<string name="delete_event_dialog_content">Delete message?</string>
<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 -->