mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
ViewBinding
This commit is contained in:
parent
512a58b49c
commit
3c94fbcb86
4 changed files with 30 additions and 31 deletions
|
@ -1,44 +1,41 @@
|
|||
package com.lagradost.cloudstream3.ui.account
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.AccountListItemBinding
|
||||
import com.lagradost.cloudstream3.ui.result.setImage
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
|
||||
class AccountAdapter(private val accounts: List<DataStoreHelper.Account>, private val onItemClick: (DataStoreHelper.Account) -> Unit) :
|
||||
RecyclerView.Adapter<AccountAdapter.AccountViewHolder>() {
|
||||
class AccountAdapter(
|
||||
private val accounts: List<DataStoreHelper.Account>,
|
||||
private val onItemClick: (DataStoreHelper.Account) -> Unit
|
||||
) : RecyclerView.Adapter<AccountAdapter.AccountViewHolder>() {
|
||||
|
||||
inner class AccountViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val accountName: TextView = itemView.findViewById(R.id.account_name)
|
||||
val accountImage: ImageView = itemView.findViewById(R.id.account_image)
|
||||
val lockIcon: ImageView = itemView.findViewById(R.id.lock_icon)
|
||||
inner class AccountViewHolder(private val binding: AccountListItemBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(account: DataStoreHelper.Account) {
|
||||
binding.accountName.text = account.name
|
||||
binding.accountImage.setImage(account.image)
|
||||
binding.lockIcon.isVisible = account.lockPin != null
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
onItemClick(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AccountViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.account_list_item, parent, false)
|
||||
return AccountViewHolder(view)
|
||||
val binding = AccountListItemBinding.inflate(
|
||||
LayoutInflater.from(parent.context), parent, false
|
||||
)
|
||||
return AccountViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: AccountViewHolder, position: Int) {
|
||||
val account = accounts[position]
|
||||
|
||||
// Populate data into the UI elements
|
||||
holder.accountName.text = account.name
|
||||
holder.accountImage.setImage(account.image)
|
||||
|
||||
if (account.lockPin != null) {
|
||||
holder.lockIcon.isVisible = true
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
onItemClick(account)
|
||||
}
|
||||
holder.bind(accounts[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
|
|
@ -6,18 +6,21 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lagradost.cloudstream3.MainActivity
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.ActivityAccountSelectBinding
|
||||
import com.lagradost.cloudstream3.ui.account.AccountDialog.showPinInputDialog
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
|
||||
|
||||
class AccountSelectActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityAccountSelectBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_account_select)
|
||||
binding = ActivityAccountSelectBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val recyclerView: RecyclerView = findViewById(R.id.accountRecyclerView)
|
||||
val recyclerView: RecyclerView = binding.accountRecyclerView
|
||||
|
||||
val accounts = getAccounts(this@AccountSelectActivity)
|
||||
|
||||
|
@ -51,6 +54,4 @@ class AccountSelectActivity : AppCompatActivity() {
|
|||
startActivity(mainIntent)
|
||||
finish() // Finish the account selection activity
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
android:layout_margin="4dp"
|
||||
android:src="@drawable/video_locked"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_name"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
android:layout_marginBottom="16dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/accountRecyclerView"
|
||||
android:id="@+id/account_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue