Create chapterGridItemAD and its associated item_chapter_grid
This commit is contained in:
@@ -0,0 +1,58 @@
|
|||||||
|
package org.koitharu.kotatsu.details.ui.adapter
|
||||||
|
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.drawableStart
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.getThemeColorStateList
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemChapterGridBinding
|
||||||
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
fun chapterGridItemAD(
|
||||||
|
clickListener: OnListItemClickListener<ChapterListItem>,
|
||||||
|
) = adapterDelegateViewBinding<ChapterListItem, ListModel, ItemChapterGridBinding>(
|
||||||
|
{ inflater, parent -> ItemChapterGridBinding.inflate(inflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
val eventListener = AdapterDelegateClickListenerAdapter(this, clickListener)
|
||||||
|
itemView.setOnClickListener(eventListener)
|
||||||
|
itemView.setOnLongClickListener(eventListener)
|
||||||
|
|
||||||
|
bind { payloads ->
|
||||||
|
if (payloads.isEmpty()) {
|
||||||
|
binding.textViewTitle.text = item.chapter.number.roundToInt().toString()
|
||||||
|
}
|
||||||
|
when {
|
||||||
|
item.isCurrent -> {
|
||||||
|
binding.textViewTitle.drawableStart = ContextCompat.getDrawable(context, R.drawable.ic_current_chapter)
|
||||||
|
binding.textViewTitle.setTextColor(context.getThemeColorStateList(android.R.attr.textColorPrimary))
|
||||||
|
binding.textViewTitle.typeface = Typeface.DEFAULT_BOLD
|
||||||
|
}
|
||||||
|
|
||||||
|
item.isUnread -> {
|
||||||
|
binding.textViewTitle.drawableStart = if (item.isNew) {
|
||||||
|
ContextCompat.getDrawable(context, R.drawable.ic_new)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
binding.textViewTitle.setTextColor(context.getThemeColorStateList(android.R.attr.textColorPrimary))
|
||||||
|
binding.textViewTitle.typeface = Typeface.DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
binding.textViewTitle.drawableStart = null
|
||||||
|
binding.textViewTitle.setTextColor(context.getThemeColorStateList(android.R.attr.textColorHint))
|
||||||
|
binding.textViewTitle.typeface = Typeface.DEFAULT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.imageViewBookmarked.isVisible = item.isBookmarked
|
||||||
|
binding.imageViewDownloaded.isVisible = item.isDownloaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
68
app/src/main/res/layout/item_chapter_grid.xml
Normal file
68
app/src/main/res/layout/item_chapter_grid.xml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:clipChildren="false"
|
||||||
|
app:cardCornerRadius="16dp"
|
||||||
|
app:cardUseCompatPadding="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintDimensionRatio="H,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"
|
||||||
|
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_marginEnd="6dp"
|
||||||
|
android:contentDescription="@string/bookmarks"
|
||||||
|
app:srcCompat="@drawable/ic_bookmark" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView_downloaded"
|
||||||
|
android:layout_width="20dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
android:contentDescription="@string/downloaded"
|
||||||
|
app:srcCompat="@drawable/ic_save_ok" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user