Merge pull request #982 from vector-im/feature/remove_message_step2

Redact message step2
This commit is contained in:
Benoit Marty 2020-02-11 11:35:16 +01:00 committed by GitHub
commit 251de0b89c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 19 deletions

View file

@ -64,6 +64,7 @@ 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.google.android.material.textfield.TextInputLayout
import com.jakewharton.rxbinding3.widget.textChanges
import im.vector.matrix.android.api.permalinks.PermalinkFactory
import im.vector.matrix.android.api.session.Session
@ -787,16 +788,17 @@ class RoomDetailFragment @Inject constructor(
.show()
}
private fun promptReasonToDeleteEvent(eventId: String) {
private fun promptReasonToRedactEvent(eventId: String) {
val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null)
val reasonCheckBox = layout.findViewById<MaterialCheckBox>(R.id.deleteEventReasonCheck)
val reasonTextInputLayout = layout.findViewById<TextInputLayout>(R.id.deleteEventReasonTextInputLayout)
val reasonInput = layout.findViewById<TextInputEditText>(R.id.deleteEventReasonInput)
reasonCheckBox.setOnCheckedChangeListener { _, isChecked -> reasonInput.isEnabled = isChecked }
reasonCheckBox.setOnCheckedChangeListener { _, isChecked -> reasonTextInputLayout.isEnabled = isChecked }
AlertDialog.Builder(requireActivity())
.setView(layout)
.setTitle(R.string.delete_event_dialog_title)
.setView(layout)
.setPositiveButton(R.string.remove) { _, _ ->
val reason = reasonInput.text.toString()
.takeIf { reasonCheckBox.isChecked }
@ -1118,8 +1120,8 @@ class RoomDetailFragment @Inject constructor(
copyToClipboard(requireContext(), action.content, false)
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
}
is EventSharedAction.Delete -> {
promptReasonToDeleteEvent(action.eventId)
is EventSharedAction.Redact -> {
promptReasonToRedactEvent(action.eventId)
}
is EventSharedAction.Share -> {
// TODO current data communication is too limited

View file

@ -22,7 +22,9 @@ import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorSharedAction
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
sealed class EventSharedAction(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int) : VectorSharedAction {
sealed class EventSharedAction(@StringRes val titleRes: Int,
@DrawableRes val iconResId: Int,
val destructive: Boolean = false) : VectorSharedAction {
object Separator :
EventSharedAction(0, 0)
@ -51,10 +53,10 @@ sealed class EventSharedAction(@StringRes val titleRes: Int, @DrawableRes val ic
EventSharedAction(R.string.global_retry, R.drawable.ic_refresh_cw)
data class Remove(val eventId: String) :
EventSharedAction(R.string.remove, R.drawable.ic_trash)
EventSharedAction(R.string.remove, R.drawable.ic_trash, true)
data class Delete(val eventId: String) :
EventSharedAction(R.string.delete, R.drawable.ic_delete)
data class Redact(val eventId: String) :
EventSharedAction(R.string.message_action_item_redact, R.drawable.ic_delete, true)
data class Cancel(val eventId: String) :
EventSharedAction(R.string.cancel, R.drawable.ic_close_round)
@ -81,7 +83,7 @@ sealed class EventSharedAction(@StringRes val titleRes: Int, @DrawableRes val ic
EventSharedAction(R.string.report_content_custom, R.drawable.ic_report_custom)
data class IgnoreUser(val senderId: String?) :
EventSharedAction(R.string.message_ignore_user, R.drawable.ic_alert_triangle)
EventSharedAction(R.string.message_ignore_user, R.drawable.ic_alert_triangle, true)
data class QuickReact(val eventId: String, val clickedOn: String, val add: Boolean) :
EventSharedAction(0, 0)

View file

@ -111,7 +111,7 @@ class MessageActionsEpoxyController @Inject constructor(
showExpand(action is EventSharedAction.ReportContent)
expanded(state.expendedReportContentMenu)
listener(View.OnClickListener { listener?.didSelectMenuAction(action) })
destructive(action is EventSharedAction.IgnoreUser)
destructive(action.destructive)
}
if (action is EventSharedAction.ReportContent && state.expendedReportContentMenu) {

View file

@ -227,7 +227,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
}
if (canRedact(timelineEvent, session.myUserId)) {
add(EventSharedAction.Delete(eventId))
add(EventSharedAction.Redact(eventId))
}
if (canCopy(msgType)) {

View file

@ -22,28 +22,29 @@
android:id="@+id/deleteEventReasonCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
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"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/deleteEventConfirmationText" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/deleteEventReasonTextInputLayout"
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_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
app:layout_constraintTop_toBottomOf="@+id/deleteEventReasonCheck">
<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"/>
android:text="@string/event_redacted_by_user_reason" />
</com.google.android.material.textfield.TextInputLayout>

View file

@ -11,7 +11,7 @@
<!-- BEGIN Strings added by Benoit -->
<string name="message_action_item_redact">Remove…</string>
<!-- END Strings added by Benoit -->