Make library preferences account specific (#649)

This commit is contained in:
Luna712 2023-10-03 14:59:26 -06:00 committed by GitHub
parent b5d4c3bd27
commit 3f5119525c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -35,6 +35,7 @@ import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
import com.lagradost.cloudstream3.utils.AppUtils.loadResult import com.lagradost.cloudstream3.utils.AppUtils.loadResult
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
import com.lagradost.cloudstream3.utils.AppUtils.reduceDragSensitivity import com.lagradost.cloudstream3.utils.AppUtils.reduceDragSensitivity
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
@ -180,7 +181,7 @@ class LibraryFragment : Fragment() {
val items = baseOptions.map { txt(it.stringRes).asString(this) } + availableProviders val items = baseOptions.map { txt(it.stringRes).asString(this) } + availableProviders
val savedSelection = getKey<LibraryOpener>(LIBRARY_FOLDER, key) val savedSelection = getKey<LibraryOpener>("$currentAccount/$LIBRARY_FOLDER", key)
val selectedIndex = val selectedIndex =
when { when {
savedSelection == null -> 0 savedSelection == null -> 0
@ -215,7 +216,7 @@ class LibraryFragment : Fragment() {
} }
setKey( setKey(
LIBRARY_FOLDER, "$currentAccount/$LIBRARY_FOLDER",
key, key,
savedData, savedData,
) )
@ -262,8 +263,8 @@ class LibraryFragment : Fragment() {
// This basically first selects the individual opener and if that is default then // This basically first selects the individual opener and if that is default then
// selects the whole list opener // selects the whole list opener
val savedListSelection = val savedListSelection =
getKey<LibraryOpener>(LIBRARY_FOLDER, syncName.name) getKey<LibraryOpener>("$currentAccount/$LIBRARY_FOLDER", syncName.name)
val savedSelection = getKey<LibraryOpener>(LIBRARY_FOLDER, syncId).takeIf { val savedSelection = getKey<LibraryOpener>("$currentAccount/$LIBRARY_FOLDER", syncId).takeIf {
it?.openType != LibraryOpenerType.Default it?.openType != LibraryOpenerType.Default
} ?: savedListSelection } ?: savedListSelection

View file

@ -11,6 +11,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.currentAccount
enum class ListSorting(@StringRes val stringRes: Int) { enum class ListSorting(@StringRes val stringRes: Int) {
Query(R.string.none), Query(R.string.none),
@ -35,12 +36,12 @@ class LibraryViewModel : ViewModel() {
get() = SyncApis.filter { it.hasAccount() } get() = SyncApis.filter { it.hasAccount() }
var currentSyncApi = availableSyncApis.let { allApis -> var currentSyncApi = availableSyncApis.let { allApis ->
val lastSelection = getKey<String>(LAST_SYNC_API_KEY) val lastSelection = getKey<String>("$currentAccount/$LAST_SYNC_API_KEY")
availableSyncApis.firstOrNull { it.name == lastSelection } ?: allApis.firstOrNull() availableSyncApis.firstOrNull { it.name == lastSelection } ?: allApis.firstOrNull()
} }
private set(value) { private set(value) {
field = value field = value
setKey(LAST_SYNC_API_KEY, field?.name) setKey("$currentAccount/$LAST_SYNC_API_KEY", field?.name)
} }
val availableApiNames: List<String> val availableApiNames: List<String>