mirror of
https://github.com/fromchat-messenger/app.git
synced 2026-09-23 03:25:06 +03:00
Make a robust sending system
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.pr0gramm3r101.utils
|
||||
|
||||
import android.content.ClipData as AndroidClipData
|
||||
import androidx.compose.ui.platform.ClipEntry
|
||||
import androidx.compose.ui.platform.Clipboard
|
||||
|
||||
actual fun Clipboard.toSupport(): SupportClipboardManager {
|
||||
val clipboard = this
|
||||
return object : SupportClipboardManager {
|
||||
private var listener: ((String) -> Unit)? = null
|
||||
|
||||
override suspend fun setText(string: String) {
|
||||
val clipData = AndroidClipData.newPlainText("text", string)
|
||||
clipboard.setClipEntry(ClipEntry(clipData))
|
||||
listener?.invoke(string)
|
||||
}
|
||||
|
||||
override suspend fun getText(): String? {
|
||||
val entry = clipboard.getClipEntry() ?: return null
|
||||
return entry.clipData?.getItemAt(0)?.text?.toString()
|
||||
}
|
||||
|
||||
override fun setTextListener(listener: (String) -> Unit) {
|
||||
this.listener = listener
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -7,7 +7,9 @@ internal actual fun expectExists(path: String): Boolean =
|
||||
File(path).exists()
|
||||
|
||||
internal actual fun expectWriteBytes(path: String, bytes: ByteArray) {
|
||||
File(path).writeBytes(bytes)
|
||||
val file = File(path)
|
||||
file.parentFile?.mkdirs()
|
||||
file.writeBytes(bytes)
|
||||
}
|
||||
|
||||
internal actual fun expectDelete(path: String) {
|
||||
|
||||
Reference in New Issue
Block a user