Remove links to website in app & fix plugin deletion bug

This commit is contained in:
Blatzar 2022-10-10 23:57:50 +02:00
parent e2118c3271
commit a565319ecb
7 changed files with 89 additions and 75 deletions

View file

@ -16,7 +16,6 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.MainActivity.Companion.afterRepositoryLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterRepositoryLoadedEvent
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
@ -25,7 +24,6 @@ import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.plugins.RepositoryManager import com.lagradost.cloudstream3.plugins.RepositoryManager
import com.lagradost.cloudstream3.ui.result.setText import com.lagradost.cloudstream3.ui.result.setText
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
import com.lagradost.cloudstream3.utils.AppUtils.downloadAllPluginsDialog import com.lagradost.cloudstream3.utils.AppUtils.downloadAllPluginsDialog
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
@ -34,7 +32,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.widget.LinearRecycleViewLayoutManager import com.lagradost.cloudstream3.widget.LinearRecycleViewLayoutManager
import kotlinx.android.synthetic.main.add_repo_input.* import kotlinx.android.synthetic.main.add_repo_input.*
import kotlinx.android.synthetic.main.fragment_extensions.* import kotlinx.android.synthetic.main.fragment_extensions.*
import kotlinx.android.synthetic.main.fragment_extensions.list_repositories
const val PUBLIC_REPOSITORIES_LIST = "https://recloudstream.github.io/repos/" const val PUBLIC_REPOSITORIES_LIST = "https://recloudstream.github.io/repos/"
@ -128,20 +125,20 @@ class ExtensionsFragment : Fragment() {
} }
} }
list_repositories?.setOnClickListener { // list_repositories?.setOnClickListener {
// Open webview on tv if browser fails // // Open webview on tv if browser fails
val isTv = isTvSettings() // val isTv = isTvSettings()
openBrowser(PUBLIC_REPOSITORIES_LIST, isTv, this) // openBrowser(PUBLIC_REPOSITORIES_LIST, isTv, this)
//
// Set clipboard on TV because the browser might not exist or work properly // // Set clipboard on TV because the browser might not exist or work properly
if (isTv) { // if (isTv) {
val serviceClipboard = // val serviceClipboard =
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?) // (activity?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?)
?: return@setOnClickListener // ?: return@setOnClickListener
val clip = ClipData.newPlainText("Repository url", PUBLIC_REPOSITORIES_LIST) // val clip = ClipData.newPlainText("Repository url", PUBLIC_REPOSITORIES_LIST)
serviceClipboard.setPrimaryClip(clip) // serviceClipboard.setPrimaryClip(clip)
} // }
} // }
observe(extensionViewModel.pluginStats) { observe(extensionViewModel.pluginStats) {
when (it) { when (it) {
@ -200,11 +197,11 @@ class ExtensionsFragment : Fragment() {
} }
} }
dialog.list_repositories?.setOnClickListener { // dialog.list_repositories?.setOnClickListener {
// Open webview on tv if browser fails // // Open webview on tv if browser fails
openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this) // openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this)
dialog.dismissSafe() // dialog.dismissSafe()
} // }
// dialog.text2?.text = provider.name // dialog.text2?.text = provider.name
dialog.apply_btt?.setOnClickListener secondListener@{ dialog.apply_btt?.setOnClickListener secondListener@{

View file

@ -12,7 +12,6 @@ import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.apmap import com.lagradost.cloudstream3.apmap
import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.plugins.PluginData
import com.lagradost.cloudstream3.plugins.PluginManager import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.plugins.PluginManager.getPluginPath import com.lagradost.cloudstream3.plugins.PluginManager.getPluginPath
import com.lagradost.cloudstream3.plugins.RepositoryManager import com.lagradost.cloudstream3.plugins.RepositoryManager
@ -21,8 +20,8 @@ import com.lagradost.cloudstream3.ui.result.txt
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
import kotlinx.coroutines.launch
import me.xdrop.fuzzywuzzy.FuzzySearch import me.xdrop.fuzzywuzzy.FuzzySearch
import java.io.File
typealias Plugin = Pair<String, SitePlugin> typealias Plugin = Pair<String, SitePlugin>
/** /**
@ -47,7 +46,11 @@ class PluginsViewModel : ViewModel() {
private val repositoryCache: MutableMap<String, List<Plugin>> = mutableMapOf() private val repositoryCache: MutableMap<String, List<Plugin>> = mutableMapOf()
const val TAG = "PLG" const val TAG = "PLG"
private fun isDownloaded(context: Context, pluginName: String, repositoryUrl: String): Boolean { private fun isDownloaded(
context: Context,
pluginName: String,
repositoryUrl: String
): Boolean {
return getPluginPath(context, pluginName, repositoryUrl).exists() return getPluginPath(context, pluginName, repositoryUrl).exists()
} }
@ -73,7 +76,13 @@ class PluginsViewModel : ViewModel() {
if (activity == null) return@ioSafe if (activity == null) return@ioSafe
val plugins = getPlugins(repositoryUrl) val plugins = getPlugins(repositoryUrl)
plugins.filter { plugin -> !isDownloaded(activity, plugin.second.internalName, repositoryUrl) }.also { list -> plugins.filter { plugin ->
!isDownloaded(
activity,
plugin.second.internalName,
repositoryUrl
)
}.also { list ->
main { main {
showToast( showToast(
activity, activity,
@ -133,9 +142,13 @@ class PluginsViewModel : ViewModel() {
if (activity == null) return@ioSafe if (activity == null) return@ioSafe
val (repo, metadata) = plugin val (repo, metadata) = plugin
val file = getPluginPath(activity, plugin.second.internalName, plugin.first) val file = if (isLocal) File(plugin.second.url) else getPluginPath(
activity,
plugin.second.internalName,
plugin.first
)
val (success, message) = if (file.exists() || isLocal) { val (success, message) = if (file.exists()) {
PluginManager.deletePlugin(file) to R.string.plugin_deleted PluginManager.deletePlugin(file) to R.string.plugin_deleted
} else { } else {
PluginManager.downloadAndLoadPlugin( PluginManager.downloadAndLoadPlugin(
@ -167,7 +180,9 @@ class PluginsViewModel : ViewModel() {
} }
this.plugins = list this.plugins = list
_filteredPlugins.postValue(false to list.filterTvTypes().filterLang().sortByQuery(currentQuery)) _filteredPlugins.postValue(
false to list.filterTvTypes().filterLang().sortByQuery(currentQuery)
)
} }
// Perhaps can be optimized? // Perhaps can be optimized?
@ -175,7 +190,8 @@ class PluginsViewModel : ViewModel() {
if (tvTypes.isEmpty()) return this if (tvTypes.isEmpty()) return this
return this.filter { return this.filter {
(it.plugin.second.tvTypes?.any { type -> tvTypes.contains(type) } == true) || (it.plugin.second.tvTypes?.any { type -> tvTypes.contains(type) } == true) ||
(tvTypes.contains("Others") && (it.plugin.second.tvTypes ?: emptyList()).isEmpty()) (tvTypes.contains("Others") && (it.plugin.second.tvTypes
?: emptyList()).isEmpty())
} }
} }
@ -199,7 +215,9 @@ class PluginsViewModel : ViewModel() {
} }
fun updateFilteredPlugins() { fun updateFilteredPlugins() {
_filteredPlugins.postValue(false to plugins.filterTvTypes().filterLang().sortByQuery(currentQuery)) _filteredPlugins.postValue(
false to plugins.filterTvTypes().filterLang().sortByQuery(currentQuery)
)
} }
fun updatePluginList(context: Context?, repositoryUrl: String) = viewModelScope.launchSafe { fun updatePluginList(context: Context?, repositoryUrl: String) = viewModelScope.launchSafe {
@ -210,7 +228,9 @@ class PluginsViewModel : ViewModel() {
fun search(query: String?) { fun search(query: String?) {
currentQuery = query currentQuery = query
_filteredPlugins.postValue(true to (filteredPlugins.value?.second?.sortByQuery(query) ?: emptyList())) _filteredPlugins.postValue(
true to (filteredPlugins.value?.second?.sortByQuery(query) ?: emptyList())
)
} }
/** /**
@ -226,6 +246,8 @@ class PluginsViewModel : ViewModel() {
} }
plugins = downloadedPlugins plugins = downloadedPlugins
_filteredPlugins.postValue(false to downloadedPlugins.filterTvTypes().filterLang().sortByQuery(currentQuery)) _filteredPlugins.postValue(
false to downloadedPlugins.filterTvTypes().filterLang().sortByQuery(currentQuery)
)
} }
} }

View file

@ -7,21 +7,16 @@ import android.view.ViewGroup
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
import com.lagradost.cloudstream3.MainActivity.Companion.afterRepositoryLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterRepositoryLoadedEvent
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.plugins.RepositoryManager import com.lagradost.cloudstream3.plugins.RepositoryManager
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.ui.settings.extensions.PUBLIC_REPOSITORIES_LIST
import com.lagradost.cloudstream3.ui.settings.extensions.PluginsViewModel import com.lagradost.cloudstream3.ui.settings.extensions.PluginsViewModel
import com.lagradost.cloudstream3.ui.settings.extensions.RepoAdapter import com.lagradost.cloudstream3.ui.settings.extensions.RepoAdapter
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import kotlinx.android.synthetic.main.fragment_extensions.blank_repo_screen import kotlinx.android.synthetic.main.fragment_extensions.blank_repo_screen
import kotlinx.android.synthetic.main.fragment_extensions.list_repositories
import kotlinx.android.synthetic.main.fragment_extensions.repo_recycler_view import kotlinx.android.synthetic.main.fragment_extensions.repo_recycler_view
import kotlinx.android.synthetic.main.fragment_setup_extensions.*
import kotlinx.android.synthetic.main.fragment_setup_media.next_btt import kotlinx.android.synthetic.main.fragment_setup_media.next_btt
import kotlinx.android.synthetic.main.fragment_setup_media.prev_btt import kotlinx.android.synthetic.main.fragment_setup_media.prev_btt
import kotlinx.android.synthetic.main.fragment_setup_media.setup_root import kotlinx.android.synthetic.main.fragment_setup_media.setup_root
@ -64,18 +59,19 @@ class SetupFragmentExtensions : Fragment() {
val hasRepos = repositories.isNotEmpty() val hasRepos = repositories.isNotEmpty()
repo_recycler_view?.isVisible = hasRepos repo_recycler_view?.isVisible = hasRepos
blank_repo_screen?.isVisible = !hasRepos blank_repo_screen?.isVisible = !hasRepos
view_public_repositories_button?.isVisible = hasRepos // view_public_repositories_button?.isVisible = hasRepos
if (hasRepos) { if (hasRepos) {
repo_recycler_view?.adapter = RepoAdapter(true, {}, { repo_recycler_view?.adapter = RepoAdapter(true, {}, {
PluginsViewModel.downloadAll(activity, it.url, null) PluginsViewModel.downloadAll(activity, it.url, null)
}).apply { updateList(repositories) } }).apply { updateList(repositories) }
} else {
list_repositories?.setOnClickListener {
// Open webview on tv if browser fails
openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this)
}
} }
// else {
// list_repositories?.setOnClickListener {
// // Open webview on tv if browser fails
// openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this)
// }
// }
} }
} }
@ -84,9 +80,9 @@ class SetupFragmentExtensions : Fragment() {
context?.fixPaddingStatusbar(setup_root) context?.fixPaddingStatusbar(setup_root)
val isSetup = arguments?.getBoolean(SETUP_EXTENSION_BUNDLE_IS_SETUP) ?: false val isSetup = arguments?.getBoolean(SETUP_EXTENSION_BUNDLE_IS_SETUP) ?: false
view_public_repositories_button?.setOnClickListener { // view_public_repositories_button?.setOnClickListener {
openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this) // openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this)
} // }
with(context) { with(context) {
if (this == null) return if (this == null) return

View file

@ -28,15 +28,15 @@
android:textSize="20sp" android:textSize="20sp"
android:textStyle="bold" /> android:textStyle="bold" />
<com.google.android.material.button.MaterialButton <!-- <com.google.android.material.button.MaterialButton-->
android:nextFocusDown="@id/repo_name_input" <!-- android:nextFocusDown="@id/repo_name_input"-->
android:id="@+id/list_repositories" <!-- android:id="@+id/list_repositories"-->
android:nextFocusLeft="@id/apply_btt" <!-- android:nextFocusLeft="@id/apply_btt"-->
android:nextFocusRight="@id/cancel_btt" <!-- android:nextFocusRight="@id/cancel_btt"-->
style="@style/WhiteButton" <!-- style="@style/WhiteButton"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_gravity="center_vertical" <!-- android:layout_gravity="center_vertical"-->
android:text="@string/view_public_repositories_button_short" /> <!-- android:text="@string/view_public_repositories_button_short" />-->
</LinearLayout> </LinearLayout>
<TextView <TextView
@ -70,7 +70,6 @@
android:autofillHints="username" android:autofillHints="username"
android:hint="@string/repository_name_hint" android:hint="@string/repository_name_hint"
android:inputType="text" android:inputType="text"
android:nextFocusUp="@id/list_repositories"
android:nextFocusLeft="@id/apply_btt" android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt" android:nextFocusRight="@id/cancel_btt"
android:nextFocusDown="@id/site_url_input" android:nextFocusDown="@id/site_url_input"

View file

@ -47,12 +47,12 @@
android:text="@string/blank_repo_message" android:text="@string/blank_repo_message"
android:textSize="16sp" /> android:textSize="16sp" />
<com.google.android.material.button.MaterialButton <!-- <com.google.android.material.button.MaterialButton-->
android:id="@+id/list_repositories" <!-- android:id="@+id/list_repositories"-->
style="@style/WhiteButton" <!-- style="@style/WhiteButton"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:nextFocusDown="@id/add_repo_button" <!-- android:nextFocusDown="@id/add_repo_button"-->
android:text="@string/view_public_repositories_button" /> <!-- android:text="@string/view_public_repositories_button" />-->
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -44,11 +44,11 @@
android:text="@string/blank_repo_message" android:text="@string/blank_repo_message"
android:textSize="16sp" /> android:textSize="16sp" />
<com.google.android.material.button.MaterialButton <!-- <com.google.android.material.button.MaterialButton-->
android:id="@+id/list_repositories" <!-- android:id="@+id/list_repositories"-->
style="@style/WhiteButton" <!-- style="@style/WhiteButton"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:text="@string/view_public_repositories_button" /> <!-- android:text="@string/view_public_repositories_button" />-->
</LinearLayout> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -68,12 +68,12 @@
android:gravity="bottom|end" android:gravity="bottom|end"
android:orientation="horizontal"> android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <!-- <com.google.android.material.button.MaterialButton-->
android:id="@+id/view_public_repositories_button" <!-- android:id="@+id/view_public_repositories_button"-->
style="@style/WhiteButton" <!-- style="@style/WhiteButton"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_gravity="center_vertical|end" <!-- android:layout_gravity="center_vertical|end"-->
android:text="@string/add_repository" /> <!-- android:text="@string/add_repository" />-->
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/next_btt" android:id="@+id/next_btt"

View file

@ -602,7 +602,7 @@
<string name="plugins_disabled" formatted="true">Disabled: %d</string> <string name="plugins_disabled" formatted="true">Disabled: %d</string>
<string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string> <string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string>
<string name="plugins_updated" formatted="true">Updated %d plugins</string> <string name="plugins_updated" formatted="true">Updated %d plugins</string>
<string name="blank_repo_message">Add a repository to install site extensions</string> <string name="blank_repo_message">CloudStream has no sites installed by default. You need to install the sites from repositories.\n\nBecause of a brainless DMCA takedown by Sky Uk Limited 🤮 we cannot link the repository sites in app.\n\nJoin our discord for links or search online.</string>
<string name="view_public_repositories_button">View community repositories</string> <string name="view_public_repositories_button">View community repositories</string>
<string name="view_public_repositories_button_short">Public list</string> <string name="view_public_repositories_button_short">Public list</string>
<string name="uppercase_all_subtitles">Uppercase all subtitles</string> <string name="uppercase_all_subtitles">Uppercase all subtitles</string>