Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show toast message after version text copied #6966

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
Loading