Use nicer grid layout for account select on TV (#737)

This commit is contained in:
Luna712 2023-11-02 14:14:16 -06:00 committed by GitHub
parent 6a8c251013
commit 5b0cbbf09f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 45 deletions

View file

@ -43,14 +43,6 @@ class AccountAdapter(
LayoutInflater.from(parent.context), parent, false
)
if (isTvSettings()) {
val layoutParams = binding.root.layoutParams as RecyclerView.LayoutParams
val marginInDp = 5 // Set the margin to 5dp
val marginInPixels = (marginInDp * parent.resources.displayMetrics.density).toInt()
layoutParams.setMargins(marginInPixels, marginInPixels, marginInPixels, marginInPixels)
binding.root.layoutParams = layoutParams
}
return AccountViewHolder(binding)
}

View file

@ -4,14 +4,12 @@ import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.CommonActivity.loadThemes
import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.databinding.ActivityAccountSelectBinding
import com.lagradost.cloudstream3.databinding.ActivityAccountSelectTvBinding
import com.lagradost.cloudstream3.ui.account.AccountDialog.showPinInputDialog
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.DataStoreHelper
@ -36,13 +34,11 @@ class AccountSelectActivity : AppCompatActivity() {
window.navigationBarColor = colorFromAttribute(R.attr.primaryBlackBackground)
val binding = if (isTvSettings()) {
ActivityAccountSelectTvBinding.inflate(layoutInflater)
} else ActivityAccountSelectBinding.inflate(layoutInflater)
val binding = ActivityAccountSelectBinding.inflate(layoutInflater)
setContentView(binding.root)
val recyclerView: RecyclerView = binding.root.findViewById(R.id.account_recycler_view)
val recyclerView: RecyclerView = binding.accountRecyclerView
val adapter = AccountAdapter(accounts) { selectedAccount ->
@ -51,9 +47,13 @@ class AccountSelectActivity : AppCompatActivity() {
}
recyclerView.adapter = adapter
recyclerView.layoutManager = if (isTvSettings()) {
LinearLayoutManager(this)
} else GridLayoutManager(this, 2)
if (isTvSettings()) {
val spanSize = if (accounts.count() <= 6) {
accounts.count()
} else 6
recyclerView.layoutManager = GridLayoutManager(this, spanSize)
}
}
private fun onAccountSelected(selectedAccount: DataStoreHelper.Account) {

View file

@ -17,7 +17,7 @@
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />
<androidx.recyclerview.widget.RecyclerView
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
android:id="@+id/account_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/primaryBlackBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="36dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:text="@string/select_an_account"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/account_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" />
</LinearLayout>