From 0b4dd5beefa0acf71e87e6ad2b5f8783d6c4cb22 Mon Sep 17 00:00:00 2001 From: Zakhar Timoshenko Date: Wed, 17 Jan 2024 16:09:55 +0300 Subject: [PATCH] Enhance chapter items --- .../details/ui/adapter/ChapterListItemAD.kt | 35 +++++++++++-------- .../details/ui/model/ChapterListItem.kt | 9 ++--- .../main/res/drawable/ic_current_chapter.xml | 11 ++++++ app/src/main/res/drawable/ic_new.xml | 8 ++--- app/src/main/res/layout/item_chapter.xml | 18 ++-------- 5 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 app/src/main/res/drawable/ic_current_chapter.xml diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt index 2c11ee18f..41721e951 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt @@ -1,5 +1,6 @@ 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 @@ -7,11 +8,10 @@ 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.getThemeColor +import org.koitharu.kotatsu.core.util.ext.getThemeColorStateList import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ItemChapterBinding import org.koitharu.kotatsu.details.ui.model.ChapterListItem -import com.google.android.material.R as materialR fun chapterListItemAD( clickListener: OnListItemClickListener, @@ -26,31 +26,38 @@ fun chapterListItemAD( bind { payloads -> if (payloads.isEmpty()) { binding.textViewTitle.text = item.chapter.name - binding.textViewNumber.text = item.chapter.number.toString() binding.textViewDescription.textAndVisible = item.description() } when { item.isCurrent -> { - binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_primary) - binding.textViewNumber.setTextColor(context.getThemeColor(materialR.attr.colorOnPrimary)) + binding.textViewTitle.drawableStart = ContextCompat.getDrawable(context, R.drawable.ic_current_chapter) + binding.textViewTitle.setTextColor(context.getThemeColorStateList(android.R.attr.textColorPrimary)) + binding.textViewDescription.setTextColor(context.getThemeColorStateList(android.R.attr.textColorPrimary)) + binding.textViewTitle.typeface = Typeface.DEFAULT_BOLD + binding.textViewDescription.typeface = Typeface.DEFAULT_BOLD } item.isUnread -> { - binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_default) - binding.textViewNumber.setTextColor(context.getThemeColor(materialR.attr.colorOnTertiary)) + 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.textViewDescription.setTextColor(context.getThemeColorStateList(android.R.attr.textColorPrimary)) + binding.textViewTitle.typeface = Typeface.DEFAULT + binding.textViewDescription.typeface = Typeface.DEFAULT } else -> { - binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_outline) - binding.textViewNumber.setTextColor(context.getThemeColor(android.R.attr.textColorTertiary)) + binding.textViewTitle.drawableStart = null + binding.textViewTitle.setTextColor(context.getThemeColorStateList(android.R.attr.textColorHint)) + binding.textViewDescription.setTextColor(context.getThemeColorStateList(android.R.attr.textColorHint)) + binding.textViewTitle.typeface = Typeface.DEFAULT + binding.textViewDescription.typeface = Typeface.DEFAULT } } binding.imageViewBookmarked.isVisible = item.isBookmarked binding.imageViewDownloaded.isVisible = item.isDownloaded - binding.textViewTitle.drawableStart = if (item.isNew) { - ContextCompat.getDrawable(context, R.drawable.ic_new) - } else { - null - } } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt index 609f6ad09..e9b987ebb 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/ChapterListItem.kt @@ -38,12 +38,13 @@ data class ChapterListItem( val isNew: Boolean get() = hasFlag(FLAG_NEW) - fun description(): CharSequence? { + fun description(): CharSequence { + val number = chapter.number.toString() val scanlator = chapter.scanlator?.takeUnless { it.isBlank() } return when { - uploadDate != null && scanlator != null -> "$uploadDate • $scanlator" - scanlator != null -> scanlator - else -> uploadDate + uploadDate != null && scanlator != null -> "#$number • $uploadDate • $scanlator" + scanlator != null -> "#$number • $scanlator" + else -> "#$number • $uploadDate" } } diff --git a/app/src/main/res/drawable/ic_current_chapter.xml b/app/src/main/res/drawable/ic_current_chapter.xml new file mode 100644 index 000000000..602e1bc0c --- /dev/null +++ b/app/src/main/res/drawable/ic_current_chapter.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_new.xml b/app/src/main/res/drawable/ic_new.xml index f0e81e12d..2c9614c24 100644 --- a/app/src/main/res/drawable/ic_new.xml +++ b/app/src/main/res/drawable/ic_new.xml @@ -1,11 +1,11 @@ + android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z" /> diff --git a/app/src/main/res/layout/item_chapter.xml b/app/src/main/res/layout/item_chapter.xml index 3244de9c9..fd9082b03 100644 --- a/app/src/main/res/layout/item_chapter.xml +++ b/app/src/main/res/layout/item_chapter.xml @@ -4,27 +4,13 @@ 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" + android:layout_height="?attr/listPreferredItemHeight" android:background="?selectableItemBackground" android:baselineAligned="false" android:gravity="center_vertical" android:minHeight="@dimen/chapter_list_item_height" android:orientation="horizontal"> - -