Skip to content

Commit

Permalink
Use nicer grid layout for account select on TV (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna712 authored Nov 2, 2023
1 parent 6a8c251 commit 5b0cbbf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_account_select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 0 additions & 27 deletions app/src/main/res/layout/activity_account_select_tv.xml

This file was deleted.

0 comments on commit 5b0cbbf

Please sign in to comment.