Skip to content

Commit

Permalink
Improved copy clipboard #3035
Browse files Browse the repository at this point in the history
  • Loading branch information
fast4x committed Jul 31, 2024
1 parent f8a64f7 commit 97b2805
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/src/main/kotlin/it/fast4x/rimusic/utils/ClipBoard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.res.stringResource
import it.fast4x.rimusic.R
import it.fast4x.rimusic.enums.PopupType
import it.fast4x.rimusic.ui.components.themed.SmartMessage
import timber.log.Timber

@Composable
fun TextCopyToClipboard(textCopied:String) {
Expand All @@ -22,7 +23,8 @@ fun TextCopyToClipboard(textCopied:String) {
runCatching {
clipboardManager.setPrimaryClip(ClipData.newPlainText("", textCopied))
}.onFailure {
SmartMessage("Failed to copy text to clipbaoard ${it.stackTraceToString()}", type = PopupType.Error, context = context)
Timber.e(it.stackTraceToString())
SmartMessage("Failed to copy text to clipbaoard, try again", type = PopupType.Error, context = context)
}
// Only show a toast for Android 12 and lower.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2)
Expand All @@ -37,11 +39,12 @@ fun textCopyFromClipboard(): String {
runCatching {
textCopied = clipboardManager.primaryClip?.getItemAt(0)?.coerceToText(context).toString()
}.onFailure {
SmartMessage("Failed to copy text from clipbaoard ${it.stackTraceToString()}", type = PopupType.Error, context = context)
Timber.e(it.stackTraceToString())
SmartMessage("Failed to copy text from clipbaoard, try again", type = PopupType.Error, context = context)
}
// Only show a toast for Android 12 and lower.
//if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2)
// SmartToast(context.resources.getString(R.string.value_copied), type = PopupType.Info)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2)
SmartMessage(context.resources.getString(R.string.value_copied), type = PopupType.Info, context = context)

return textCopied
}

0 comments on commit 97b2805

Please sign in to comment.