diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt index dc49a0a6..1db49e27 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt @@ -323,6 +323,17 @@ object AccountHelper { recyclerView.setLinearListLayout(isHorizontal = true) + val currentAccount = DataStoreHelper.accounts.firstOrNull { + it.keyIndex == DataStoreHelper.selectedKeyIndex + } ?: getDefaultAccount(activity) + + // We want to make sure the accounts are up-to-date + viewModel.handleAccountSelect( + currentAccount, + activity, + reloadForActivity = true + ) + activity.observe(viewModel.accounts) { liveAccounts -> recyclerView.adapter = AccountAdapter( liveAccounts, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountViewModel.kt index cd2b7183..c73acd4d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountViewModel.kt @@ -89,8 +89,19 @@ class AccountViewModel : ViewModel() { fun handleAccountSelect( account: DataStoreHelper.Account, context: Context, - forStartup: Boolean = false + forStartup: Boolean = false, + reloadForActivity: Boolean = false ) { + if (reloadForActivity) { + val currentAccount = DataStoreHelper.accounts.firstOrNull { + it.keyIndex == DataStoreHelper.selectedKeyIndex + } + + _accounts.postValue(getAccounts(context)) + _selectedKeyIndex.postValue(getAccounts(context).indexOf(currentAccount)) + return + } + // Check if the selected account has a lock PIN set if (account.lockPin != null) { // The selected account has a PIN set, prompt the user to enter the PIN