mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-18 04:30:55 +01:00
allow copying a message value into the clipboard easily
This commit is contained in:
parent
e1f1583b17
commit
bed6ef764f
@ -36,7 +36,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.24.15'
|
implementation 'com.simplemobiletools:commons:5.24.16'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,13 @@ class ThreadAdapter(
|
|||||||
setupDragListener(true)
|
setupDragListener(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getActionMenuId() = R.menu.cab_messages
|
override fun getActionMenuId() = R.menu.cab_thread
|
||||||
|
|
||||||
override fun prepareActionMode(menu: Menu) {}
|
override fun prepareActionMode(menu: Menu) {
|
||||||
|
menu.apply {
|
||||||
|
findItem(R.id.cab_copy_to_clipboard).isVisible = isOneItemSelected()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun actionItemPressed(id: Int) {
|
override fun actionItemPressed(id: Int) {
|
||||||
if (selectedKeys.isEmpty()) {
|
if (selectedKeys.isEmpty()) {
|
||||||
@ -41,6 +45,7 @@ class ThreadAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
when (id) {
|
when (id) {
|
||||||
|
R.id.cab_copy_to_clipboard -> copyToClipboard()
|
||||||
R.id.cab_select_all -> selectAll()
|
R.id.cab_select_all -> selectAll()
|
||||||
R.id.cab_delete -> askConfirmDelete()
|
R.id.cab_delete -> askConfirmDelete()
|
||||||
}
|
}
|
||||||
@ -92,6 +97,11 @@ class ThreadAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun copyToClipboard() {
|
||||||
|
val firstItem = getSelectedItems().first() as? Message ?: return
|
||||||
|
activity.copyToClipboard(firstItem.body)
|
||||||
|
}
|
||||||
|
|
||||||
private fun askConfirmDelete() {
|
private fun askConfirmDelete() {
|
||||||
val itemsCnt = selectedKeys.size
|
val itemsCnt = selectedKeys.size
|
||||||
val items = resources.getQuantityString(R.plurals.delete_messages, itemsCnt, itemsCnt)
|
val items = resources.getQuantityString(R.plurals.delete_messages, itemsCnt, itemsCnt)
|
||||||
@ -128,6 +138,8 @@ class ThreadAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSelectedItems() = messages.filter { selectedKeys.contains((it as? Message)?.id ?: 0) } as ArrayList<ThreadItem>
|
||||||
|
|
||||||
private fun isThreadDateTime(position: Int) = messages.getOrNull(position) is ThreadDateTime
|
private fun isThreadDateTime(position: Int) = messages.getOrNull(position) is ThreadDateTime
|
||||||
|
|
||||||
private fun setupView(view: View, message: Message) {
|
private fun setupView(view: View, message: Message) {
|
||||||
|
19
app/src/main/res/menu/cab_thread.xml
Normal file
19
app/src/main/res/menu/cab_thread.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/cab_copy_to_clipboard"
|
||||||
|
android:icon="@drawable/ic_copy"
|
||||||
|
android:title="@string/copy_to_clipboard"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/cab_select_all"
|
||||||
|
android:icon="@drawable/ic_select_all_vector"
|
||||||
|
android:title="@string/select_all"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/cab_delete"
|
||||||
|
android:icon="@drawable/ic_delete_vector"
|
||||||
|
android:title="@string/delete"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
</menu>
|
Loading…
x
Reference in New Issue
Block a user