kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
feat: Copy message to clipboard (#1443)
rodzic
d76eac258b
commit
e412faecb9
|
@ -127,6 +127,7 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
|
|||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_messages, menu)
|
||||
menu.findItem(R.id.resendButton).isVisible = false
|
||||
menu.findItem(R.id.copyButton).isVisible = false
|
||||
mode.title = "1"
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
|
||||
package com.geeksville.mesh.ui
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
|
@ -40,6 +43,7 @@ import androidx.lifecycle.lifecycleScope
|
|||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.android.toast
|
||||
import com.geeksville.mesh.database.entity.QuickChatAction
|
||||
import com.geeksville.mesh.databinding.MessagesFragmentBinding
|
||||
import com.geeksville.mesh.model.Message
|
||||
|
@ -284,19 +288,20 @@ class MessagesFragment : Fragment(), Logging {
|
|||
actionMode?.title = selectedList.size.toString()
|
||||
}
|
||||
}
|
||||
|
||||
R.id.resendButton -> lifecycleScope.launch {
|
||||
debug("User clicked resendButton")
|
||||
var resendText = ""
|
||||
selectedList.forEach {
|
||||
resendText = resendText + it.text + System.lineSeparator()
|
||||
}
|
||||
if (resendText != "") {
|
||||
resendText = resendText.substring(0, resendText.length - 1)
|
||||
}
|
||||
val resendText = getSelectedMessagesText()
|
||||
binding.messageInputText.setText(resendText)
|
||||
mode.finish()
|
||||
}
|
||||
R.id.copyButton -> lifecycleScope.launch {
|
||||
val copyText = getSelectedMessagesText()
|
||||
val clipboardManager =
|
||||
requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText("message text", copyText))
|
||||
requireActivity().toast(getString(R.string.copied))
|
||||
mode.finish()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -313,4 +318,15 @@ class MessagesFragment : Fragment(), Logging {
|
|||
model.focusUserNode(node)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectedMessagesText(): String {
|
||||
var messageText = ""
|
||||
selectedList.forEach {
|
||||
messageText = messageText + it.text + System.lineSeparator()
|
||||
}
|
||||
if (messageText != "") {
|
||||
messageText = messageText.substring(0, messageText.length - 1)
|
||||
}
|
||||
return messageText
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M8,7h11v14H8z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillColor="@android:color/white"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"
|
||||
android:fillColor="@android:color/white"/>
|
||||
</vector>
|
|
@ -38,4 +38,9 @@
|
|||
android:icon="@drawable/ic_twotone_select_all_24"
|
||||
android:title="@string/select_all"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/copyButton"
|
||||
android:icon="@drawable/ic_twotone_content_copy_24"
|
||||
android:title="@string/copy"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
|
@ -277,4 +277,6 @@
|
|||
<item quantity="other">%d skoków</item>
|
||||
</plurals>
|
||||
<string name="traceroute_diff">Skoki do: %1$d. Skoki od: %2$d</string>
|
||||
<string name="copy">Kopiuj</string>
|
||||
<string name="copied">Skopiowano</string>
|
||||
</resources>
|
||||
|
|
|
@ -310,4 +310,6 @@
|
|||
<string name="selected">Selected</string>
|
||||
<string name="not_selected">Not Selected</string>
|
||||
<string name="unknown_age">Unknown Age</string>
|
||||
<string name="copy">Copy</string>
|
||||
<string name="copied">Copied</string>
|
||||
</resources>
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
<style name="MyActionBar" parent="@style/ThemeOverlay.MaterialComponents.ActionBar">
|
||||
<item name="background">@color/colorPrimary</item>
|
||||
<item name="android:textColorPrimary">@color/colorOnPrimary</item>
|
||||
<item name="tint">@color/colorOnPrimary</item>
|
||||
</style>
|
||||
|
||||
<style name="MyToolbar" parent="Widget.MaterialComponents.Toolbar">
|
||||
|
|
Ładowanie…
Reference in New Issue