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.Actions
import org.libre.agosto.p2play.ajax.Channels import org.libre.agosto.p2play.ajax.Channels
import org.libre.agosto.p2play.ajax.Videos 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.ChannelModel
import org.libre.agosto.p2play.models.VideoModel import org.libre.agosto.p2play.models.VideoModel
class ChannelActivity : AppCompatActivity() { class ChannelActivity : AppCompatActivity() {
@ -32,7 +33,7 @@ class ChannelActivity : AppCompatActivity() {
channelId = this.intent.extras?.getString("channel")!! channelId = this.intent.extras?.getString("channel")!!
viewManager = LinearLayoutManager(this) viewManager = getViewManager(this, resources)
subcriptionBtn.setOnClickListener { subcriptionBtn.setOnClickListener {
subscribeAction() 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 kotlinx.android.synthetic.main.nav_header_main.*
import org.libre.agosto.p2play.adapters.VideosAdapter import org.libre.agosto.p2play.adapters.VideosAdapter
import org.libre.agosto.p2play.ajax.Videos 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.models.VideoModel
import org.libre.agosto.p2play.singletons.PlaybackSingleton import org.libre.agosto.p2play.singletons.PlaybackSingleton
@ -54,17 +55,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
nav_view.setNavigationItemSelectedListener(this) nav_view.setNavigationItemSelectedListener(this)
val screenSize = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK viewManager = getViewManager(this, resources)
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)
}
// Init RecyclerView // Init RecyclerView
this.initRecycler() 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,97 +6,92 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".LoginActivity"> tools:context=".LoginActivity">
<FrameLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="8dp" android:gravity="center"
android:layout_marginStart="8dp" android:orientation="vertical"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintWidth_max="500dp">
<LinearLayout <ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"> android:contentDescription="Logo"
app:srcCompat="@drawable/icon" />
<ImageView <androidx.legacy.widget.Space
android:id="@+id/imageView2" android:layout_width="match_parent"
android:layout_height="30dp" />
<TextView
android:id="@+id/loginInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/loginInfo"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
<androidx.legacy.widget.Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/userTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="@string/userTxt"
android:maxWidth="600dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/userText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="Logo" android:ems="10"
app:srcCompat="@drawable/icon" /> android:hint="@string/userText"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.legacy.widget.Space <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:id="@+id/passwordTxt"
android:layout_height="30dp" /> android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="@string/passwordTxt"
android:maxWidth="600dp"
android:maxEms="10"
app:endIconMode="password_toggle">
<TextView <EditText
android:id="@+id/loginInfo" android:id="@+id/passwordText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/loginInfo" android:ems="10"
android:textAlignment="center" android:inputType="textPassword" />
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> </com.google.android.material.textfield.TextInputLayout>
<androidx.legacy.widget.Space <com.google.android.material.button.MaterialButton
android:layout_width="match_parent" android:id="@+id/loginBtn"
android:layout_height="30dp" /> android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/loginBtn"
android:textAlignment="center" />
<com.google.android.material.textfield.TextInputLayout <androidx.legacy.widget.Space
android:id="@+id/userTxt" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="30dp" />
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="@string/userTxt">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.button.MaterialButton
android:id="@+id/userText" android:id="@+id/registerActionBtn"
android:layout_width="match_parent" style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:ems="10" android:layout_height="wrap_content"
android:hint="@string/userText" android:text="@string/registerActionBtn"
android:inputType="text" /> android:visibility="invisible" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout </LinearLayout>
android:id="@+id/passwordTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:endIconMode="password_toggle"
android:hint="@string/passwordTxt" >
<EditText
android:id="@+id/passwordText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/loginBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/loginBtn"
android:textAlignment="center" />
<androidx.legacy.widget.Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/registerActionBtn"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/registerActionBtn"
android:visibility="invisible" />
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>