diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountAdapter.kt index 33662329..d652563d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountAdapter.kt @@ -9,7 +9,7 @@ import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.databinding.AccountListItemAddBinding import com.lagradost.cloudstream3.databinding.AccountListItemBinding import com.lagradost.cloudstream3.databinding.AccountListItemEditingBinding -import com.lagradost.cloudstream3.ui.account.AccountDialogs.showAccountEditDialog +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 diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountDialogs.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt similarity index 86% rename from app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountDialogs.kt rename to app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt index 08da3abe..60f5da7f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountDialogs.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountHelper.kt @@ -11,12 +11,15 @@ import androidx.appcompat.app.AlertDialog import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.core.widget.doOnTextChanged +import com.google.android.material.bottomsheet.BottomSheetDialog import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.databinding.AccountEditDialogBinding +import com.lagradost.cloudstream3.databinding.AccountSelectLinearBinding import com.lagradost.cloudstream3.databinding.LockPinDialogBinding import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.result.setImage +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 @@ -24,7 +27,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod -object AccountDialogs { +object AccountHelper { fun showAccountEditDialog( context: Context, account: DataStoreHelper.Account, @@ -265,4 +268,38 @@ object AccountDialogs { showInputMethod(binding.pinEditText) }, 200) } + + fun showAccountSelectLinear(context: Context) { + val binding: AccountSelectLinearBinding = AccountSelectLinearBinding.inflate( + LayoutInflater.from(context) + ) + + val builder = BottomSheetDialog(context) + builder.setContentView(binding.root) + builder.show() + + binding.profilesRecyclerview.setLinearListLayout(isHorizontal = true) + binding.profilesRecyclerview.adapter = AccountAdapter( + DataStoreHelper.getAccounts(context), + accountSelectCallback = { account -> + // Check if the selected account has a lock PIN set + if (account.lockPin != null) { + // Prompt for the lock pin + showPinInputDialog(context, account.lockPin, false) { pin -> + if (pin == null) return@showPinInputDialog + // Pin is correct, unlock the profile + setAccount(account, true) + builder.dismissSafe() + } + } else { + // No lock PIN set, directly set the account + setAccount(account, true) + builder.dismissSafe() + } + }, + accountCreateCallback = {}, + // TODO + accountEditCallback = {} + ) + } } \ No newline at end of file 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 36c6376f..ab720708 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 @@ -11,7 +11,7 @@ import com.lagradost.cloudstream3.MainActivity import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.databinding.ActivityAccountSelectBinding import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_EDIT_ACCOUNT -import com.lagradost.cloudstream3.ui.account.AccountDialogs.showPinInputDialog +import com.lagradost.cloudstream3.ui.account.AccountHelper.showPinInputDialog import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index 0fc80e91..a13f2944 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -38,7 +38,7 @@ import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observeNullable import com.lagradost.cloudstream3.ui.APIRepository.Companion.noneApi import com.lagradost.cloudstream3.ui.APIRepository.Companion.randomApi -import com.lagradost.cloudstream3.ui.account.AccountSelectActivity +import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountSelectLinear import com.lagradost.cloudstream3.ui.result.txt import com.lagradost.cloudstream3.ui.search.* import com.lagradost.cloudstream3.ui.search.SearchHelper.handleSearchClickCallback @@ -497,8 +497,7 @@ class HomeFragment : Fragment() { homeApiFab.setOnClickListener(apiChangeClickListener) homeChangeApi.setOnClickListener(apiChangeClickListener) homeSwitchAccount.setOnClickListener { v -> - val accountSelectIntent = Intent(v.context, AccountSelectActivity::class.java) - v.context.startActivity(accountSelectIntent) + showAccountSelectLinear(v?.context ?: return@setOnClickListener) } homeRandom.setOnClickListener { if (listHomepageItems.isNotEmpty()) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt index 22d46b6b..2616c92a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt @@ -1,6 +1,5 @@ package com.lagradost.cloudstream3.ui.home -import android.content.Intent import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -28,7 +27,7 @@ import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.debugException import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.ui.WatchType -import com.lagradost.cloudstream3.ui.account.AccountSelectActivity +import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountSelectLinear import com.lagradost.cloudstream3.ui.home.HomeFragment.Companion.selectHomepage import com.lagradost.cloudstream3.ui.result.FOCUS_SELF import com.lagradost.cloudstream3.ui.result.ResultViewModel2 @@ -480,8 +479,7 @@ class HomeParentItemAdapterPreview( } homeAccount?.setOnClickListener { v -> - val accountSelectIntent = Intent(v.context, AccountSelectActivity::class.java) - v.context.startActivity(accountSelectIntent) + showAccountSelectLinear(v?.context ?: return@setOnClickListener) } (binding as? FragmentHomeHeadTvBinding)?.apply { diff --git a/app/src/main/res/layout/account_select_linear.xml b/app/src/main/res/layout/account_select_linear.xml new file mode 100644 index 00000000..5fbf83d5 --- /dev/null +++ b/app/src/main/res/layout/account_select_linear.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + \ No newline at end of file