mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Use nicer grid layout for account select on TV (#737)
This commit is contained in:
parent
6a8c251013
commit
5b0cbbf09f
4 changed files with 10 additions and 45 deletions
|
@ -43,14 +43,6 @@ class AccountAdapter(
|
||||||
LayoutInflater.from(parent.context), parent, false
|
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)
|
return AccountViewHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,12 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.lagradost.cloudstream3.CommonActivity
|
import com.lagradost.cloudstream3.CommonActivity
|
||||||
import com.lagradost.cloudstream3.CommonActivity.loadThemes
|
import com.lagradost.cloudstream3.CommonActivity.loadThemes
|
||||||
import com.lagradost.cloudstream3.MainActivity
|
import com.lagradost.cloudstream3.MainActivity
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.databinding.ActivityAccountSelectBinding
|
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.account.AccountDialog.showPinInputDialog
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||||
|
@ -36,13 +34,11 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
|
|
||||||
window.navigationBarColor = colorFromAttribute(R.attr.primaryBlackBackground)
|
window.navigationBarColor = colorFromAttribute(R.attr.primaryBlackBackground)
|
||||||
|
|
||||||
val binding = if (isTvSettings()) {
|
val binding = ActivityAccountSelectBinding.inflate(layoutInflater)
|
||||||
ActivityAccountSelectTvBinding.inflate(layoutInflater)
|
|
||||||
} else ActivityAccountSelectBinding.inflate(layoutInflater)
|
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
val recyclerView: RecyclerView = binding.root.findViewById(R.id.account_recycler_view)
|
val recyclerView: RecyclerView = binding.accountRecyclerView
|
||||||
|
|
||||||
|
|
||||||
val adapter = AccountAdapter(accounts) { selectedAccount ->
|
val adapter = AccountAdapter(accounts) { selectedAccount ->
|
||||||
|
@ -51,9 +47,13 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
|
|
||||||
recyclerView.layoutManager = if (isTvSettings()) {
|
if (isTvSettings()) {
|
||||||
LinearLayoutManager(this)
|
val spanSize = if (accounts.count() <= 6) {
|
||||||
} else GridLayoutManager(this, 2)
|
accounts.count()
|
||||||
|
} else 6
|
||||||
|
|
||||||
|
recyclerView.layoutManager = GridLayoutManager(this, spanSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onAccountSelected(selectedAccount: DataStoreHelper.Account) {
|
private fun onAccountSelected(selectedAccount: DataStoreHelper.Account) {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginBottom="16dp" />
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||||
android:id="@+id/account_recycler_view"
|
android:id="@+id/account_recycler_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -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>
|
|
Loading…
Reference in a new issue