Moved stuff to R.strings and fixed reloading the page

This commit is contained in:
Blatzar 2023-01-22 19:09:37 +01:00
parent 30dbd3920e
commit 7053d77ca1
3 changed files with 19 additions and 13 deletions

View file

@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.mvvm.debugAssert
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.syncproviders.SyncAPI import com.lagradost.cloudstream3.syncproviders.SyncAPI
import com.lagradost.cloudstream3.syncproviders.SyncIdName 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.result.txt
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
@ -70,14 +71,12 @@ class LibraryFragment : Fragment() {
sort_fab?.setOnClickListener { sort_fab?.setOnClickListener {
val methods = libraryViewModel.sortingMethods.map { val methods = libraryViewModel.sortingMethods.map {
txt(it.stringRes).asString( txt(it.stringRes).asString(view.context)
context ?: view.context
)
} }
activity?.showBottomDialog(methods, activity?.showBottomDialog(methods,
libraryViewModel.sortingMethods.indexOf(libraryViewModel.currentSortingMethod), libraryViewModel.sortingMethods.indexOf(libraryViewModel.currentSortingMethod),
"Sort by", txt(R.string.sort_by).asString(view.context),
false, false,
{}, {},
{ {
@ -98,7 +97,7 @@ class LibraryFragment : Fragment() {
} }
}) })
libraryViewModel.loadPages() libraryViewModel.reloadPages(false)
list_selector?.setOnClickListener { list_selector?.setOnClickListener {
val items = libraryViewModel.availableApiNames val items = libraryViewModel.availableApiNames
@ -106,10 +105,10 @@ class LibraryFragment : Fragment() {
activity?.showBottomDialog(items, activity?.showBottomDialog(items,
items.indexOf(currentItem), items.indexOf(currentItem),
"Select library", txt(R.string.select_library).asString(it.context),
false, false,
{}) { {}) { index ->
val selectedItem = items.getOrNull(it) ?: return@showBottomDialog val selectedItem = items.getOrNull(index) ?: return@showBottomDialog
libraryViewModel.switchList(selectedItem) libraryViewModel.switchList(selectedItem)
} }
} }
@ -155,7 +154,7 @@ class LibraryFragment : Fragment() {
this.showBottomDialog( this.showBottomDialog(
items, items,
selectedIndex, selectedIndex,
"Open with", txt(R.string.open_with).asString(this),
true, true,
{}, {},
) { ) {

View file

@ -44,14 +44,16 @@ class LibraryViewModel : ViewModel() {
ListSorting.AlphabeticalZ, ListSorting.AlphabeticalZ,
) )
var currentSortingMethod: ListSorting = sortingMethods.first() var currentSortingMethod: ListSorting = sortingMethods.first().also {
println("SET SORTING METHOD $it")
}
private set private set
fun switchList(name: String) { fun switchList(name: String) {
currentSyncApi = availableSyncApis[availableApiNames.indexOf(name)] currentSyncApi = availableSyncApis[availableApiNames.indexOf(name)]
_currentApiName.postValue(currentSyncApi?.name) _currentApiName.postValue(currentSyncApi?.name)
loadPages() reloadPages(true)
} }
fun sort(method: ListSorting, query: String? = null) { fun sort(method: ListSorting, query: String? = null) {
@ -63,7 +65,10 @@ class LibraryViewModel : ViewModel() {
_pages.postValue(currentList) _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 { ioSafe {
currentSyncApi?.let { repo -> currentSyncApi?.let { repo ->
_currentApiName.postValue(repo.name) _currentApiName.postValue(repo.name)
@ -80,7 +85,6 @@ class LibraryViewModel : ViewModel() {
it.value it.value
) )
} }
println("PAGES $pages")
_pages.postValue(pages) _pages.postValue(pages)
} }
} }

View file

@ -617,10 +617,13 @@
<string name="safe_mode_title">Safe Mode enabled</string> <string name="safe_mode_title">Safe Mode enabled</string>
<string name="safe_mode_description">An unrecoverable crash occurred and we\'ve automatically disabled all extensions, so you can find and remove the extension which is causing trouble.</string> <string name="safe_mode_description">An unrecoverable crash occurred and we\'ve automatically disabled all extensions, so you can find and remove the extension which is causing trouble.</string>
<string name="safe_mode_crash_info">View crash info</string> <string name="safe_mode_crash_info">View crash info</string>
<string name="sort_by">Sort by</string>
<string name="sort_rating_desc">Rating (High to Low)</string> <string name="sort_rating_desc">Rating (High to Low)</string>
<string name="sort_rating_asc">Rating (Low to High)</string> <string name="sort_rating_asc">Rating (Low to High)</string>
<string name="sort_updated_new">Updated (New to Old)</string> <string name="sort_updated_new">Updated (New to Old)</string>
<string name="sort_updated_old">Updated (Old to New)</string> <string name="sort_updated_old">Updated (Old to New)</string>
<string name="sort_alphabetical_a">Alphabetical (A to Z)</string> <string name="sort_alphabetical_a">Alphabetical (A to Z)</string>
<string name="sort_alphabetical_z">Alphabetical (Z to A)</string> <string name="sort_alphabetical_z">Alphabetical (Z to A)</string>
<string name="select_library">Select Library</string>
<string name="open_with">Open with</string>
</resources> </resources>