mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Merge pull request #5379 from Isira-Seneviratne/ClipboardHelper
refactor: Improve ClipboardHelper
This commit is contained in:
commit
8f13d13084
@ -7,8 +7,8 @@ import androidx.core.content.getSystemService
|
||||
import com.github.libretube.R
|
||||
|
||||
object ClipboardHelper {
|
||||
fun save(context: Context, text: String) {
|
||||
val clip = ClipData.newPlainText(context.getString(R.string.copied), text)
|
||||
fun save(context: Context, label: String = context.getString(R.string.copied), text: String) {
|
||||
val clip = ClipData.newPlainText(label, text)
|
||||
context.getSystemService<ClipboardManager>()!!.setPrimaryClip(clip)
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class AboutActivity : BaseActivity() {
|
||||
|
||||
private fun onLongClick(href: String) {
|
||||
// copy the link to the clipboard
|
||||
ClipboardHelper.save(this, href)
|
||||
ClipboardHelper.save(this, text = href)
|
||||
// show the snackBar with open action
|
||||
Snackbar.make(
|
||||
binding.root,
|
||||
|
@ -136,7 +136,7 @@ class CommentsAdapter(
|
||||
root.setOnLongClickListener {
|
||||
ClipboardHelper.save(
|
||||
root.context,
|
||||
comment.commentText.orEmpty().parseAsHtml().toString()
|
||||
text = comment.commentText.orEmpty().parseAsHtml().toString()
|
||||
)
|
||||
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
|
@ -22,7 +22,7 @@ class ErrorDialog : DialogFragment() {
|
||||
.setMessage(errorLog)
|
||||
.setNegativeButton(R.string.okay, null)
|
||||
.setPositiveButton(androidx.preference.R.string.copy) { _, _ ->
|
||||
ClipboardHelper.save(requireContext(), errorLog)
|
||||
ClipboardHelper.save(requireContext(), text = errorLog)
|
||||
Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
.show()
|
||||
|
@ -1,19 +1,13 @@
|
||||
package com.github.libretube.ui.sheets
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import androidx.core.content.getSystemService
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogStatsBinding
|
||||
import com.github.libretube.extensions.parcelable
|
||||
import com.github.libretube.helpers.ClipboardHelper
|
||||
import com.github.libretube.obj.VideoStats
|
||||
|
||||
class StatsSheet : ExpandedBottomSheet() {
|
||||
@ -35,19 +29,12 @@ class StatsSheet : ExpandedBottomSheet() {
|
||||
stats = arguments?.parcelable(IntentData.videoStats)!!
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val binding = binding
|
||||
|
||||
val clipboardManager = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
context?.getSystemService(ClipboardManager::class.java)!!
|
||||
} else {
|
||||
context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
}
|
||||
|
||||
binding.videoId.setText(stats.videoId)
|
||||
binding.videoIdCopy.setEndIconOnClickListener {
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText("text", stats.videoId))
|
||||
ClipboardHelper.save(requireContext(), "text", stats.videoId)
|
||||
}
|
||||
binding.videoInfo.setText(stats.videoInfo)
|
||||
binding.audioInfo.setText(stats.audioInfo)
|
||||
|
Loading…
x
Reference in New Issue
Block a user