From 7053d77ca1b391110d87e240cdb78535e0fe4543 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:09:37 +0100 Subject: [PATCH] Moved stuff to R.strings and fixed reloading the page --- .../cloudstream3/ui/library/LibraryFragment.kt | 17 ++++++++--------- .../cloudstream3/ui/library/LibraryViewModel.kt | 12 ++++++++---- app/src/main/res/values/strings.xml | 3 +++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt index fa70d61b..295511b5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt @@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.mvvm.debugAssert import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.syncproviders.SyncAPI import com.lagradost.cloudstream3.syncproviders.SyncIdName +import com.lagradost.cloudstream3.ui.result.UiText import com.lagradost.cloudstream3.ui.result.txt import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA @@ -70,14 +71,12 @@ class LibraryFragment : Fragment() { sort_fab?.setOnClickListener { val methods = libraryViewModel.sortingMethods.map { - txt(it.stringRes).asString( - context ?: view.context - ) + txt(it.stringRes).asString(view.context) } activity?.showBottomDialog(methods, libraryViewModel.sortingMethods.indexOf(libraryViewModel.currentSortingMethod), - "Sort by", + txt(R.string.sort_by).asString(view.context), false, {}, { @@ -98,7 +97,7 @@ class LibraryFragment : Fragment() { } }) - libraryViewModel.loadPages() + libraryViewModel.reloadPages(false) list_selector?.setOnClickListener { val items = libraryViewModel.availableApiNames @@ -106,10 +105,10 @@ class LibraryFragment : Fragment() { activity?.showBottomDialog(items, items.indexOf(currentItem), - "Select library", + txt(R.string.select_library).asString(it.context), false, - {}) { - val selectedItem = items.getOrNull(it) ?: return@showBottomDialog + {}) { index -> + val selectedItem = items.getOrNull(index) ?: return@showBottomDialog libraryViewModel.switchList(selectedItem) } } @@ -155,7 +154,7 @@ class LibraryFragment : Fragment() { this.showBottomDialog( items, selectedIndex, - "Open with", + txt(R.string.open_with).asString(this), true, {}, ) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt index 266ae94a..86a56cd2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt @@ -44,14 +44,16 @@ class LibraryViewModel : ViewModel() { ListSorting.AlphabeticalZ, ) - var currentSortingMethod: ListSorting = sortingMethods.first() + var currentSortingMethod: ListSorting = sortingMethods.first().also { + println("SET SORTING METHOD $it") + } private set fun switchList(name: String) { currentSyncApi = availableSyncApis[availableApiNames.indexOf(name)] _currentApiName.postValue(currentSyncApi?.name) - loadPages() + reloadPages(true) } fun sort(method: ListSorting, query: String? = null) { @@ -63,7 +65,10 @@ class LibraryViewModel : ViewModel() { _pages.postValue(currentList) } - fun loadPages() { + fun reloadPages(forceReload: Boolean) { + // Only skip loading if its not forced and pages is not empty + if (!forceReload && pages.value?.isNotEmpty() == true) return + ioSafe { currentSyncApi?.let { repo -> _currentApiName.postValue(repo.name) @@ -80,7 +85,6 @@ class LibraryViewModel : ViewModel() { it.value ) } - println("PAGES $pages") _pages.postValue(pages) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5896e922..fb6284d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -617,10 +617,13 @@ Safe Mode enabled An unrecoverable crash occurred and we\'ve automatically disabled all extensions, so you can find and remove the extension which is causing trouble. View crash info + Sort by Rating (High to Low) Rating (Low to High) Updated (New to Old) Updated (Old to New) Alphabetical (A to Z) Alphabetical (Z to A) + Select Library + Open with