Improve layout

This commit is contained in:
Luna712 2023-10-29 21:43:03 -06:00
parent df92ad9655
commit 8fe4f58b5a
5 changed files with 55 additions and 13 deletions

View file

@ -8,7 +8,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.databinding.AccountListItemBinding
import com.lagradost.cloudstream3.ui.result.setImage
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.DataStoreHelper
class AccountAdapter(
@ -28,7 +28,7 @@ class AccountAdapter(
binding.outline.isVisible = isLastUsedAccount
@RequiresApi(Build.VERSION_CODES.O)
if (isTrueTvSettings()) {
if (isTvSettings()) {
binding.root.isFocusedByDefault = isLastUsedAccount
}
@ -42,6 +42,15 @@ class AccountAdapter(
val binding = AccountListItemBinding.inflate(
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

@ -8,7 +8,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.CommonActivity
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
@ -16,16 +18,17 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
class AccountSelectActivity : AppCompatActivity() {
private lateinit var binding: ActivityAccountSelectBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
CommonActivity.init(this)
binding = ActivityAccountSelectBinding.inflate(layoutInflater)
val binding = if (isTvSettings()) {
ActivityAccountSelectTvBinding.inflate(layoutInflater)
} else ActivityAccountSelectBinding.inflate(layoutInflater)
setContentView(binding.root)
val recyclerView: RecyclerView = binding.accountRecyclerView
val recyclerView: RecyclerView = binding.root.findViewById(R.id.account_recycler_view)
val accounts = getAccounts(this@AccountSelectActivity)
@ -44,7 +47,7 @@ class AccountSelectActivity : AppCompatActivity() {
recyclerView.layoutManager = if (isTvSettings()) {
LinearLayoutManager(this)
} else GridLayoutManager(this, 3)
} else GridLayoutManager(this, 2)
}
private fun onAccountSelected(selectedAccount: DataStoreHelper.Account) {

View file

@ -4,13 +4,13 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_width="110dp"
android:layout_height="110dp"
android:animateLayoutChanges="true"
android:backgroundTint="?attr/primaryGrayBackground"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="@dimen/rounded_image_radius"
android:layout_margin="5dp"
android:layout_margin="15dp"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1"

View file

@ -2,7 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/primaryBlackBackground"
android:background="?attr/black"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -19,9 +19,11 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/account_recycler_view"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp" />
android:layout_gravity="center_horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</LinearLayout>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/black"
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>