small fix to home load

This commit is contained in:
LagradOst 2023-08-15 02:05:07 +02:00
parent 74867bed1c
commit 4d98690adb
4 changed files with 81 additions and 45 deletions

View file

@ -165,6 +165,9 @@ object PluginManager {
var loadedLocalPlugins = false
private set
var loadedOnlinePlugins = false
private set
private val gson = Gson()
private suspend fun maybeLoadPlugin(context: Context, file: File) {
@ -278,6 +281,7 @@ object PluginManager {
}
// ioSafe {
loadedOnlinePlugins = true
afterPluginsLoadedEvent.invoke(false)
// }

View file

@ -187,6 +187,7 @@ class HomeViewModel : ViewModel() {
private var onGoingLoad: Job? = null
private var isCurrentlyLoadingName: String? = null
private fun loadAndCancel(api: MainAPI) {
//println("loaded ${api.name}")
onGoingLoad?.cancel()
isCurrentlyLoadingName = api.name
onGoingLoad = load(api)
@ -455,9 +456,9 @@ class HomeViewModel : ViewModel() {
fromUI: Boolean = false
) =
ioSafe {
//println("trying to load $preferredApiName")
// Since plugins are loaded in stages this function can get called multiple times.
// The issue with this is that the homepage may be fetched multiple times while the first request is loading
val api = getApiFromNameNull(preferredApiName)
// api?.let { expandable[it.name]?.list?.list?.isNotEmpty() } == true
val currentPage = page.value
@ -467,6 +468,7 @@ class HomeViewModel : ViewModel() {
return@ioSafe
}
val api = getApiFromNameNull(preferredApiName)
if (preferredApiName == noneApi.name) {
// just set to random
if (fromUI) setKey(USER_SELECTED_HOMEPAGE_API, noneApi.name)
@ -485,10 +487,12 @@ class HomeViewModel : ViewModel() {
} else if (api == null) {
// API is not found aka not loaded or removed, post the loading
// progress if waiting for plugins, otherwise nothing
if(PluginManager.loadedLocalPlugins || PluginManager.checkSafeModeFile() || lastError != null) {
if (PluginManager.loadedOnlinePlugins || PluginManager.checkSafeModeFile() || lastError != null) {
loadAndCancel(noneApi)
} else {
_page.postValue(Resource.Loading())
if (preferredApiName != null)
_apiName.postValue(preferredApiName)
}
} else {
// if the api is found, then set it to it and save key

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.settings.extensions
import android.content.ClipboardManager
import android.content.Context
import android.content.DialogInterface
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -12,6 +13,8 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.marginBottom
import androidx.core.view.marginTop
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
@ -33,7 +36,6 @@ import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.widget.LinearRecycleViewLayoutManager
class ExtensionsFragment : Fragment() {
var binding: FragmentExtensionsBinding? = null
@ -84,7 +86,9 @@ class ExtensionsFragment : Fragment() {
setUpToolbar(R.string.extensions)
binding?.repoRecyclerView?.setLinearListLayout(
binding?.repoRecyclerView?.apply {
setLinearListLayout(
isHorizontal = false,
nextUp = R.id.settings_toolbar, //FOCUS_SELF, // back has no id so we cant :pensive:
nextDown = R.id.plugin_storage_appbar,
@ -92,7 +96,29 @@ class ExtensionsFragment : Fragment() {
nextLeft = R.id.nav_rail_view
)
binding?.repoRecyclerView?.adapter = RepoAdapter(false, {
if (!isTrueTvSettings())
binding?.addRepoButton?.let { button ->
button.post {
setPadding(
paddingLeft,
paddingTop,
paddingRight,
button.measuredHeight + button.marginTop + button.marginBottom
)
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
val dy = scrollY - oldScrollY
if (dy > 0) { //check for scroll down
binding?.addRepoButton?.shrink() // hide
} else if (dy < -5) {
binding?.addRepoButton?.extend() // show
}
}
}
adapter = RepoAdapter(false, {
findNavController().navigate(
R.id.navigation_settings_extensions_to_navigation_settings_plugins,
PluginsFragment.newInstance(
@ -129,6 +155,7 @@ class ExtensionsFragment : Fragment() {
.show().setDefaultFocus()
}
})
}
observe(extensionViewModel.repositories) {
binding?.repoRecyclerView?.isVisible = it.isNotEmpty()

View file

@ -11,6 +11,7 @@
<include layout="@layout/standard_toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:clipToPadding="false"
android:id="@+id/repo_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"