improve delete option ui

This commit is contained in:
ryanzhao 2021-08-16 12:08:35 +10:00
parent 4ce1bd6875
commit e8551a3545
3 changed files with 22 additions and 3 deletions

View File

@ -1170,6 +1170,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
override fun deleteMessages(messages: Set<MessageRecord>) {
val allSentByCurrentUser = messages.all { it.isOutgoing }
if (thread.isOpenGroupRecipient) {
val messageCount = messages.size
val builder = AlertDialog.Builder(this)
@ -1187,7 +1188,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
endActionMode()
}
builder.show()
} else {
} else if (allSentByCurrentUser) {
val bottomSheet = DeleteOptionsBottomSheet()
bottomSheet.recipient = thread
bottomSheet.onDeleteForMeTapped = {
@ -1209,6 +1210,23 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
endActionMode()
}
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
} else {
val messageCount = messages.size
val builder = AlertDialog.Builder(this)
builder.setTitle(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
builder.setMessage(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
builder.setCancelable(true)
builder.setPositiveButton(R.string.delete) { _, _ ->
for (message in messages) {
this.deleteLocally(message)
}
endActionMode()
}
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
dialog.dismiss()
endActionMode()
}
builder.show()
}
}

View File

@ -34,8 +34,9 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p
val thread = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)!!
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
fun userCanDeleteSelectedItems(): Boolean {
if (openGroup == null) { return true }
val allSentByCurrentUser = selectedItems.all { it.isOutgoing }
val allReceivedByByCurrentUser = selectedItems.all { !it.isOutgoing }
if (openGroup == null) { return allSentByCurrentUser || allReceivedByByCurrentUser }
if (allSentByCurrentUser) { return true }
return OpenGroupAPIV2.isUserModerator(userPublicKey, openGroup.room, openGroup.server)
}

View File

@ -128,7 +128,7 @@ public class MmsSmsDatabase extends Database {
public Cursor getConversationSnippet(long threadId) {
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
return queryTables(PROJECTION, selection, order, null);
}