Update chapters grid ui
parent
bec0ce2c96
commit
65077c1fba
@ -0,0 +1,46 @@
|
||||
package org.koitharu.kotatsu.details.ui.pager.chapters
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.koitharu.kotatsu.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class ChapterGridSpanHelper private constructor() : View.OnLayoutChangeListener {
|
||||
|
||||
override fun onLayoutChange(
|
||||
v: View?,
|
||||
left: Int,
|
||||
top: Int,
|
||||
right: Int,
|
||||
bottom: Int,
|
||||
oldLeft: Int,
|
||||
oldTop: Int,
|
||||
oldRight: Int,
|
||||
oldBottom: Int
|
||||
) {
|
||||
val rv = v as? RecyclerView ?: return
|
||||
if (rv.width > 0) {
|
||||
apply(rv)
|
||||
}
|
||||
}
|
||||
|
||||
private fun apply(rv: RecyclerView) {
|
||||
(rv.layoutManager as? GridLayoutManager)?.spanCount = getSpanCount(rv)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun attach(view: RecyclerView) {
|
||||
val helper = ChapterGridSpanHelper()
|
||||
view.addOnLayoutChangeListener(helper)
|
||||
helper.apply(view)
|
||||
}
|
||||
|
||||
fun getSpanCount(view: RecyclerView): Int {
|
||||
val cellWidth = view.resources.getDimension(R.dimen.chapter_grid_width)
|
||||
val estimatedCount = (view.width / cellWidth).roundToInt()
|
||||
return estimatedCount.coerceAtLeast(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,68 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="?materialCardViewOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:layout_width="@dimen/chapter_grid_width">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
<TextView
|
||||
android:id="@+id/textView_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="6dp"
|
||||
android:clipChildren="false"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="H,1:1"
|
||||
android:gravity="center"
|
||||
android:singleLine="true"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="?attr/textAppearanceTitleMedium"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?attr/textAppearanceBodyLarge"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="150"
|
||||
tools:textColor="?android:textColorPrimary" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="6dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView_bookmarked"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_width="14dp"
|
||||
android:layout_height="14dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:contentDescription="@string/bookmarks"
|
||||
app:srcCompat="@drawable/ic_bookmark" />
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@id/textView_title"
|
||||
app:layout_constraintEnd_toEndOf="@id/textView_title"
|
||||
app:srcCompat="@drawable/ic_bookmark"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView_downloaded"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_width="14dp"
|
||||
android:layout_height="14dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:contentDescription="@string/downloaded"
|
||||
app:srcCompat="@drawable/ic_save_ok" />
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@id/textView_title"
|
||||
app:layout_constraintEnd_toStartOf="@id/imageView_bookmarked"
|
||||
app:srcCompat="@drawable/ic_save_ok"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/imageView_new"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:contentDescription="@string/new_chapters"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="@id/textView_title"
|
||||
app:layout_constraintTop_toTopOf="@id/textView_title"
|
||||
app:srcCompat="@drawable/ic_new"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/imageView_current"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:contentDescription="@string/new_chapters"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintStart_toStartOf="@id/textView_title"
|
||||
app:layout_constraintTop_toTopOf="@id/textView_title"
|
||||
app:srcCompat="@drawable/ic_current_chapter"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
Loading…
Reference in New Issue