mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
lib fix2
This commit is contained in:
parent
f14557fe6a
commit
33eb3a3b29
2 changed files with 25 additions and 9 deletions
|
@ -12,6 +12,7 @@ import com.lagradost.cloudstream3.mvvm.Resource
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.SyncApis
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.SyncApis
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
|
||||||
|
|
||||||
enum class ListSorting(@StringRes val stringRes: Int) {
|
enum class ListSorting(@StringRes val stringRes: Int) {
|
||||||
|
@ -30,7 +31,7 @@ class LibraryViewModel : ViewModel() {
|
||||||
private val _pages: MutableLiveData<Resource<List<SyncAPI.Page>>> = MutableLiveData(null)
|
private val _pages: MutableLiveData<Resource<List<SyncAPI.Page>>> = MutableLiveData(null)
|
||||||
val pages: LiveData<Resource<List<SyncAPI.Page>>> = _pages
|
val pages: LiveData<Resource<List<SyncAPI.Page>>> = _pages
|
||||||
|
|
||||||
var currentPage : Int = 0
|
var currentPage: Int = 0
|
||||||
|
|
||||||
private val _currentApiName: MutableLiveData<String> = MutableLiveData("")
|
private val _currentApiName: MutableLiveData<String> = MutableLiveData("")
|
||||||
val currentApiName: LiveData<String> = _currentApiName
|
val currentApiName: LiveData<String> = _currentApiName
|
||||||
|
@ -62,13 +63,21 @@ class LibraryViewModel : ViewModel() {
|
||||||
reloadPages(true)
|
reloadPages(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sort(method: ListSorting, query: String? = null) {
|
fun sort(method: ListSorting, query: String? = null) = ioSafe {
|
||||||
val currentList = pages.value ?: return
|
val value = _pages.value ?: return@ioSafe
|
||||||
|
if (value is Resource.Success) {
|
||||||
|
sort(method, query, value.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sort(method: ListSorting, query: String? = null, items: List<SyncAPI.Page>) {
|
||||||
currentSortingMethod = method
|
currentSortingMethod = method
|
||||||
(currentList as? Resource.Success)?.value?.forEachIndexed { _, page ->
|
DataStoreHelper.librarySortingMode = method.ordinal
|
||||||
|
|
||||||
|
items.forEach { page ->
|
||||||
page.sort(method, query)
|
page.sort(method, query)
|
||||||
}
|
}
|
||||||
_pages.postValue(currentList)
|
_pages.postValue(Resource.Success(items))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reloadPages(forceReload: Boolean) {
|
fun reloadPages(forceReload: Boolean) {
|
||||||
|
@ -89,8 +98,6 @@ class LibraryViewModel : ViewModel() {
|
||||||
val library = (libraryResource as? Resource.Success)?.value ?: return@let
|
val library = (libraryResource as? Resource.Success)?.value ?: return@let
|
||||||
|
|
||||||
sortingMethods = library.supportedListSorting.toList()
|
sortingMethods = library.supportedListSorting.toList()
|
||||||
currentSortingMethod = null
|
|
||||||
|
|
||||||
repo.requireLibraryRefresh = false
|
repo.requireLibraryRefresh = false
|
||||||
|
|
||||||
val pages = library.allLibraryLists.map {
|
val pages = library.allLibraryLists.map {
|
||||||
|
@ -100,11 +107,18 @@ class LibraryViewModel : ViewModel() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_pages.postValue(Resource.Success(pages))
|
val desiredSortingMethod =
|
||||||
|
ListSorting.values().getOrNull(DataStoreHelper.librarySortingMode)
|
||||||
|
if (desiredSortingMethod != null && library.supportedListSorting.contains(desiredSortingMethod)) {
|
||||||
|
sort(desiredSortingMethod, null, pages)
|
||||||
|
} else {
|
||||||
|
// null query = no sorting
|
||||||
|
sort(ListSorting.Query, null, pages)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
MainActivity.reloadHomeEvent += ::reloadPages
|
MainActivity.reloadHomeEvent += ::reloadPages
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
import com.lagradost.cloudstream3.ui.WatchType
|
import com.lagradost.cloudstream3.ui.WatchType
|
||||||
import com.lagradost.cloudstream3.ui.WhoIsWatchingAdapter
|
import com.lagradost.cloudstream3.ui.WhoIsWatchingAdapter
|
||||||
|
import com.lagradost.cloudstream3.ui.library.ListSorting
|
||||||
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
|
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
|
||||||
import com.lagradost.cloudstream3.ui.result.UiImage
|
import com.lagradost.cloudstream3.ui.result.UiImage
|
||||||
import com.lagradost.cloudstream3.ui.result.VideoWatchState
|
import com.lagradost.cloudstream3.ui.result.VideoWatchState
|
||||||
|
@ -123,6 +124,7 @@ object DataStoreHelper {
|
||||||
var homeBookmarkedList : IntArray by UserPreferenceDelegate("home_bookmarked_last_list", IntArray(0))
|
var homeBookmarkedList : IntArray by UserPreferenceDelegate("home_bookmarked_last_list", IntArray(0))
|
||||||
var playBackSpeed : Float by UserPreferenceDelegate("playback_speed", 1.0f)
|
var playBackSpeed : Float by UserPreferenceDelegate("playback_speed", 1.0f)
|
||||||
var resizeMode : Int by UserPreferenceDelegate("resize_mode", 0)
|
var resizeMode : Int by UserPreferenceDelegate("resize_mode", 0)
|
||||||
|
var librarySortingMode : Int by UserPreferenceDelegate("library_sorting_mode", ListSorting.AlphabeticalA.ordinal)
|
||||||
|
|
||||||
data class Account(
|
data class Account(
|
||||||
@JsonProperty("keyIndex")
|
@JsonProperty("keyIndex")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue