Restore linear account select functionality

This commit is contained in:
Luna712 2023-11-02 22:43:12 -06:00
parent 8b5a74b94a
commit f0db3068d0
6 changed files with 99 additions and 10 deletions

View file

@ -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

View file

@ -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 = {}
)
}
}

View file

@ -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

View file

@ -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()) {

View file

@ -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 {

View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:text="@string/switch_account"
android:textSize="20sp"
android:textColor="?attr/textColor"
android:layout_width="match_parent"
android:layout_rowWeight="1"
android:layout_height="wrap_content" />
<TextView
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="@string/history"
android:textSize="15sp"
android:textColor="?attr/grayTextColor"
android:layout_width="match_parent"
android:layout_rowWeight="1"
android:layout_height="wrap_content" />
<TextView
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="@string/error_bookmarks_text"
android:textSize="15sp"
android:textColor="?attr/grayTextColor"
android:layout_width="match_parent"
android:layout_rowWeight="1"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:layout_marginTop="10dp"
android:descendantFocusability="afterDescendants"
android:id="@+id/profiles_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="4"
tools:listitem="@layout/account_list_item">
<requestFocus />
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>