forked from recloudstream/cloudstream
Fix homepage loading with plugins
This commit is contained in:
parent
2d3d8dd781
commit
b2ee957833
3 changed files with 23 additions and 11 deletions
|
@ -87,6 +87,7 @@ import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIE
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
|
||||||
import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData
|
import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
|
import com.lagradost.cloudstream3.utils.Event
|
||||||
|
|
||||||
|
|
||||||
const val VLC_PACKAGE = "org.videolan.vlc"
|
const val VLC_PACKAGE = "org.videolan.vlc"
|
||||||
|
@ -131,6 +132,7 @@ var app = Requests(responseParser = object : ResponseParser {
|
||||||
class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "MAINACT"
|
const val TAG = "MAINACT"
|
||||||
|
val afterPluginsLoadedEvent = Event<Boolean>()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onColorSelected(dialogId: Int, color: Int) {
|
override fun onColorSelected(dialogId: Int, color: Int) {
|
||||||
|
@ -462,6 +464,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginManager.loadAllLocalPlugins(this@MainActivity)
|
PluginManager.loadAllLocalPlugins(this@MainActivity)
|
||||||
|
afterPluginsLoadedEvent.invoke(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ioSafe {
|
// ioSafe {
|
||||||
|
@ -495,7 +498,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
ioSafe {
|
ioSafe {
|
||||||
initAll()
|
initAll()
|
||||||
apis = allProviders
|
// No duplicates (which can happen by registerMainAPI)
|
||||||
|
apis = allProviders.distinctBy { it }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getKey<Array<SettingsGeneral.CustomSite>>(USER_PROVIDER_API)?.let { list ->
|
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
|
APIHolder.apiMap = null
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logError(e)
|
logError(e)
|
||||||
|
|
|
@ -35,6 +35,7 @@ abstract class Plugin {
|
||||||
fun registerMainAPI(element: MainAPI) {
|
fun registerMainAPI(element: MainAPI) {
|
||||||
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI")
|
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI")
|
||||||
element.sourcePlugin = this.__filename
|
element.sourcePlugin = this.__filename
|
||||||
|
// Race condition causing which would case duplicates if not for distinctBy
|
||||||
APIHolder.allProviders.add(element)
|
APIHolder.allProviders.add(element)
|
||||||
APIHolder.addPluginMapping(element)
|
APIHolder.addPluginMapping(element)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
|
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
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.Resource
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.mvvm.observe
|
import com.lagradost.cloudstream3.mvvm.observe
|
||||||
|
@ -304,7 +305,8 @@ class HomeFragment : Fragment() {
|
||||||
val cancelBtt = dialog.findViewById<MaterialButton>(R.id.cancel_btt)
|
val cancelBtt = dialog.findViewById<MaterialButton>(R.id.cancel_btt)
|
||||||
val applyBtt = dialog.findViewById<MaterialButton>(R.id.apply_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 {
|
cancelBtt?.setOnClickListener {
|
||||||
dialog.dismissSafe()
|
dialog.dismissSafe()
|
||||||
|
@ -435,12 +437,13 @@ class HomeFragment : Fragment() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
reloadStored()
|
reloadStored()
|
||||||
|
afterPluginsLoadedEvent += ::loadHomePage
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
backEvent -= ::handleBack
|
afterPluginsLoadedEvent -= ::loadHomePage
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}*/
|
}
|
||||||
|
|
||||||
private fun reloadStored() {
|
private fun reloadStored() {
|
||||||
homeViewModel.loadResumeWatching()
|
homeViewModel.loadResumeWatching()
|
||||||
|
@ -451,6 +454,14 @@ class HomeFragment : Fragment() {
|
||||||
homeViewModel.loadStoredData(list)
|
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) {
|
/*private fun handleBack(poppedFragment: Boolean) {
|
||||||
if (poppedFragment) {
|
if (poppedFragment) {
|
||||||
reloadStored()
|
reloadStored()
|
||||||
|
@ -948,11 +959,7 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadStored()
|
reloadStored()
|
||||||
val apiName = context?.getKey<String>(HOMEPAGE_API)
|
loadHomePage()
|
||||||
if (homeViewModel.apiName.value != apiName || apiName == null) {
|
|
||||||
//println("Caught home: " + homeViewModel.apiName.value + " at " + apiName)
|
|
||||||
homeViewModel.loadAndCancel(apiName)
|
|
||||||
}
|
|
||||||
|
|
||||||
home_loaded.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, oldScrollY ->
|
home_loaded.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, oldScrollY ->
|
||||||
val dy = scrollY - oldScrollY
|
val dy = scrollY - oldScrollY
|
||||||
|
|
Loading…
Reference in a new issue