mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Maintain AccountSelectActivity scroll position as well
This commit is contained in:
parent
6ec8634836
commit
28367de5c3
3 changed files with 12 additions and 5 deletions
|
@ -308,7 +308,7 @@ object AccountHelper {
|
||||||
|
|
||||||
recyclerView.setLinearListLayout(isHorizontal = true)
|
recyclerView.setLinearListLayout(isHorizontal = true)
|
||||||
|
|
||||||
viewModel.handleAccountUpdate(activity)
|
viewModel.updateAccounts(activity)
|
||||||
|
|
||||||
activity.observe(viewModel.accounts) { liveAccounts ->
|
activity.observe(viewModel.accounts) { liveAccounts ->
|
||||||
recyclerView.adapter = AccountAdapter(
|
recyclerView.adapter = AccountAdapter(
|
||||||
|
@ -319,7 +319,7 @@ object AccountHelper {
|
||||||
},
|
},
|
||||||
accountCreateCallback = { viewModel.handleAccountUpdate(it, activity) },
|
accountCreateCallback = { viewModel.handleAccountUpdate(it, activity) },
|
||||||
accountEditCallback = { viewModel.handleAccountUpdate(it, activity) },
|
accountEditCallback = { viewModel.handleAccountUpdate(it, activity) },
|
||||||
accountDeleteCallback = { viewModel.handleAccountUpdate(activity) }
|
accountDeleteCallback = { viewModel.updateAccounts(activity) }
|
||||||
)
|
)
|
||||||
|
|
||||||
activity.observe(viewModel.selectedKeyIndex) { selectedKeyIndex ->
|
activity.observe(viewModel.selectedKeyIndex) { selectedKeyIndex ->
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.lagradost.cloudstream3.CommonActivity
|
import com.lagradost.cloudstream3.CommonActivity
|
||||||
import com.lagradost.cloudstream3.CommonActivity.loadThemes
|
import com.lagradost.cloudstream3.CommonActivity.loadThemes
|
||||||
import com.lagradost.cloudstream3.MainActivity
|
import com.lagradost.cloudstream3.MainActivity
|
||||||
|
@ -77,7 +78,7 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
navigateToMainActivity()
|
navigateToMainActivity()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
accountDeleteCallback = { viewModel.handleAccountUpdate(this@AccountSelectActivity) }
|
accountDeleteCallback = { viewModel.updateAccounts(this@AccountSelectActivity) }
|
||||||
)
|
)
|
||||||
|
|
||||||
recyclerView.adapter = adapter
|
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 ->
|
observe(viewModel.isEditing) { isEditing ->
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
binding.editAccountButton.setImageResource(R.drawable.ic_baseline_close_24)
|
binding.editAccountButton.setImageResource(R.drawable.ic_baseline_close_24)
|
||||||
|
|
|
@ -23,7 +23,7 @@ class AccountViewModel : ViewModel() {
|
||||||
private val _isAllowedLogin = MutableLiveData(false)
|
private val _isAllowedLogin = MutableLiveData(false)
|
||||||
val isAllowedLogin: LiveData<Boolean> = _isAllowedLogin
|
val isAllowedLogin: LiveData<Boolean> = _isAllowedLogin
|
||||||
|
|
||||||
private val _selectedKeyIndex = MutableLiveData(0)
|
private val _selectedKeyIndex = MutableLiveData(DataStoreHelper.selectedKeyIndex)
|
||||||
val selectedKeyIndex: LiveData<Int> = _selectedKeyIndex
|
val selectedKeyIndex: LiveData<Int> = _selectedKeyIndex
|
||||||
|
|
||||||
fun setIsEditing(value: Boolean) {
|
fun setIsEditing(value: Boolean) {
|
||||||
|
@ -34,7 +34,7 @@ class AccountViewModel : ViewModel() {
|
||||||
_isEditing.postValue(!(_isEditing.value ?: false))
|
_isEditing.postValue(!(_isEditing.value ?: false))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleAccountUpdate(context: Context) {
|
fun updateAccounts(context: Context) {
|
||||||
_accounts.postValue(getAccounts(context))
|
_accounts.postValue(getAccounts(context))
|
||||||
_selectedKeyIndex.postValue(DataStoreHelper.selectedKeyIndex)
|
_selectedKeyIndex.postValue(DataStoreHelper.selectedKeyIndex)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue