allow copying conversation numbers to clipboard

This commit is contained in:
tibbi 2020-11-03 22:15:28 +01:00
parent 524a3546c4
commit 7d8e1a2155
2 changed files with 12 additions and 0 deletions

View File

@ -39,6 +39,7 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
menu.apply { menu.apply {
findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false
findItem(R.id.cab_block_number).isVisible = isNougatPlus() findItem(R.id.cab_block_number).isVisible = isNougatPlus()
findItem(R.id.cab_copy_number).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false
} }
} }
@ -50,6 +51,7 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
when (id) { when (id) {
R.id.cab_add_number_to_contact -> addNumberToContact() R.id.cab_add_number_to_contact -> addNumberToContact()
R.id.cab_block_number -> askConfirmBlock() R.id.cab_block_number -> askConfirmBlock()
R.id.cab_copy_number -> copyNumberToClipboard()
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete() R.id.cab_delete -> askConfirmDelete()
} }
@ -110,6 +112,12 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
} }
} }
private fun copyNumberToClipboard() {
val conversation = getSelectedItems().firstOrNull() ?: return
activity.copyToClipboard(conversation.phoneNumber)
finishActMode()
}
private fun askConfirmDelete() { private fun askConfirmDelete() {
val itemsCnt = selectedKeys.size val itemsCnt = selectedKeys.size
val items = resources.getQuantityString(R.plurals.delete_conversations, itemsCnt, itemsCnt) val items = resources.getQuantityString(R.plurals.delete_conversations, itemsCnt, itemsCnt)

View File

@ -11,6 +11,10 @@
android:icon="@drawable/ic_minus_circle_vector" android:icon="@drawable/ic_minus_circle_vector"
android:title="@string/block_number" android:title="@string/block_number"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/cab_copy_number"
android:title="@string/copy_number_to_clipboard"
app:showAsAction="never" />
<item <item
android:id="@+id/cab_select_all" android:id="@+id/cab_select_all"
android:icon="@drawable/ic_select_all_vector" android:icon="@drawable/ic_select_all_vector"