mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
If we are skipping account select on startup, still ask for PIN if needed with an option to use default account
This commit is contained in:
parent
9b3d13a7d0
commit
352f90a08b
4 changed files with 65 additions and 12 deletions
|
@ -17,6 +17,7 @@ import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
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.getActivity
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
|
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
|
||||||
import com.lagradost.cloudstream3.MainActivity
|
import com.lagradost.cloudstream3.MainActivity
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
@ -33,6 +34,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getDefaultAccount
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
|
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
object AccountHelper {
|
object AccountHelper {
|
||||||
fun showAccountEditDialog(
|
fun showAccountEditDialog(
|
||||||
|
@ -169,6 +171,7 @@ object AccountHelper {
|
||||||
context: Context,
|
context: Context,
|
||||||
currentPin: String?,
|
currentPin: String?,
|
||||||
editAccount: Boolean,
|
editAccount: Boolean,
|
||||||
|
forStartup: Boolean = false,
|
||||||
errorText: String? = null,
|
errorText: String? = null,
|
||||||
callback: (String?) -> Unit
|
callback: (String?) -> Unit
|
||||||
) {
|
) {
|
||||||
|
@ -207,6 +210,28 @@ object AccountHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forStartup) {
|
||||||
|
val currentAccount = DataStoreHelper.accounts.firstOrNull {
|
||||||
|
it.keyIndex == DataStoreHelper.selectedKeyIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setTitle(context.getString(R.string.enter_pin_with_name, currentAccount?.name))
|
||||||
|
builder.setOnDismissListener {
|
||||||
|
if (!isPinValid) {
|
||||||
|
exitProcess(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// So that if they don't know the PIN for the current account,
|
||||||
|
// they don't get completely locked out
|
||||||
|
builder.setNeutralButton(R.string.use_default_account) { _, _ ->
|
||||||
|
val activity = context.getActivity()
|
||||||
|
if (activity is AccountSelectActivity) {
|
||||||
|
isPinValid = true
|
||||||
|
activity.viewModel.handleAccountSelect(getDefaultAccount(context), activity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isNewPin) {
|
if (isNewPin) {
|
||||||
if (errorText != null) binding.pinEditTextError.visibleWithText(errorText)
|
if (errorText != null) binding.pinEditTextError.visibleWithText(errorText)
|
||||||
builder.setPositiveButton(R.string.setup_done) { _, _ ->
|
builder.setPositiveButton(R.string.setup_done) { _, _ ->
|
||||||
|
|
|
@ -9,6 +9,7 @@ import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
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.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.MainActivity
|
import com.lagradost.cloudstream3.MainActivity
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.databinding.ActivityAccountSelectBinding
|
import com.lagradost.cloudstream3.databinding.ActivityAccountSelectBinding
|
||||||
|
@ -18,14 +19,20 @@ import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_
|
||||||
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_SELECT_ACCOUNT
|
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_SELECT_ACCOUNT
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.accounts
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.accounts
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.selectedKeyIndex
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||||
|
|
||||||
class AccountSelectActivity : AppCompatActivity() {
|
class AccountSelectActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
lateinit var viewModel: AccountViewModel
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
loadThemes(this)
|
||||||
|
|
||||||
|
window.navigationBarColor = colorFromAttribute(R.attr.primaryBlackBackground)
|
||||||
|
|
||||||
// Are we editing and coming from MainActivity?
|
// Are we editing and coming from MainActivity?
|
||||||
val isEditingFromMainActivity = intent.getBooleanExtra(
|
val isEditingFromMainActivity = intent.getBooleanExtra(
|
||||||
|
@ -38,31 +45,48 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
false
|
false
|
||||||
) ?: false || accounts.count() <= 1
|
) ?: false || accounts.count() <= 1
|
||||||
|
|
||||||
|
viewModel = ViewModelProvider(this)[AccountViewModel::class.java]
|
||||||
|
|
||||||
// Don't show account selection if there is only
|
// Don't show account selection if there is only
|
||||||
// one account that exists
|
// one account that exists
|
||||||
if (!isEditingFromMainActivity && skipStartup) {
|
if (!isEditingFromMainActivity && skipStartup) {
|
||||||
navigateToMainActivity()
|
val currentAccount = accounts.firstOrNull { it.keyIndex == selectedKeyIndex }
|
||||||
|
if (currentAccount?.lockPin != null) {
|
||||||
|
CommonActivity.init(this)
|
||||||
|
viewModel.handleAccountSelect(currentAccount, this, true)
|
||||||
|
observe(viewModel.isAllowedLogin) { isAllowedLogin ->
|
||||||
|
if (isAllowedLogin) {
|
||||||
|
// We are allowed to continue to MainActivity
|
||||||
|
navigateToMainActivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (accounts.count() > 1) {
|
||||||
|
showToast(this, getString(
|
||||||
|
R.string.logged_account,
|
||||||
|
currentAccount?.name
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
navigateToMainActivity()
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonActivity.init(this)
|
CommonActivity.init(this)
|
||||||
loadThemes(this)
|
|
||||||
|
|
||||||
window.navigationBarColor = colorFromAttribute(R.attr.primaryBlackBackground)
|
|
||||||
|
|
||||||
val binding = ActivityAccountSelectBinding.inflate(layoutInflater)
|
val binding = ActivityAccountSelectBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
val recyclerView: AutofitRecyclerView = binding.accountRecyclerView
|
val recyclerView: AutofitRecyclerView = binding.accountRecyclerView
|
||||||
|
|
||||||
val viewModel = ViewModelProvider(this)[AccountViewModel::class.java]
|
|
||||||
|
|
||||||
observe(viewModel.accounts) { liveAccounts ->
|
observe(viewModel.accounts) { liveAccounts ->
|
||||||
val adapter = AccountAdapter(
|
val adapter = AccountAdapter(
|
||||||
liveAccounts,
|
liveAccounts,
|
||||||
// Handle the selected account
|
// Handle the selected account
|
||||||
accountSelectCallback = {
|
accountSelectCallback = {
|
||||||
viewModel.handleAccountSelect(it,this@AccountSelectActivity)
|
viewModel.handleAccountSelect(it, this)
|
||||||
observe(viewModel.isAllowedLogin) { isAllowedLogin ->
|
observe(viewModel.isAllowedLogin) { isAllowedLogin ->
|
||||||
if (isAllowedLogin) {
|
if (isAllowedLogin) {
|
||||||
// We are allowed to continue to MainActivity
|
// We are allowed to continue to MainActivity
|
||||||
|
@ -70,9 +94,9 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
accountCreateCallback = { viewModel.handleAccountUpdate(it, this@AccountSelectActivity) },
|
accountCreateCallback = { viewModel.handleAccountUpdate(it, this) },
|
||||||
accountEditCallback = {
|
accountEditCallback = {
|
||||||
viewModel.handleAccountUpdate(it, this@AccountSelectActivity)
|
viewModel.handleAccountUpdate(it, this)
|
||||||
|
|
||||||
// We came from MainActivity, return there
|
// We came from MainActivity, return there
|
||||||
// and switch to the edited account
|
// and switch to the edited account
|
||||||
|
@ -81,7 +105,7 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
navigateToMainActivity()
|
navigateToMainActivity()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
accountDeleteCallback = { viewModel.updateAccounts(this@AccountSelectActivity) }
|
accountDeleteCallback = { viewModel.updateAccounts(this) }
|
||||||
)
|
)
|
||||||
|
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
|
|
|
@ -63,7 +63,8 @@ class AccountViewModel : ViewModel() {
|
||||||
|
|
||||||
fun handleAccountSelect(
|
fun handleAccountSelect(
|
||||||
account: DataStoreHelper.Account,
|
account: DataStoreHelper.Account,
|
||||||
context: Context
|
context: Context,
|
||||||
|
forStartup: Boolean = false
|
||||||
) {
|
) {
|
||||||
// Check if the selected account has a lock PIN set
|
// Check if the selected account has a lock PIN set
|
||||||
if (account.lockPin != null) {
|
if (account.lockPin != null) {
|
||||||
|
@ -71,7 +72,8 @@ class AccountViewModel : ViewModel() {
|
||||||
showPinInputDialog(
|
showPinInputDialog(
|
||||||
context,
|
context,
|
||||||
account.lockPin,
|
account.lockPin,
|
||||||
false
|
false,
|
||||||
|
forStartup
|
||||||
) { pin ->
|
) { pin ->
|
||||||
if (pin == null) return@showPinInputDialog
|
if (pin == null) return@showPinInputDialog
|
||||||
// Pin is correct, proceed
|
// Pin is correct, proceed
|
||||||
|
|
|
@ -721,6 +721,7 @@
|
||||||
|
|
||||||
|
|
||||||
<string name="enter_pin">Enter PIN</string>
|
<string name="enter_pin">Enter PIN</string>
|
||||||
|
<string name="enter_pin_with_name" formatted="true">Enter PIN for %s</string>
|
||||||
<string name="enter_current_pin">Enter Current PIN</string>
|
<string name="enter_current_pin">Enter Current PIN</string>
|
||||||
<string name="lock_profile">Lock Profile</string>
|
<string name="lock_profile">Lock Profile</string>
|
||||||
<string name="pin">PIN</string>
|
<string name="pin">PIN</string>
|
||||||
|
@ -731,4 +732,5 @@
|
||||||
<string name="edit_account">Edit account</string>
|
<string name="edit_account">Edit account</string>
|
||||||
<string name="logged_account" formatted="true">Logged in as %s</string>
|
<string name="logged_account" formatted="true">Logged in as %s</string>
|
||||||
<string name="skip_startup_account_select_pref">Skip account selection at startup</string>
|
<string name="skip_startup_account_select_pref">Skip account selection at startup</string>
|
||||||
|
<string name="use_default_account">Use Default Account</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue