mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
faster init time for homepage dex
This commit is contained in:
parent
10f4d33c59
commit
34cbcd8311
3 changed files with 38 additions and 7 deletions
|
@ -41,6 +41,7 @@ import com.lagradost.cloudstream3.CommonActivity.updateLocale
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.network.initClient
|
import com.lagradost.cloudstream3.network.initClient
|
||||||
import com.lagradost.cloudstream3.plugins.PluginManager
|
import com.lagradost.cloudstream3.plugins.PluginManager
|
||||||
|
import com.lagradost.cloudstream3.plugins.PluginManager.loadSinglePlugin
|
||||||
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
||||||
|
@ -78,6 +79,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
||||||
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
|
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
|
||||||
|
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
|
||||||
import com.lagradost.nicehttp.Requests
|
import com.lagradost.nicehttp.Requests
|
||||||
import com.lagradost.nicehttp.ResponseParser
|
import com.lagradost.nicehttp.ResponseParser
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
@ -130,6 +132,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "MAINACT"
|
const val TAG = "MAINACT"
|
||||||
val afterPluginsLoadedEvent = Event<Boolean>()
|
val afterPluginsLoadedEvent = Event<Boolean>()
|
||||||
|
val mainPluginsLoadedEvent =
|
||||||
|
Event<Boolean>() // homepage api, used to speed up time to load for homepage
|
||||||
val afterRepositoryLoadedEvent = Event<Boolean>()
|
val afterRepositoryLoadedEvent = Event<Boolean>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +440,12 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
changeStatusBarState(isEmulatorSettings())
|
changeStatusBarState(isEmulatorSettings())
|
||||||
|
|
||||||
ioSafe {
|
ioSafe {
|
||||||
|
getKey<String>(USER_SELECTED_HOMEPAGE_API)?.let { homeApi ->
|
||||||
|
mainPluginsLoadedEvent.invoke(loadSinglePlugin(this@MainActivity, homeApi))
|
||||||
|
} ?: run {
|
||||||
|
mainPluginsLoadedEvent.invoke(false)
|
||||||
|
}
|
||||||
|
|
||||||
if (settingsManager.getBoolean(getString(R.string.auto_update_plugins_key), true)) {
|
if (settingsManager.getBoolean(getString(R.string.auto_update_plugins_key), true)) {
|
||||||
PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity)
|
PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -164,6 +164,17 @@ object PluginManager {
|
||||||
|
|
||||||
var allCurrentOutDatedPlugins: Set<OnlinePluginData> = emptySet()
|
var allCurrentOutDatedPlugins: Set<OnlinePluginData> = emptySet()
|
||||||
|
|
||||||
|
suspend fun loadSinglePlugin(activity: Activity, apiName: String) : Boolean {
|
||||||
|
return getPluginsOnline().firstOrNull { it.internalName == apiName }?.let { savedData ->
|
||||||
|
// OnlinePluginData(savedData, onlineData)
|
||||||
|
loadPlugin(
|
||||||
|
activity,
|
||||||
|
File(savedData.filePath),
|
||||||
|
savedData
|
||||||
|
)
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Needs to be run before other plugin loading because plugin loading can not be overwritten
|
* Needs to be run before other plugin loading because plugin loading can not be overwritten
|
||||||
* 1. Gets all online data about the downloaded plugins
|
* 1. Gets all online data about the downloaded plugins
|
||||||
|
@ -376,7 +387,7 @@ object PluginManager {
|
||||||
file ?: return false,
|
file ?: return false,
|
||||||
PluginData(internalName, pluginUrl, true, file.absolutePath, PLUGIN_VERSION_NOT_SET)
|
PluginData(internalName, pluginUrl, true, file.absolutePath, PLUGIN_VERSION_NOT_SET)
|
||||||
)
|
)
|
||||||
} catch (e : Exception) {
|
} catch (e: Exception) {
|
||||||
logError(e)
|
logError(e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
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.MainActivity.Companion.afterPluginsLoadedEvent
|
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
|
||||||
|
import com.lagradost.cloudstream3.MainActivity.Companion.mainPluginsLoadedEvent
|
||||||
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
|
||||||
|
@ -60,7 +60,6 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.deleteAllResumeStateIds
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
|
||||||
import com.lagradost.cloudstream3.utils.Event
|
import com.lagradost.cloudstream3.utils.Event
|
||||||
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
|
|
||||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes
|
||||||
import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso
|
import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
|
@ -70,6 +69,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
|
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.setImageBlur
|
import com.lagradost.cloudstream3.utils.UIHelper.setImageBlur
|
||||||
|
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
|
||||||
import com.lagradost.cloudstream3.widget.CenterZoomLayoutManager
|
import com.lagradost.cloudstream3.widget.CenterZoomLayoutManager
|
||||||
import kotlinx.android.synthetic.main.fragment_home.*
|
import kotlinx.android.synthetic.main.fragment_home.*
|
||||||
import kotlinx.android.synthetic.main.fragment_home.home_api_fab
|
import kotlinx.android.synthetic.main.fragment_home.home_api_fab
|
||||||
|
@ -437,11 +437,13 @@ class HomeFragment : Fragment() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
reloadStored()
|
reloadStored()
|
||||||
afterPluginsLoadedEvent += ::loadHomePage
|
afterPluginsLoadedEvent += ::firstLoadHomePage
|
||||||
|
mainPluginsLoadedEvent += ::firstLoadHomePage
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
afterPluginsLoadedEvent -= ::loadHomePage
|
afterPluginsLoadedEvent -= ::firstLoadHomePage
|
||||||
|
mainPluginsLoadedEvent -= ::firstLoadHomePage
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,6 +456,14 @@ class HomeFragment : Fragment() {
|
||||||
homeViewModel.loadStoredData(list)
|
homeViewModel.loadStoredData(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var hasBeenConsumed = false
|
||||||
|
private fun firstLoadHomePage(successful: Boolean = false) {
|
||||||
|
// dirty hack to make it only load once
|
||||||
|
if(hasBeenConsumed) return
|
||||||
|
hasBeenConsumed = true
|
||||||
|
loadHomePage(successful)
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadHomePage(successful: Boolean = false) {
|
private fun loadHomePage(successful: Boolean = false) {
|
||||||
val apiName = context?.getKey<String>(USER_SELECTED_HOMEPAGE_API)
|
val apiName = context?.getKey<String>(USER_SELECTED_HOMEPAGE_API)
|
||||||
|
|
||||||
|
@ -962,13 +972,13 @@ class HomeFragment : Fragment() {
|
||||||
reloadStored()
|
reloadStored()
|
||||||
loadHomePage()
|
loadHomePage()
|
||||||
|
|
||||||
home_loaded.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, oldScrollY ->
|
home_loaded.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, _, scrollY, _, oldScrollY ->
|
||||||
val dy = scrollY - oldScrollY
|
val dy = scrollY - oldScrollY
|
||||||
if (dy > 0) { //check for scroll down
|
if (dy > 0) { //check for scroll down
|
||||||
home_api_fab?.shrink() // hide
|
home_api_fab?.shrink() // hide
|
||||||
home_random?.shrink()
|
home_random?.shrink()
|
||||||
} else if (dy < -5) {
|
} else if (dy < -5) {
|
||||||
if (view?.context?.isTvSettings() == false) {
|
if (v.context?.isTvSettings() == false) {
|
||||||
home_api_fab?.extend() // show
|
home_api_fab?.extend() // show
|
||||||
home_random?.extend()
|
home_random?.extend()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue