Add view manager helper

This commit is contained in:
Ivan Agosto 2024-05-14 18:39:45 -06:00
parent d3466f9cce
commit ff995e383d
4 changed files with 98 additions and 87 deletions

View File

@ -12,6 +12,7 @@ import org.libre.agosto.p2play.adapters.VideosAdapter
import org.libre.agosto.p2play.ajax.Actions
import org.libre.agosto.p2play.ajax.Channels
import org.libre.agosto.p2play.ajax.Videos
import org.libre.agosto.p2play.helpers.getViewManager
import org.libre.agosto.p2play.models.ChannelModel
import org.libre.agosto.p2play.models.VideoModel
class ChannelActivity : AppCompatActivity() {
@ -32,7 +33,7 @@ class ChannelActivity : AppCompatActivity() {
channelId = this.intent.extras?.getString("channel")!!
viewManager = LinearLayoutManager(this)
viewManager = getViewManager(this, resources)
subcriptionBtn.setOnClickListener {
subscribeAction()

View File

@ -29,6 +29,7 @@ import kotlinx.android.synthetic.main.mini_player.mini_player_title
import kotlinx.android.synthetic.main.nav_header_main.*
import org.libre.agosto.p2play.adapters.VideosAdapter
import org.libre.agosto.p2play.ajax.Videos
import org.libre.agosto.p2play.helpers.getViewManager
import org.libre.agosto.p2play.models.VideoModel
import org.libre.agosto.p2play.singletons.PlaybackSingleton
@ -54,17 +55,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
nav_view.setNavigationItemSelectedListener(this)
val screenSize = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
viewManager = if (screenSize > Configuration.SCREENLAYOUT_SIZE_LARGE) {
val orientation = resources.configuration.orientation
val gridItems = when (orientation) {
Configuration.ORIENTATION_LANDSCAPE -> 4
else -> 3
}
GridLayoutManager(this, gridItems)
} else {
LinearLayoutManager(this)
}
viewManager = getViewManager(this, resources)
// Init RecyclerView
this.initRecycler()

View File

@ -0,0 +1,24 @@
package org.libre.agosto.p2play.helpers
import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView.LayoutManager
fun getViewManager (context: Context, resources: Resources): LayoutManager {
val screenSize = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
val manager = if (screenSize > Configuration.SCREENLAYOUT_SIZE_LARGE) {
val orientation = resources.configuration.orientation
val gridItems = when (orientation) {
Configuration.ORIENTATION_LANDSCAPE -> 4
else -> 3
}
GridLayoutManager(context, gridItems)
} else {
LinearLayoutManager(context)
}
return manager
}

View File

@ -6,21 +6,14 @@
android:layout_height="match_parent"
tools:context=".LoginActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintWidth_max="500dp">
<ImageView
android:id="@+id/imageView2"
@ -39,7 +32,7 @@
android:layout_height="wrap_content"
android:text="@string/loginInfo"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/>
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
<androidx.legacy.widget.Space
android:layout_width="match_parent"
@ -50,7 +43,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="@string/userTxt">
android:hint="@string/userTxt"
android:maxWidth="600dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/userText"
@ -66,15 +60,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:endIconMode="password_toggle"
android:hint="@string/passwordTxt" >
android:hint="@string/passwordTxt"
android:maxWidth="600dp"
android:maxEms="10"
app:endIconMode="password_toggle">
<EditText
android:id="@+id/passwordText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"/>
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
@ -98,5 +94,4 @@
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>