Fix homepage loading with plugins

This commit is contained in:
Blatzar 2022-08-14 23:34:47 +02:00
parent 2d3d8dd781
commit b2ee957833
3 changed files with 23 additions and 11 deletions

View File

@ -87,6 +87,7 @@ import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIE
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData
import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.Event
const val VLC_PACKAGE = "org.videolan.vlc"
@ -131,6 +132,7 @@ var app = Requests(responseParser = object : ResponseParser {
class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
companion object {
const val TAG = "MAINACT"
val afterPluginsLoadedEvent = Event<Boolean>()
}
override fun onColorSelected(dialogId: Int, color: Int) {
@ -462,6 +464,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
}
PluginManager.loadAllLocalPlugins(this@MainActivity)
afterPluginsLoadedEvent.invoke(true)
}
// ioSafe {
@ -495,7 +498,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
ioSafe {
initAll()
apis = allProviders
// No duplicates (which can happen by registerMainAPI)
apis = allProviders.distinctBy { it }
try {
getKey<Array<SettingsGeneral.CustomSite>>(USER_PROVIDER_API)?.let { list ->
@ -511,7 +515,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
}
}
}
apis = allProviders
apis = allProviders.distinctBy { it }
APIHolder.apiMap = null
} catch (e: Exception) {
logError(e)

View File

@ -35,6 +35,7 @@ abstract class Plugin {
fun registerMainAPI(element: MainAPI) {
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI")
element.sourcePlugin = this.__filename
// Race condition causing which would case duplicates if not for distinctBy
APIHolder.allProviders.add(element)
APIHolder.addPluginMapping(element)
}

View File

@ -32,6 +32,7 @@ import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.observe
@ -304,7 +305,8 @@ class HomeFragment : Fragment() {
val cancelBtt = dialog.findViewById<MaterialButton>(R.id.cancel_btt)
val applyBtt = dialog.findViewById<MaterialButton>(R.id.apply_btt)
val pairList = getPairList(anime, cartoons, tvs, docs, movies, asian, livestream, nsfw, others)
val pairList =
getPairList(anime, cartoons, tvs, docs, movies, asian, livestream, nsfw, others)
cancelBtt?.setOnClickListener {
dialog.dismissSafe()
@ -435,12 +437,13 @@ class HomeFragment : Fragment() {
override fun onResume() {
super.onResume()
reloadStored()
afterPluginsLoadedEvent += ::loadHomePage
}
/*
override fun onStop() {
backEvent -= ::handleBack
afterPluginsLoadedEvent -= ::loadHomePage
super.onStop()
}*/
}
private fun reloadStored() {
homeViewModel.loadResumeWatching()
@ -451,6 +454,14 @@ class HomeFragment : Fragment() {
homeViewModel.loadStoredData(list)
}
private fun loadHomePage(successful: Boolean = true) {
val apiName = context?.getKey<String>(HOMEPAGE_API)
if (homeViewModel.apiName.value != apiName || apiName == null) {
//println("Caught home: " + homeViewModel.apiName.value + " at " + apiName)
homeViewModel.loadAndCancel(apiName)
}
}
/*private fun handleBack(poppedFragment: Boolean) {
if (poppedFragment) {
reloadStored()
@ -948,11 +959,7 @@ class HomeFragment : Fragment() {
}
reloadStored()
val apiName = context?.getKey<String>(HOMEPAGE_API)
if (homeViewModel.apiName.value != apiName || apiName == null) {
//println("Caught home: " + homeViewModel.apiName.value + " at " + apiName)
homeViewModel.loadAndCancel(apiName)
}
loadHomePage()
home_loaded.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, oldScrollY ->
val dy = scrollY - oldScrollY