add UI options for delete messages

This commit is contained in:
ryanzhao 2021-08-13 15:30:26 +10:00
parent 4f89c33676
commit aad58043d3
3 changed files with 114 additions and 14 deletions

View File

@ -1167,22 +1167,41 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} }
override fun deleteMessages(messages: Set<MessageRecord>) { override fun deleteMessages(messages: Set<MessageRecord>) {
val messageCount = messages.size if (thread.isOpenGroupRecipient) {
val builder = AlertDialog.Builder(this) val messageCount = messages.size
builder.setTitle(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount)) val builder = AlertDialog.Builder(this)
builder.setMessage(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount)) builder.setTitle(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
builder.setCancelable(true) builder.setMessage(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
builder.setPositiveButton(R.string.delete) { _, _ -> builder.setCancelable(true)
for (message in messages) { builder.setPositiveButton(R.string.delete) { _, _ ->
this.deleteForEveryone(message) for (message in messages) {
this.deleteForEveryone(message)
}
endActionMode()
} }
endActionMode() builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
dialog.dismiss()
endActionMode()
}
builder.show()
} else {
val bottomSheet = DeleteOptionsBottomSheet()
bottomSheet.recipient = thread
bottomSheet.onDeleteForMeTapped = {
for (message in messages) {
this.deleteLocally(message)
}
bottomSheet.dismiss()
}
bottomSheet.onDeleteForEveryoneTapped = {
for (message in messages) {
this.deleteForEveryone(message)
}
bottomSheet.dismiss()
}
bottomSheet.onCancelTapped = { bottomSheet.dismiss() }
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
} }
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
dialog.dismiss()
endActionMode()
}
builder.show()
} }
override fun banUser(messages: Set<MessageRecord>) { override fun banUser(messages: Set<MessageRecord>) {

View File

@ -0,0 +1,52 @@
package org.thoughtcrime.securesms.conversation.v2
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.android.synthetic.main.fragment_conversation_bottom_sheet.*
import kotlinx.android.synthetic.main.fragment_delete_message_bottom_sheet.*
import network.loki.messenger.R
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.util.UiModeUtilities
class DeleteOptionsBottomSheet: BottomSheetDialogFragment(), View.OnClickListener {
lateinit var recipient: Recipient
var onDeleteForMeTapped: (() -> Unit?)? = null
var onDeleteForEveryoneTapped: (() -> Unit)? = null
var onCancelTapped: (() -> Unit)? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_delete_message_bottom_sheet, container, false)
}
override fun onClick(v: View?) {
when (v) {
deleteForMeTextView -> onDeleteForMeTapped?.invoke()
deleteForEveryoneTextView -> onDeleteForEveryoneTapped?.invoke()
cancelTextView -> onCancelTapped?.invoke()
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (!this::recipient.isInitialized) { return dismiss() }
if (!recipient.isGroupRecipient) {
deleteForEveryoneTextView.text = resources.getString(R.string.delete_message_for_me_and_recipient, recipient.name)
}
deleteForMeTextView.setOnClickListener(this)
deleteForEveryoneTextView.setOnClickListener(this)
cancelTextView.setOnClickListener(this)
}
override fun onStart() {
super.onStart()
val window = dialog?.window ?: return
val isLightMode = UiModeUtilities.isDayUiMode(requireContext())
window.setDimAmount(if (isLightMode) 0.1f else 0.75f)
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<TextView
android:id="@+id/deleteForMeTextView"
style="@style/BottomSheetActionItem"
android:text="@string/delete_message_for_me"
android:textColor="@color/core_red"/>
<TextView
android:id="@+id/deleteForEveryoneTextView"
style="@style/BottomSheetActionItem"
android:text="@string/delete_message_for_everyone"
android:textColor="@color/core_red"/>
<TextView
android:id="@+id/cancelTextView"
style="@style/BottomSheetActionItem"
android:text="@string/cancel" />
</LinearLayout>