From af99b0121e97b80f5d30fbbc0961747039e84bf6 Mon Sep 17 00:00:00 2001 From: IndusAryan Date: Wed, 21 Feb 2024 15:23:33 +0530 Subject: [PATCH] refactor --- .../cloudstream3/ui/result/ResultFragmentPhone.kt | 8 +------- .../cloudstream3/ui/result/ResultViewModel2.kt | 4 ++-- .../cloudstream3/ui/settings/SettingsFragment.kt | 7 ------- .../cloudstream3/ui/settings/SettingsUpdates.kt | 14 +++----------- .../ui/settings/extensions/RepoAdapter.kt | 7 +++---- .../com/lagradost/cloudstream3/utils/UIHelper.kt | 13 ++++++++----- 6 files changed, 17 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt index 449b3c8c..431fedcd 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt @@ -754,16 +754,10 @@ open class ResultFragmentPhone : FullScreenPlayer() { resultReloadConnectionOpenInBrowser.isVisible = data is Resource.Failure resultTitle.setOnLongClickListener { - val titleString = activity?.getString(R.string.title) as String + val titleString = txt(R.string.title) clipboardHelper(titleString, resultTitle.text) true } - - resultDescription.setOnLongClickListener { - val synopsisString = activity?.getString(R.string.torrent_plot) as String - clipboardHelper(synopsisString, resultDescription.text) - true - } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index 879dc8d3..d9e73371 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -1693,8 +1693,8 @@ class ResultViewModel2 : ViewModel() { txt(R.string.episode_action_copy_link) ) { (result, index) -> val link = result.links[index] - val clip = "${link.name} , ${link.url}" - clipboardHelper(link.name, clip ) + val linkCopyLabel = UiText.DynamicString(link.name) + clipboardHelper(linkCopyLabel, link.url) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 2e61d5c4..37c71134 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -19,7 +19,6 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.MaterialToolbar -import com.lagradost.cloudstream3.AcraApplication.Companion.context import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.databinding.MainSettingsBinding import com.lagradost.cloudstream3.mvvm.logError @@ -156,12 +155,6 @@ class SettingsFragment : Fragment() { return getLayoutInt() == 2 } - // phone exclusive - fun isTruePhone(): Boolean { - return !isTrueTvSettings() && !isTvSettings() && context?.isEmulatorSettings() != true - && context?.isAutoTv() != true && !isTrueTv && !isTv - } - private fun Context.isAutoTv(): Boolean { val uiModeManager = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager? // AFT = Fire TV diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index ac71cf5c..53c42b1c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -1,7 +1,5 @@ package com.lagradost.cloudstream3.ui.settings -import android.content.Intent -import android.net.Uri import android.os.Bundle import android.os.TransactionTooLargeException import android.view.View @@ -19,8 +17,8 @@ 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.UiText import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref -import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTruePhone import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar @@ -115,19 +113,13 @@ class SettingsUpdates : PreferenceFragmentCompat() { } val text = log.toString() - val lagraAppsSupportUri = "https://discord.com/channels/737724143126052974/737725084881387652" binding.text1.text = text binding.copyBtt.setOnClickListener { // Can crash on too much text try { - clipboardHelper("Logcat", text) - // copy log and open support channel of Lagra apps server - if (isTruePhone()) - { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(lagraAppsSupportUri))) - } - + val logcat = UiText.DynamicString("Logcat") + clipboardHelper(logcat, text) dialog.dismissSafe(activity) } catch (e: TransactionTooLargeException) { showToast(R.string.clipboard_too_large) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt index c46ffeec..af9572ce 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt @@ -5,11 +5,11 @@ import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding -import com.lagradost.cloudstream3.CommonActivity.activity 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 @@ -117,9 +117,8 @@ class RepoAdapter( repositoryItemRoot.setOnLongClickListener { val shareableRepoData = "${repositoryData.name} : \n ${repositoryData.url}" - val copyLabel = activity?.getString(R.string.repo_copy_label) as String - - clipboardHelper(copyLabel, shareableRepoData) + val repoCopyLabel = txt(R.string.repo_copy_label) + clipboardHelper(repoCopyLabel, shareableRepoData) true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt index 11b2cc64..527bac16 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -67,6 +67,8 @@ import com.lagradost.cloudstream3.MainActivity 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 @@ -127,17 +129,18 @@ object UIHelper { ) } - fun clipboardHelper(label: String, text: CharSequence) { + fun clipboardHelper(label: UiText, text: CharSequence) { try { - val clip = ClipData.newPlainText(label, text) - val labelSuffix = activity?.getString(R.string.toast_copied) as String + val clip = ClipData.newPlainText(label.asString(context!!), text) + val labelSuffix = txt(R.string.toast_copied) context?.getSystemService()!!.setPrimaryClip(clip) if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) { - showToast("$label $labelSuffix", Toast.LENGTH_SHORT) + showToast("${label.asString(context!!)} ${labelSuffix.asString(context!!)}") } - } catch (e: Exception) { + } catch (t: Throwable) { + Log.e("ClipboardService", "$t") showToast(R.string.clipboard_too_large) } }