mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Some fixes
This commit is contained in:
parent
76f63a7aa2
commit
8f85aed7e8
8 changed files with 91 additions and 88 deletions
|
@ -1,8 +1,5 @@
|
|||
package com.lagradost.cloudstream3.ui.account
|
||||
|
||||
import android.graphics.RenderEffect
|
||||
import android.graphics.Shader
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -17,13 +14,14 @@ import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountEditDialog
|
|||
import com.lagradost.cloudstream3.ui.result.setImage
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
|
||||
class AccountAdapter(
|
||||
private val accounts: List<DataStoreHelper.Account>,
|
||||
private val accountSelectCallback: (DataStoreHelper.Account) -> Unit,
|
||||
private val accountCreateCallback: (DataStoreHelper.Account) -> Unit,
|
||||
private val accountEditCallback: (DataStoreHelper.Account) -> Unit,
|
||||
private val accountDeleteCallback: () -> Unit
|
||||
private val accountDeleteCallback: (DataStoreHelper.Account) -> Unit
|
||||
) : RecyclerView.Adapter<AccountAdapter.AccountViewHolder>() {
|
||||
|
||||
companion object {
|
||||
|
@ -62,11 +60,13 @@ class AccountAdapter(
|
|||
)
|
||||
} else {
|
||||
root.setOnLongClickListener {
|
||||
showAccountEditDialog(root.context, account, isNewAccount = false) {
|
||||
if (it != null) {
|
||||
accountEditCallback.invoke(it)
|
||||
} else accountDeleteCallback.invoke()
|
||||
}
|
||||
showAccountEditDialog(
|
||||
context = root.context,
|
||||
account = account,
|
||||
isNewAccount = false,
|
||||
accountEditCallback = { account -> accountEditCallback.invoke(account) },
|
||||
accountDeleteCallback = { account -> accountDeleteCallback.invoke(account) }
|
||||
)
|
||||
|
||||
true
|
||||
}
|
||||
|
@ -85,18 +85,14 @@ class AccountAdapter(
|
|||
val isLastUsedAccount = account.keyIndex == DataStoreHelper.selectedKeyIndex
|
||||
|
||||
accountName.text = account.name
|
||||
accountImage.setImage(account.image)
|
||||
accountImage.setImage(
|
||||
account.image,
|
||||
fadeIn = false,
|
||||
radius = 10
|
||||
)
|
||||
lockIcon.isVisible = account.lockPin != null
|
||||
outline.isVisible = !isTv && isLastUsedAccount
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
accountImage.setRenderEffect(
|
||||
RenderEffect.createBlurEffect(
|
||||
10f, 10f, Shader.TileMode.CLAMP
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (isTv) {
|
||||
// For emulator but this is fine on TV also
|
||||
root.isFocusableInTouchMode = true
|
||||
|
@ -111,11 +107,13 @@ class AccountAdapter(
|
|||
}
|
||||
|
||||
root.setOnClickListener {
|
||||
showAccountEditDialog(root.context, account, isNewAccount = false) {
|
||||
if (it != null) {
|
||||
accountEditCallback.invoke(it)
|
||||
} else accountDeleteCallback.invoke()
|
||||
}
|
||||
showAccountEditDialog(
|
||||
context = root.context,
|
||||
account = account,
|
||||
isNewAccount = false,
|
||||
accountEditCallback = { account -> accountEditCallback.invoke(account) },
|
||||
accountDeleteCallback = { account -> accountDeleteCallback.invoke(account) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,16 +129,18 @@ class AccountAdapter(
|
|||
|
||||
val accountName = root.context.getString(R.string.account)
|
||||
|
||||
showAccountEditDialog(root.context, DataStoreHelper.Account(
|
||||
keyIndex = keyIndex,
|
||||
name = "$accountName $keyIndex",
|
||||
customImage = null,
|
||||
defaultImageIndex = image
|
||||
), isNewAccount = true) {
|
||||
if (it != null) {
|
||||
accountCreateCallback.invoke(it)
|
||||
}
|
||||
}
|
||||
showAccountEditDialog(
|
||||
root.context,
|
||||
DataStoreHelper.Account(
|
||||
keyIndex = keyIndex,
|
||||
name = "$accountName $keyIndex",
|
||||
customImage = null,
|
||||
defaultImageIndex = image
|
||||
),
|
||||
isNewAccount = true,
|
||||
accountEditCallback = { account -> accountCreateCallback.invoke(account) },
|
||||
accountDeleteCallback = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.MainActivity
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.AccountEditDialogBinding
|
||||
|
@ -31,17 +30,16 @@ import com.lagradost.cloudstream3.ui.result.setLinearListLayout
|
|||
import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDefaultAccount
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
object AccountHelper {
|
||||
fun showAccountEditDialog(
|
||||
context: Context,
|
||||
account: DataStoreHelper.Account,
|
||||
isNewAccount: Boolean,
|
||||
callback: (DataStoreHelper.Account?) -> Unit
|
||||
accountEditCallback: (DataStoreHelper.Account) -> Unit,
|
||||
accountDeleteCallback: (DataStoreHelper.Account) -> Unit
|
||||
) {
|
||||
val binding = AccountEditDialogBinding.inflate(LayoutInflater.from(context), null, false)
|
||||
val builder = AlertDialog.Builder(context, R.style.AlertDialogCustom)
|
||||
|
@ -63,17 +61,7 @@ object AccountHelper {
|
|||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
// Remove the account
|
||||
removeKeys(account.keyIndex.toString())
|
||||
val currentAccounts = DataStoreHelper.accounts.toMutableList()
|
||||
currentAccounts.removeIf { it.keyIndex == account.keyIndex }
|
||||
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
||||
|
||||
if (account.keyIndex == DataStoreHelper.selectedKeyIndex) {
|
||||
setAccount(getDefaultAccount(context))
|
||||
}
|
||||
|
||||
callback.invoke(null)
|
||||
accountDeleteCallback.invoke(account)
|
||||
dialog?.dismissSafe()
|
||||
}
|
||||
|
||||
|
@ -117,12 +105,12 @@ object AccountHelper {
|
|||
showPinInputDialog(context, currentEditAccount.lockPin, false) { pin ->
|
||||
if (pin == null) return@showPinInputDialog
|
||||
// PIN is correct, proceed to update the account
|
||||
callback.invoke(currentEditAccount)
|
||||
accountEditCallback.invoke(currentEditAccount)
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
} else {
|
||||
// No lock PIN set, proceed to update the account
|
||||
callback.invoke(currentEditAccount)
|
||||
accountEditCallback.invoke(currentEditAccount)
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +208,7 @@ object AccountHelper {
|
|||
builder.setTitle(context.getString(R.string.enter_pin_with_name, currentAccount?.name))
|
||||
builder.setOnDismissListener {
|
||||
if (!isPinValid) {
|
||||
exitProcess(0)
|
||||
context.getActivity()?.finish()
|
||||
}
|
||||
}
|
||||
// So that if they don't know the PIN for the current account,
|
||||
|
@ -335,8 +323,6 @@ object AccountHelper {
|
|||
|
||||
recyclerView.setLinearListLayout(isHorizontal = true)
|
||||
|
||||
viewModel.updateAccounts(activity)
|
||||
|
||||
activity.observe(viewModel.accounts) { liveAccounts ->
|
||||
recyclerView.adapter = AccountAdapter(
|
||||
liveAccounts,
|
||||
|
@ -346,7 +332,7 @@ object AccountHelper {
|
|||
},
|
||||
accountCreateCallback = { viewModel.handleAccountUpdate(it, activity) },
|
||||
accountEditCallback = { viewModel.handleAccountUpdate(it, activity) },
|
||||
accountDeleteCallback = { viewModel.updateAccounts(activity) }
|
||||
accountDeleteCallback = { viewModel.handleAccountDelete(it, activity) }
|
||||
)
|
||||
|
||||
activity.observe(viewModel.selectedKeyIndex) { selectedKeyIndex ->
|
||||
|
|
|
@ -5,8 +5,8 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||
import com.lagradost.cloudstream3.CommonActivity
|
||||
import com.lagradost.cloudstream3.CommonActivity.loadThemes
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
|
@ -40,10 +40,11 @@ class AccountSelectActivity : AppCompatActivity() {
|
|||
false
|
||||
)
|
||||
|
||||
val skipStartup = getKey(
|
||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val skipStartup = settingsManager.getBoolean(
|
||||
getString(R.string.skip_startup_account_select_key),
|
||||
false
|
||||
) ?: false || accounts.count() <= 1
|
||||
) || accounts.count() <= 1
|
||||
|
||||
viewModel = ViewModelProvider(this)[AccountViewModel::class.java]
|
||||
|
||||
|
@ -105,7 +106,7 @@ class AccountSelectActivity : AppCompatActivity() {
|
|||
navigateToMainActivity()
|
||||
}
|
||||
},
|
||||
accountDeleteCallback = { viewModel.updateAccounts(this) }
|
||||
accountDeleteCallback = { viewModel.handleAccountDelete(it,this) }
|
||||
)
|
||||
|
||||
recyclerView.adapter = adapter
|
||||
|
|
|
@ -5,15 +5,19 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
|
||||
import com.lagradost.cloudstream3.ui.account.AccountHelper.showPinInputDialog
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDefaultAccount
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
||||
|
||||
class AccountViewModel : ViewModel() {
|
||||
private val _accounts: MutableLiveData<List<DataStoreHelper.Account>> = MutableLiveData(
|
||||
context?.let { getAccounts(it) } ?: DataStoreHelper.accounts.toList()
|
||||
)
|
||||
private fun getAllAccounts(): List<DataStoreHelper.Account> {
|
||||
return context?.let { getAccounts(it) } ?: DataStoreHelper.accounts.toList()
|
||||
}
|
||||
|
||||
private val _accounts: MutableLiveData<List<DataStoreHelper.Account>> = MutableLiveData(getAllAccounts())
|
||||
val accounts: LiveData<List<DataStoreHelper.Account>> = _accounts
|
||||
|
||||
private val _isEditing = MutableLiveData(false)
|
||||
|
@ -22,7 +26,11 @@ class AccountViewModel : ViewModel() {
|
|||
private val _isAllowedLogin = MutableLiveData(false)
|
||||
val isAllowedLogin: LiveData<Boolean> = _isAllowedLogin
|
||||
|
||||
private val _selectedKeyIndex = MutableLiveData(DataStoreHelper.selectedKeyIndex)
|
||||
private val _selectedKeyIndex = MutableLiveData(
|
||||
getAllAccounts().indexOfFirst {
|
||||
it.keyIndex == DataStoreHelper.selectedKeyIndex
|
||||
}
|
||||
)
|
||||
val selectedKeyIndex: LiveData<Int> = _selectedKeyIndex
|
||||
|
||||
fun setIsEditing(value: Boolean) {
|
||||
|
@ -33,11 +41,6 @@ class AccountViewModel : ViewModel() {
|
|||
_isEditing.postValue(!(_isEditing.value ?: false))
|
||||
}
|
||||
|
||||
fun updateAccounts(context: Context) {
|
||||
_accounts.postValue(getAccounts(context))
|
||||
_selectedKeyIndex.postValue(DataStoreHelper.selectedKeyIndex)
|
||||
}
|
||||
|
||||
fun handleAccountUpdate(
|
||||
account: DataStoreHelper.Account,
|
||||
context: Context
|
||||
|
@ -58,7 +61,29 @@ class AccountViewModel : ViewModel() {
|
|||
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
||||
|
||||
_accounts.postValue(getAccounts(context))
|
||||
_selectedKeyIndex.postValue(account.keyIndex)
|
||||
_selectedKeyIndex.postValue(getAccounts(context).indexOf(account))
|
||||
}
|
||||
|
||||
fun handleAccountDelete(
|
||||
account: DataStoreHelper.Account,
|
||||
context: Context
|
||||
) {
|
||||
removeKeys(account.keyIndex.toString())
|
||||
|
||||
val currentAccounts = getAccounts(context).toMutableList()
|
||||
|
||||
currentAccounts.removeIf { it.keyIndex == account.keyIndex }
|
||||
|
||||
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
||||
|
||||
if (account.keyIndex == DataStoreHelper.selectedKeyIndex) {
|
||||
setAccount(getDefaultAccount(context))
|
||||
}
|
||||
|
||||
_accounts.postValue(getAccounts(context))
|
||||
_selectedKeyIndex.postValue(getAllAccounts().indexOfFirst {
|
||||
it.keyIndex == DataStoreHelper.selectedKeyIndex
|
||||
})
|
||||
}
|
||||
|
||||
fun handleAccountSelect(
|
||||
|
@ -78,13 +103,13 @@ class AccountViewModel : ViewModel() {
|
|||
if (pin == null) return@showPinInputDialog
|
||||
// Pin is correct, proceed
|
||||
_isAllowedLogin.postValue(true)
|
||||
_selectedKeyIndex.postValue(account.keyIndex)
|
||||
_selectedKeyIndex.postValue(getAccounts(context).indexOf(account))
|
||||
setAccount(account)
|
||||
}
|
||||
} else {
|
||||
// No PIN set for the selected account, proceed
|
||||
_isAllowedLogin.postValue(true)
|
||||
_selectedKeyIndex.postValue(account.keyIndex)
|
||||
_selectedKeyIndex.postValue(getAccounts(context).indexOf(account))
|
||||
setAccount(account)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -335,15 +335,6 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
|||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
|
||||
settingsManager.edit().putBoolean(
|
||||
getString(R.string.skip_startup_account_select_key),
|
||||
getKey(getString(R.string.skip_startup_account_select_key), false) ?: false
|
||||
).apply()
|
||||
getPref(R.string.skip_startup_account_select_key)?.setOnPreferenceChangeListener { _, newValue ->
|
||||
setKey(getString(R.string.skip_startup_account_select_key), newValue)
|
||||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
|
||||
getPref(R.string.download_path_key)?.setOnPreferenceClickListener {
|
||||
val dirs = getDownloadDirs()
|
||||
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/manage_accounts_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/manage_accounts"
|
||||
android:textSize="16sp"
|
||||
app:icon="@drawable/ic_baseline_edit_24"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton" />
|
||||
style="@style/BlackButton" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,6 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_outline_account_circle_24"
|
||||
android:key="@string/skip_startup_account_select_key"
|
||||
android:title="@string/skip_startup_account_select_pref" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/mal_logo"
|
||||
android:key="@string/mal_key" />
|
||||
|
|
|
@ -11,12 +11,6 @@
|
|||
android:title="@string/download_path_pref"
|
||||
android:icon="@drawable/netflix_download" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_outline_account_circle_24"
|
||||
android:key="@string/skip_startup_account_select_key"
|
||||
android:title="@string/skip_startup_account_select_pref" />
|
||||
|
||||
<Preference
|
||||
android:key="@string/legal_notice_key"
|
||||
android:title="@string/legal_notice"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue