Fix randomized homepage

This commit is contained in:
Blatzar 2022-08-24 04:21:46 +02:00
parent 1e11a78698
commit abeda3e758
2 changed files with 15 additions and 7 deletions

View file

@ -168,8 +168,13 @@ object PluginManager {
// var allCurrentOutDatedPlugins: Set<OnlinePluginData> = 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,

View file

@ -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