mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #2952 from Isira-Seneviratne/ClipboardHelper
Convert ClipboardHelper to an object.
This commit is contained in:
commit
1f00a98dd5
@ -3,15 +3,12 @@ package com.github.libretube.helpers
|
|||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.core.content.getSystemService
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
|
||||||
class ClipboardHelper(
|
object ClipboardHelper {
|
||||||
private val context: Context
|
fun save(context: Context, text: String) {
|
||||||
) {
|
|
||||||
fun save(text: String) {
|
|
||||||
val clipboard: ClipboardManager =
|
|
||||||
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
||||||
val clip = ClipData.newPlainText(context.getString(R.string.copied), text)
|
val clip = ClipData.newPlainText(context.getString(R.string.copied), text)
|
||||||
clipboard.setPrimaryClip(clip)
|
context.getSystemService<ClipboardManager>()!!.setPrimaryClip(clip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package com.github.libretube.ui.activities
|
package com.github.libretube.ui.activities
|
||||||
|
|
||||||
import android.content.ClipData
|
|
||||||
import android.content.ClipboardManager
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -15,6 +12,7 @@ import com.github.libretube.constants.PIPED_GITHUB_URL
|
|||||||
import com.github.libretube.constants.WEBLATE_URL
|
import com.github.libretube.constants.WEBLATE_URL
|
||||||
import com.github.libretube.constants.WEBSITE_URL
|
import com.github.libretube.constants.WEBSITE_URL
|
||||||
import com.github.libretube.databinding.ActivityAboutBinding
|
import com.github.libretube.databinding.ActivityAboutBinding
|
||||||
|
import com.github.libretube.helpers.ClipboardHelper
|
||||||
import com.github.libretube.helpers.IntentHelper
|
import com.github.libretube.helpers.IntentHelper
|
||||||
import com.github.libretube.ui.base.BaseActivity
|
import com.github.libretube.ui.base.BaseActivity
|
||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
@ -75,10 +73,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
|
|
||||||
private fun onLongClick(href: String) {
|
private fun onLongClick(href: String) {
|
||||||
// copy the link to the clipboard
|
// copy the link to the clipboard
|
||||||
val clipboard: ClipboardManager =
|
ClipboardHelper.save(this, href)
|
||||||
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
||||||
val clip = ClipData.newPlainText(getString(R.string.copied), href)
|
|
||||||
clipboard.setPrimaryClip(clip)
|
|
||||||
// show the snackBar with open action
|
// show the snackBar with open action
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
binding.root,
|
binding.root,
|
||||||
|
@ -113,7 +113,7 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
root.setOnLongClickListener {
|
root.setOnLongClickListener {
|
||||||
ClipboardHelper(root.context).save(comment.commentText ?: "")
|
ClipboardHelper.save(root.context, comment.commentText ?: "")
|
||||||
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class ErrorDialog : DialogFragment() {
|
|||||||
.setMessage(errorLog)
|
.setMessage(errorLog)
|
||||||
.setNegativeButton(R.string.okay, null)
|
.setNegativeButton(R.string.okay, null)
|
||||||
.setPositiveButton(R.string.copy) { _, _ ->
|
.setPositiveButton(R.string.copy) { _, _ ->
|
||||||
ClipboardHelper(requireContext()).save(errorLog)
|
ClipboardHelper.save(requireContext(), errorLog)
|
||||||
Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
|
Loading…
Reference in New Issue
Block a user