diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt index ef7dbf35..59dae640 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -168,8 +168,13 @@ object PluginManager { // var allCurrentOutDatedPlugins: Set = emptySet() suspend fun loadSinglePlugin(activity: Activity, apiName: String): Boolean { - return (getPluginsOnline().firstOrNull { it.internalName == apiName } - ?: getPluginsLocal().firstOrNull { it.internalName == apiName })?.let { savedData -> + return (getPluginsOnline().firstOrNull { + // Most of the time the provider ends with Provider which isn't part of the api name + it.internalName.replace("provider", "", ignoreCase = true) == apiName + } + ?: getPluginsLocal().firstOrNull { + it.internalName.replace("provider", "", ignoreCase = true) == apiName + })?.let { savedData -> // OnlinePluginData(savedData, onlineData) loadPlugin( activity, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt index daff5e4a..1d6ed584 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt @@ -267,15 +267,18 @@ class HomeViewModel : ViewModel() { fun loadAndCancel(preferredApiName: String?, forceReload: Boolean = true) = viewModelScope.launchSafe { // Since plugins are loaded in stages this function can get called multiple times. - // This makes the home page reload only if it's a failure or loading - if (!forceReload && page.value is Resource.Success) { + // The issue with this is that the homepage may be fetched multiple times while the first request is loading + val api = getApiFromNameNull(preferredApiName) + if (!forceReload && api?.let { expandable[it.name]?.list?.list?.isNotEmpty() } == true) { return@launchSafe } - val api = getApiFromNameNull(preferredApiName) - if (preferredApiName == noneApi.name) { + // If the plugin isn't loaded yet. (Does not set the key) + if (api == null) { + loadAndCancel(noneApi) + } else if (preferredApiName == noneApi.name) { setKey(USER_SELECTED_HOMEPAGE_API, noneApi.name) loadAndCancel(noneApi) - } else if (preferredApiName == randomApi.name || api == null) { + } else if (preferredApiName == randomApi.name) { val validAPIs = context?.filterProviderByPreferredMedia() if (validAPIs.isNullOrEmpty()) { // Do not set USER_SELECTED_HOMEPAGE_API when there is no plugins loaded