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,97 +6,92 @@
android:layout_height="match_parent"
tools:context=".LoginActivity">
<FrameLayout
<LinearLayout
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"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="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_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:contentDescription="Logo"
app:srcCompat="@drawable/icon" />
<ImageView
android:id="@+id/imageView2"
<androidx.legacy.widget.Space
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_height="wrap_content"
android:contentDescription="Logo"
app:srcCompat="@drawable/icon" />
android:ems="10"
android:hint="@string/userText"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.legacy.widget.Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/passwordTxt"
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
android:id="@+id/loginInfo"
<EditText
android:id="@+id/passwordText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/loginInfo"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/>
android:ems="10"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.legacy.widget.Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<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" />
<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">
<androidx.legacy.widget.Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/userText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/userText"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<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" />
<com.google.android.material.textfield.TextInputLayout
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" >
</LinearLayout>
<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>