mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fix a few more issues (and maintain horizontal scroll position!)
This commit is contained in:
parent
842ea97415
commit
6ec8634836
3 changed files with 28 additions and 10 deletions
|
@ -14,6 +14,7 @@ import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
|
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
|
||||||
|
@ -320,6 +321,12 @@ object AccountHelper {
|
||||||
accountEditCallback = { viewModel.handleAccountUpdate(it, activity) },
|
accountEditCallback = { viewModel.handleAccountUpdate(it, activity) },
|
||||||
accountDeleteCallback = { viewModel.handleAccountUpdate(activity) }
|
accountDeleteCallback = { viewModel.handleAccountUpdate(activity) }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
activity.observe(viewModel.selectedKeyIndex) { selectedKeyIndex ->
|
||||||
|
// Scroll to current account (which is focused by default)
|
||||||
|
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||||
|
layoutManager.scrollToPositionWithOffset(selectedKeyIndex, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -116,14 +116,14 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
|
|
||||||
viewModel.toggleIsEditing()
|
viewModel.toggleIsEditing()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (isTvSettings()) {
|
if (isTvSettings()) {
|
||||||
recyclerView.spanCount = if (accounts.count() <= 6) {
|
recyclerView.spanCount = if (liveAccounts.count() + 1 <= 6) {
|
||||||
accounts.count()
|
liveAccounts.count() + 1
|
||||||
} else 6
|
} else 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun navigateToMainActivity() {
|
private fun navigateToMainActivity() {
|
||||||
val mainIntent = Intent(this, MainActivity::class.java)
|
val mainIntent = Intent(this, MainActivity::class.java)
|
||||||
|
|
|
@ -4,13 +4,17 @@ import android.content.Context
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||||
import com.lagradost.cloudstream3.ui.account.AccountHelper.showPinInputDialog
|
import com.lagradost.cloudstream3.ui.account.AccountHelper.showPinInputDialog
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
||||||
|
|
||||||
class AccountViewModel : ViewModel() {
|
class AccountViewModel : ViewModel() {
|
||||||
private val _accounts: MutableLiveData<List<DataStoreHelper.Account>> = MutableLiveData(DataStoreHelper.accounts.toList())
|
private val _accounts: MutableLiveData<List<DataStoreHelper.Account>> = MutableLiveData(
|
||||||
|
context?.let { getAccounts(it) } ?: DataStoreHelper.accounts.toList()
|
||||||
|
)
|
||||||
|
|
||||||
val accounts: LiveData<List<DataStoreHelper.Account>> = _accounts
|
val accounts: LiveData<List<DataStoreHelper.Account>> = _accounts
|
||||||
|
|
||||||
private val _isEditing = MutableLiveData(false)
|
private val _isEditing = MutableLiveData(false)
|
||||||
|
@ -19,9 +23,8 @@ class AccountViewModel : ViewModel() {
|
||||||
private val _isAllowedLogin = MutableLiveData(false)
|
private val _isAllowedLogin = MutableLiveData(false)
|
||||||
val isAllowedLogin: LiveData<Boolean> = _isAllowedLogin
|
val isAllowedLogin: LiveData<Boolean> = _isAllowedLogin
|
||||||
|
|
||||||
fun handleAccountUpdate(context: Context) {
|
private val _selectedKeyIndex = MutableLiveData(0)
|
||||||
_accounts.postValue(getAccounts(context))
|
val selectedKeyIndex: LiveData<Int> = _selectedKeyIndex
|
||||||
}
|
|
||||||
|
|
||||||
fun setIsEditing(value: Boolean) {
|
fun setIsEditing(value: Boolean) {
|
||||||
_isEditing.postValue(value)
|
_isEditing.postValue(value)
|
||||||
|
@ -31,11 +34,16 @@ class AccountViewModel : ViewModel() {
|
||||||
_isEditing.postValue(!(_isEditing.value ?: false))
|
_isEditing.postValue(!(_isEditing.value ?: false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleAccountUpdate(context: Context) {
|
||||||
|
_accounts.postValue(getAccounts(context))
|
||||||
|
_selectedKeyIndex.postValue(DataStoreHelper.selectedKeyIndex)
|
||||||
|
}
|
||||||
|
|
||||||
fun handleAccountUpdate(
|
fun handleAccountUpdate(
|
||||||
account: DataStoreHelper.Account,
|
account: DataStoreHelper.Account,
|
||||||
context: Context
|
context: Context
|
||||||
) {
|
) {
|
||||||
val currentAccounts = DataStoreHelper.accounts.toMutableList()
|
val currentAccounts = getAccounts(context).toMutableList()
|
||||||
|
|
||||||
val overrideIndex = currentAccounts.indexOfFirst { it.keyIndex == account.keyIndex }
|
val overrideIndex = currentAccounts.indexOfFirst { it.keyIndex == account.keyIndex }
|
||||||
|
|
||||||
|
@ -51,6 +59,7 @@ class AccountViewModel : ViewModel() {
|
||||||
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
||||||
|
|
||||||
_accounts.postValue(getAccounts(context))
|
_accounts.postValue(getAccounts(context))
|
||||||
|
_selectedKeyIndex.postValue(account.keyIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleAccountSelect(
|
fun handleAccountSelect(
|
||||||
|
@ -68,11 +77,13 @@ class AccountViewModel : ViewModel() {
|
||||||
if (pin == null) return@showPinInputDialog
|
if (pin == null) return@showPinInputDialog
|
||||||
// Pin is correct, proceed
|
// Pin is correct, proceed
|
||||||
_isAllowedLogin.postValue(true)
|
_isAllowedLogin.postValue(true)
|
||||||
|
_selectedKeyIndex.postValue(account.keyIndex)
|
||||||
setAccount(account, true)
|
setAccount(account, true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No PIN set for the selected account, proceed
|
// No PIN set for the selected account, proceed
|
||||||
_isAllowedLogin.postValue(true)
|
_isAllowedLogin.postValue(true)
|
||||||
|
_selectedKeyIndex.postValue(account.keyIndex)
|
||||||
setAccount(account, true)
|
setAccount(account, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue