mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
adapt, improvise and overcome
This commit is contained in:
parent
55ab5a45af
commit
b58d4cc835
5 changed files with 30 additions and 21 deletions
|
@ -1693,8 +1693,7 @@ class ResultViewModel2 : ViewModel() {
|
|||
txt(R.string.episode_action_copy_link)
|
||||
) { (result, index) ->
|
||||
val link = result.links[index]
|
||||
val linkCopyLabel = UiText.DynamicString(link.name)
|
||||
clipboardHelper(linkCopyLabel, link.url)
|
||||
clipboardHelper(txt(link.name), link.url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.lagradost.cloudstream3.mvvm.logError
|
|||
import com.lagradost.cloudstream3.network.initClient
|
||||
import com.lagradost.cloudstream3.services.BackupWorkManager
|
||||
import com.lagradost.cloudstream3.ui.result.UiText
|
||||
import com.lagradost.cloudstream3.ui.result.txt
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags
|
||||
|
@ -116,14 +117,8 @@ class SettingsUpdates : PreferenceFragmentCompat() {
|
|||
binding.text1.text = text
|
||||
|
||||
binding.copyBtt.setOnClickListener {
|
||||
// Can crash on too much text
|
||||
try {
|
||||
val logcat = UiText.DynamicString("Logcat")
|
||||
clipboardHelper(logcat, text)
|
||||
dialog.dismissSafe(activity)
|
||||
} catch (e: TransactionTooLargeException) {
|
||||
showToast(R.string.clipboard_too_large)
|
||||
}
|
||||
clipboardHelper(txt("Logcat"), text)
|
||||
dialog.dismissSafe(activity)
|
||||
}
|
||||
|
||||
binding.clearBtt.setOnClickListener {
|
||||
|
|
|
@ -117,8 +117,7 @@ class RepoAdapter(
|
|||
|
||||
repositoryItemRoot.setOnLongClickListener {
|
||||
val shareableRepoData = "${repositoryData.name} : \n ${repositoryData.url}"
|
||||
val repoCopyLabel = txt(R.string.repo_copy_label)
|
||||
clipboardHelper(repoCopyLabel, shareableRepoData)
|
||||
clipboardHelper(txt(R.string.repo_copy_label), shareableRepoData)
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.graphics.Color
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.TransactionTooLargeException
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.ViewGroup.MarginLayoutParams
|
||||
|
@ -23,7 +24,7 @@ import android.view.inputmethod.InputMethodManager
|
|||
import android.widget.ImageView
|
||||
import android.widget.ListAdapter
|
||||
import android.widget.ListView
|
||||
import android.widget.Toast
|
||||
import android.widget.Toast.LENGTH_LONG
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
|
@ -63,7 +64,6 @@ import com.google.android.material.chip.ChipGroup
|
|||
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||
import com.lagradost.cloudstream3.CommonActivity.activity
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.MainActivity
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.ui.result.UiImage
|
||||
|
@ -74,7 +74,6 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSet
|
|||
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
object UIHelper {
|
||||
val Int.toPx: Int get() = (this * Resources.getSystem().displayMetrics.density).toInt()
|
||||
val Float.toPx: Float get() = (this * Resources.getSystem().displayMetrics.density)
|
||||
|
@ -130,17 +129,32 @@ object UIHelper {
|
|||
}
|
||||
|
||||
fun clipboardHelper(label: UiText, text: CharSequence) {
|
||||
val ctx = context ?: return
|
||||
try {
|
||||
val clip = ClipData.newPlainText(label.asString(context!!), text)
|
||||
val labelSuffix = txt(R.string.toast_copied)
|
||||
context?.getSystemService<ClipboardManager>()!!.setPrimaryClip(clip)
|
||||
ctx.let {
|
||||
val clip = ClipData.newPlainText(label.asString(ctx), text)
|
||||
val labelSuffix = txt(R.string.toast_copied).asString(ctx)
|
||||
ctx.getSystemService<ClipboardManager>()?.setPrimaryClip(clip)
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
showToast("${label.asString(context!!)} ${labelSuffix.asString(context!!)}")
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
showToast("$label $labelSuffix")
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
Log.e("ClipboardService", "$t")
|
||||
showToast(R.string.clipboard_too_large)
|
||||
when (t) {
|
||||
is SecurityException -> {
|
||||
showToast(R.string.clipboard_permission_error)
|
||||
}
|
||||
|
||||
is TransactionTooLargeException -> {
|
||||
showToast(R.string.clipboard_too_large)
|
||||
}
|
||||
|
||||
else -> {
|
||||
showToast(R.string.unexpected_error, LENGTH_LONG)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -645,6 +645,8 @@
|
|||
<string name="history">History</string>
|
||||
<string name="enable_skip_op_from_database_des">Show skip popups for opening/ending</string>
|
||||
<string name="clipboard_too_large">Too much text. Unable to save to clipboard.</string>
|
||||
<string name="clipboard_permission_error">Error accessing Clipboard, Please try again.</string>
|
||||
<string name="clipboard_unknown_error">Error copying content, Please copy logcat and contact app support.</string>
|
||||
<string name="action_mark_as_watched">Mark as watched</string>
|
||||
<string name="action_remove_from_watched">Remove from watched</string>
|
||||
<string name="confirm_exit_dialog">Are you sure you want to exit\?</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue