feat: show toast message after version text copied

This commit is contained in:
Bnyro 2025-01-16 17:47:51 +01:00
parent 5e53df095a
commit 643c63c629
4 changed files with 16 additions and 8 deletions

View File

@ -3,12 +3,23 @@ package com.github.libretube.helpers
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.widget.Toast
import androidx.core.content.getSystemService
import com.github.libretube.R
object ClipboardHelper {
fun save(context: Context, label: String = context.getString(R.string.copied), text: String) {
fun save(
context: Context,
label: String = context.getString(R.string.copied),
text: String,
notify: Boolean = false
) {
val clip = ClipData.newPlainText(label, text)
context.getSystemService<ClipboardManager>()!!.setPrimaryClip(clip)
if (notify && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
Toast.makeText(context, context.getString(R.string.copied), Toast.LENGTH_SHORT).show()
}
}
}

View File

@ -41,7 +41,7 @@ class AboutActivity : BaseActivity() {
val versionText = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
binding.versionTv.text = versionText
binding.versionCard.setOnClickListener {
ClipboardHelper.save(this, text = versionText)
ClipboardHelper.save(this, text = versionText, notify = true)
}
setupCard(binding.donate, DONATE_URL)

View File

@ -3,7 +3,6 @@ package com.github.libretube.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.os.bundleOf
import androidx.core.text.method.LinkMovementMethodCompat
@ -127,9 +126,9 @@ class CommentPagingAdapter(
root.setOnLongClickListener {
ClipboardHelper.save(
root.context,
text = comment.commentText.orEmpty().parseAsHtml().toString()
text = comment.commentText.orEmpty().parseAsHtml().toString(),
notify = true
)
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
true
}
}

View File

@ -3,7 +3,6 @@ package com.github.libretube.ui.dialogs
import android.annotation.SuppressLint
import android.app.Dialog
import android.os.Bundle
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
import com.github.libretube.helpers.ClipboardHelper
@ -22,8 +21,7 @@ class ErrorDialog : DialogFragment() {
.setMessage(errorLog)
.setNegativeButton(R.string.okay, null)
.setPositiveButton(androidx.preference.R.string.copy) { _, _ ->
ClipboardHelper.save(requireContext(), text = errorLog)
Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show()
ClipboardHelper.save(requireContext(), text = errorLog, notify = true)
}
.show()
}