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 79cd0b2d..d388cd1f 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 @@ -308,7 +308,7 @@ object AccountHelper { recyclerView.setLinearListLayout(isHorizontal = true) - viewModel.handleAccountUpdate(activity) + viewModel.updateAccounts(activity) activity.observe(viewModel.accounts) { liveAccounts -> recyclerView.adapter = AccountAdapter( @@ -319,7 +319,7 @@ object AccountHelper { }, accountCreateCallback = { viewModel.handleAccountUpdate(it, activity) }, accountEditCallback = { viewModel.handleAccountUpdate(it, activity) }, - accountDeleteCallback = { viewModel.handleAccountUpdate(activity) } + accountDeleteCallback = { viewModel.updateAccounts(activity) } ) activity.observe(viewModel.selectedKeyIndex) { selectedKeyIndex -> diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt index aca72335..7f0b2b4a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager import com.lagradost.cloudstream3.CommonActivity import com.lagradost.cloudstream3.CommonActivity.loadThemes import com.lagradost.cloudstream3.MainActivity @@ -77,7 +78,7 @@ class AccountSelectActivity : AppCompatActivity() { navigateToMainActivity() } }, - accountDeleteCallback = { viewModel.handleAccountUpdate(this@AccountSelectActivity) } + accountDeleteCallback = { viewModel.updateAccounts(this@AccountSelectActivity) } ) recyclerView.adapter = adapter @@ -88,6 +89,12 @@ class AccountSelectActivity : AppCompatActivity() { ) } + observe(viewModel.selectedKeyIndex) { selectedKeyIndex -> + // Scroll to current account (which is focused by default) + val layoutManager = recyclerView.layoutManager as GridLayoutManager + layoutManager.scrollToPositionWithOffset(selectedKeyIndex, 0) + } + observe(viewModel.isEditing) { isEditing -> if (isEditing) { binding.editAccountButton.setImageResource(R.drawable.ic_baseline_close_24) 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 7074b2c4..c65baa85 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 @@ -23,7 +23,7 @@ class AccountViewModel : ViewModel() { private val _isAllowedLogin = MutableLiveData(false) val isAllowedLogin: LiveData = _isAllowedLogin - private val _selectedKeyIndex = MutableLiveData(0) + private val _selectedKeyIndex = MutableLiveData(DataStoreHelper.selectedKeyIndex) val selectedKeyIndex: LiveData = _selectedKeyIndex fun setIsEditing(value: Boolean) { @@ -34,7 +34,7 @@ class AccountViewModel : ViewModel() { _isEditing.postValue(!(_isEditing.value ?: false)) } - fun handleAccountUpdate(context: Context) { + fun updateAccounts(context: Context) { _accounts.postValue(getAccounts(context)) _selectedKeyIndex.postValue(DataStoreHelper.selectedKeyIndex) }