mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
refactor: add clipboard helper and improve repo url copy (#946)
This commit is contained in:
parent
527046766a
commit
040ac77b1a
8 changed files with 74 additions and 58 deletions
|
@ -2,9 +2,6 @@ package com.lagradost.cloudstream3.ui.result
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Rect
|
||||
|
@ -34,7 +31,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
|||
import com.lagradost.cloudstream3.APIHolder
|
||||
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
|
||||
import com.lagradost.cloudstream3.CommonActivity
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.DubStatus
|
||||
import com.lagradost.cloudstream3.LoadResponse
|
||||
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
|
||||
|
@ -70,6 +66,7 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
|||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialogInstant
|
||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
|
||||
import com.lagradost.cloudstream3.utils.UIHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||
|
@ -757,14 +754,8 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
|||
resultReloadConnectionOpenInBrowser.isVisible = data is Resource.Failure
|
||||
|
||||
resultTitle.setOnLongClickListener {
|
||||
val titleToCopy = resultTitle.text
|
||||
val clipboardManager =
|
||||
activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?
|
||||
clipboardManager?.setPrimaryClip(ClipData.newPlainText("Title", titleToCopy))
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
showToast(R.string.copyTitle, Toast.LENGTH_SHORT)
|
||||
}
|
||||
return@setOnLongClickListener true
|
||||
clipboardHelper(txt(R.string.title), resultTitle.text)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,12 +81,12 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
|
|||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setSubscribedData
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setVideoWatchState
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.updateSubscribedData
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
/** This starts at 1 */
|
||||
data class EpisodeRange(
|
||||
// used to index data
|
||||
|
@ -1693,14 +1693,8 @@ class ResultViewModel2 : ViewModel() {
|
|||
LoadType.ExternalApp,
|
||||
txt(R.string.episode_action_copy_link)
|
||||
) { (result, index) ->
|
||||
val act = activity ?: return@acquireSingleLink
|
||||
val serviceClipboard =
|
||||
(act.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?)
|
||||
?: return@acquireSingleLink
|
||||
val link = result.links[index]
|
||||
val clip = ClipData.newPlainText(link.name, link.url)
|
||||
serviceClipboard.setPrimaryClip(clip)
|
||||
showToast(R.string.copy_link_toast, Toast.LENGTH_SHORT)
|
||||
clipboardHelper(txt(link.name), link.url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import com.lagradost.cloudstream3.databinding.MainSettingsBinding
|
|||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
||||
import com.lagradost.cloudstream3.ui.home.HomeFragment
|
||||
import com.lagradost.cloudstream3.ui.result.txt
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
|
@ -236,5 +238,13 @@ class SettingsFragment : Fragment() {
|
|||
settingsGeneral.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
val appVersion = getString(R.string.app_version)
|
||||
val commitInfo = getString(R.string.commit_hash)
|
||||
|
||||
binding?.appVersionInfo?.setOnLongClickListener{
|
||||
clipboardHelper(txt(R.string.extension_version), "$appVersion $commitInfo")
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package com.lagradost.cloudstream3.ui.settings
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.TransactionTooLargeException
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
|
@ -20,6 +16,7 @@ import com.lagradost.cloudstream3.databinding.LogcatBinding
|
|||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.network.initClient
|
||||
import com.lagradost.cloudstream3.services.BackupWorkManager
|
||||
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
|
||||
|
@ -30,6 +27,7 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
|||
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
|
||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||
|
@ -117,22 +115,15 @@ class SettingsUpdates : PreferenceFragmentCompat() {
|
|||
binding.text1.text = text
|
||||
|
||||
binding.copyBtt.setOnClickListener {
|
||||
// Can crash on too much text
|
||||
try {
|
||||
val serviceClipboard =
|
||||
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?)
|
||||
?: return@setOnClickListener
|
||||
val clip = ClipData.newPlainText("logcat", text)
|
||||
serviceClipboard.setPrimaryClip(clip)
|
||||
clipboardHelper(txt("Logcat"), text)
|
||||
dialog.dismissSafe(activity)
|
||||
} catch (e: TransactionTooLargeException) {
|
||||
showToast(R.string.clipboard_too_large)
|
||||
}
|
||||
}
|
||||
|
||||
binding.clearBtt.setOnClickListener {
|
||||
Runtime.getRuntime().exec("logcat -c")
|
||||
dialog.dismissSafe(activity)
|
||||
}
|
||||
|
||||
binding.saveBtt.setOnClickListener {
|
||||
var fileStream: OutputStream? = null
|
||||
try {
|
||||
|
@ -153,9 +144,11 @@ class SettingsUpdates : PreferenceFragmentCompat() {
|
|||
fileStream?.closeQuietly()
|
||||
}
|
||||
}
|
||||
|
||||
binding.closeBtt.setOnClickListener {
|
||||
dialog.dismissSafe(activity)
|
||||
}
|
||||
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
package com.lagradost.cloudstream3.ui.settings.extensions
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.lagradost.cloudstream3.CommonActivity.activity
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.RepositoryItemBinding
|
||||
import com.lagradost.cloudstream3.databinding.RepositoryItemTvBinding
|
||||
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
|
||||
import com.lagradost.cloudstream3.ui.result.txt
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
||||
|
||||
class RepoAdapter(
|
||||
val isSetup: Boolean,
|
||||
|
@ -121,13 +116,9 @@ class RepoAdapter(
|
|||
}
|
||||
|
||||
repositoryItemRoot.setOnLongClickListener {
|
||||
val clipboardManager =
|
||||
activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?
|
||||
clipboardManager?.setPrimaryClip(ClipData.newPlainText("RepoUrl", repositoryData.url))
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
showToast(R.string.copyRepoUrl, Toast.LENGTH_SHORT)
|
||||
}
|
||||
return@setOnLongClickListener true
|
||||
val shareableRepoData = "${repositoryData.name} : \n ${repositoryData.url}"
|
||||
clipboardHelper(txt(R.string.repo_copy_label), shareableRepoData)
|
||||
true
|
||||
}
|
||||
|
||||
mainText.text = repositoryData.name
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.annotation.SuppressLint
|
|||
import android.app.Activity
|
||||
import android.app.AppOpsManager
|
||||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
|
@ -14,12 +16,15 @@ 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
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.ImageView
|
||||
import android.widget.ListAdapter
|
||||
import android.widget.ListView
|
||||
import android.widget.Toast.LENGTH_LONG
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
|
@ -30,14 +35,12 @@ import androidx.appcompat.view.menu.MenuBuilder
|
|||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.alpha
|
||||
import androidx.core.graphics.blue
|
||||
import androidx.core.graphics.drawable.toBitmapOrNull
|
||||
import androidx.core.graphics.green
|
||||
import androidx.core.graphics.red
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.marginRight
|
||||
|
@ -58,17 +61,19 @@ import com.bumptech.glide.request.target.Target
|
|||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipDrawable
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||
import com.lagradost.cloudstream3.CommonActivity.activity
|
||||
import com.lagradost.cloudstream3.MainActivity
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.ui.result.UiImage
|
||||
import com.lagradost.cloudstream3.ui.result.UiText
|
||||
import com.lagradost.cloudstream3.ui.result.txt
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isEmulatorSettings
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||
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)
|
||||
|
@ -123,6 +128,35 @@ object UIHelper {
|
|||
)
|
||||
}
|
||||
|
||||
fun clipboardHelper(label: UiText, text: CharSequence) {
|
||||
val ctx = context ?: return
|
||||
try {
|
||||
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(ctx)} $labelSuffix")
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
Log.e("ClipboardService", "$t")
|
||||
when (t) {
|
||||
is SecurityException -> {
|
||||
showToast(R.string.clipboard_permission_error)
|
||||
}
|
||||
|
||||
is TransactionTooLargeException -> {
|
||||
showToast(R.string.clipboard_too_large)
|
||||
}
|
||||
|
||||
else -> {
|
||||
showToast(R.string.clipboard_unknown_error, LENGTH_LONG)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ListView height dynamically based on the height of the items.
|
||||
|
|
|
@ -105,9 +105,10 @@
|
|||
android:text="@string/extensions" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/app_version_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -174,8 +174,8 @@
|
|||
<string name="sort_close">Close</string>
|
||||
<string name="sort_clear">Clear</string>
|
||||
<string name="sort_save">Save</string>
|
||||
<string name="copyTitle">Title copied!</string>
|
||||
<string name="copyRepoUrl">Repo URL copied!</string>
|
||||
<string name="repo_copy_label">Repository name and URL</string>
|
||||
<string name="toast_copied">copied!</string>
|
||||
<string name="subscribe_tooltip">New episode notification</string>
|
||||
<string name="result_search_tooltip">Search in other extensions</string>
|
||||
<string name="recommendations_tooltip">Show recommendations</string>
|
||||
|
@ -647,6 +647,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, 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…
Reference in a new issue