Show scanlator's name in updates if grouped updates also has the same chapter

Also fixes to the xml preview of the download button
This commit is contained in:
Jays2Kings 2023-03-02 20:07:29 -05:00
parent 9a48186d7f
commit 0a2991de96
4 changed files with 125 additions and 76 deletions

View file

@ -22,64 +22,46 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut
var colorSecondary = context.getResourceColor(R.attr.colorSecondary) var colorSecondary = context.getResourceColor(R.attr.colorSecondary)
set(value) { set(value) {
field = value field = value
activeColor = ColorUtils.blendARGB( activeColor = colorSecondary
colorSecondary, downloadedColor = colorSecondary
context.getResourceColor(R.attr.background), }
0.05f, private var activeColor = colorSecondary
) set(value) {
downloadedColor = ColorUtils.blendARGB( ColorUtils.blendARGB(value, context.getResourceColor(R.attr.background), 0.05f)
colorSecondary, }
context.getResourceColor(R.attr.colorOnBackground),
0.3f, private var downloadedColor = colorSecondary
) set(value) {
ColorUtils.blendARGB(value, context.getResourceColor(R.attr.colorOnBackground), 0.3f)
}
private val progressBGColor by lazy {
ContextCompat.getColor(context, R.color.divider)
}
private val disabledColor by lazy {
ContextCompat.getColor(context, R.color.material_on_surface_disabled)
} }
private var activeColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.background),
0.05f,
)
private val progressBGColor = ContextCompat.getColor(
context,
R.color.divider,
)
private val disabledColor = ContextCompat.getColor(
context,
R.color.material_on_surface_disabled,
)
private var downloadedColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.colorOnBackground),
0.3f,
)
private val downloadedTextColor = context.getResourceColor(R.attr.background) private val downloadedTextColor = context.getResourceColor(R.attr.background)
private val errorColor = ContextCompat.getColor( private val errorColor by lazy {
context, ContextCompat.getColor(context, R.color.material_red_500)
R.color.material_red_500, }
) private val filledCircle by lazy {
private val filledCircle = ContextCompat.getDrawable( ContextCompat.getDrawable(context, R.drawable.filled_circle)?.mutate()
context, }
R.drawable.filled_circle, private val borderCircle by lazy {
)?.mutate() ContextCompat.getDrawable(context, R.drawable.border_circle)?.mutate()
private val borderCircle = ContextCompat.getDrawable( }
context, private val downloadDrawable by lazy {
R.drawable.border_circle, ContextCompat.getDrawable(context, R.drawable.ic_arrow_downward_24dp)?.mutate()
)?.mutate() }
private val downloadDrawable = ContextCompat.getDrawable( private val checkDrawable by lazy {
context, ContextCompat.getDrawable(context, R.drawable.ic_check_24dp)?.mutate()
R.drawable.ic_arrow_downward_24dp, }
)?.mutate() private val filledAnim by lazy {
private val checkDrawable = ContextCompat.getDrawable( AnimatedVectorDrawableCompat.create(context, R.drawable.anim_outline_to_filled)
context, }
R.drawable.ic_check_24dp, private val checkAnim by lazy {
)?.mutate() AnimatedVectorDrawableCompat.create(context, R.drawable.anim_dl_to_check_to_dl)
private val filledAnim = AnimatedVectorDrawableCompat.create( }
context,
R.drawable.anim_outline_to_filled,
)
private val checkAnim = AnimatedVectorDrawableCompat.create(
context,
R.drawable.anim_dl_to_check_to_dl,
)
private var isAnimating = false private var isAnimating = false
private var iconAnimation: ObjectAnimator? = null private var iconAnimation: ObjectAnimator? = null

View file

@ -59,11 +59,14 @@ class RecentMangaHolder(
) )
if (moreVisible) { if (moreVisible) {
binding.moreChaptersLayout.children.forEach { view -> binding.moreChaptersLayout.children.forEach { view ->
try {
RecentSubChapterItemBinding.bind(view).updateDivider() RecentSubChapterItemBinding.bind(view).updateDivider()
} catch (_: Exception) {
} }
} }
if (binding.moreChaptersLayout.children.any { view ->
!RecentSubChapterItemBinding.bind(view).subtitle.text.isNullOrBlank()
}
) {
showScanlatorInBody(moreVisible)
} }
binding.endView.updateLayoutParams<ViewGroup.LayoutParams> { binding.endView.updateLayoutParams<ViewGroup.LayoutParams> {
height = binding.mainView.height height = binding.mainView.height
@ -223,15 +226,34 @@ class RecentMangaHolder(
RecentSubChapterItemBinding.bind(binding.moreChaptersLayout.getChildAt(index)) RecentSubChapterItemBinding.bind(binding.moreChaptersLayout.getChildAt(index))
.configureView(chapter, item) .configureView(chapter, item)
} }
if (binding.moreChaptersLayout.children.any { view ->
!RecentSubChapterItemBinding.bind(view).subtitle.text.isNullOrBlank()
}
) {
showScanlatorInBody(moreVisible, item)
}
} else { } else {
binding.moreChaptersLayout.removeAllViews() binding.moreChaptersLayout.removeAllViews()
var hasSameChapter = false
if (item.mch.extraChapters.isNotEmpty()) { if (item.mch.extraChapters.isNotEmpty()) {
item.mch.extraChapters.forEach { chapter -> item.mch.extraChapters.forEach { chapter ->
RecentSubChapterItemBinding.inflate( val binding = RecentSubChapterItemBinding.inflate(
LayoutInflater.from(context), LayoutInflater.from(context),
binding.moreChaptersLayout, binding.moreChaptersLayout,
true, true,
).configureView(chapter, item) )
binding.configureView(chapter, item)
if (chapter.isRecognizedNumber &&
chapter.chapter_number == item.chapter.chapter_number &&
!chapter.scanlator.isNullOrBlank()
) {
binding.subtitle.text = chapter.scanlator
binding.subtitle.isVisible = true
if (!hasSameChapter) {
showScanlatorInBody(moreVisible, item)
hasSameChapter = true
}
}
} }
} else { } else {
chapterId = null chapterId = null
@ -254,6 +276,29 @@ class RecentMangaHolder(
} }
} }
private fun showScanlatorInBody(add: Boolean, originalItem: RecentMangaItem? = null) {
val item = originalItem ?: adapter.getItem(bindingAdapterPosition) as? RecentMangaItem ?: return
val originalText = binding.body.text
binding.body.maxLines = 2
val scanlator = item.chapter.scanlator ?: return
if (add) {
if (isSmallUpdates) {
binding.body.maxLines = 1
binding.body.text = item.chapter.scanlator
binding.body.isVisible = true
} else if (!originalText.contains(scanlator)) {
val text = "$originalText\n$scanlator"
binding.body.text = text
}
} else {
if (isSmallUpdates) {
binding.body.isVisible = false
} else {
binding.body.text = originalText.removeSuffix("\n$scanlator")
}
}
}
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
private fun RecentSubChapterItemBinding.configureView(chapter: Chapter, item: RecentMangaItem) { private fun RecentSubChapterItemBinding.configureView(chapter: Chapter, item: RecentMangaItem) {
val context = itemView.context val context = itemView.context
@ -282,7 +327,7 @@ class RecentMangaHolder(
false false
} }
} }
title.updatePaddingRelative(start = if (isSmallUpdates) 64.dpToPx else 84.dpToPx) textLayout.updatePaddingRelative(start = if (isSmallUpdates) 64.dpToPx else 84.dpToPx)
updateDivider() updateDivider()
root.transitionName = "recents sub chapter ${chapter.id ?: 0L} transition" root.transitionName = "recents sub chapter ${chapter.id ?: 0L} transition"
root.tag = "sub ${chapter.id}" root.tag = "sub ${chapter.id}"

View file

@ -5,8 +5,8 @@
android:id="@+id/download_button" android:id="@+id/download_button"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:layout_width="30dp" android:layout_width="32dp"
android:layout_height="30dp"> android:layout_height="32dp">
<ImageView <ImageView
android:id="@+id/download_border" android:id="@+id/download_border"

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_view" android:id="@+id/main_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -17,11 +18,10 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp"/> android:layout_height="1dp"/>
<com.google.android.material.textview.MaterialTextView <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/title"
style="?textAppearanceTitleMedium"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:orientation="vertical"
android:id="@+id/text_layout"
android:paddingTop="12dp" android:paddingTop="12dp"
android:paddingBottom="12dp" android:paddingBottom="12dp"
android:paddingStart="84dp" android:paddingStart="84dp"
@ -30,19 +30,41 @@
app:layout_constraintEnd_toStartOf="@id/download_button" app:layout_constraintEnd_toStartOf="@id/download_button"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
style="?textAppearanceTitleMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
tools:text="Chapter name"
android:textColor="?attr/colorOnBackground" android:textColor="?attr/colorOnBackground"
app:layout_constraintVertical_chainStyle="packed"/> app:layout_constraintVertical_chainStyle="packed"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/subtitle"
style="?textAppearanceBodySmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Scan name"
android:visibility="gone"
tools:visibility="visible"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintVertical_chainStyle="packed"/>
</androidx.appcompat.widget.LinearLayoutCompat>
<include <include
android:id="@+id/download_button" android:id="@+id/download_button"
layout="@layout/download_button" layout="@layout/download_button"
android:layout_width="45dp" android:layout_width="45dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
app:layout_constraintTop_toTopOf="@id/title" app:layout_constraintTop_toTopOf="@id/text_layout"
app:layout_constraintBottom_toBottomOf="@id/title" app:layout_constraintBottom_toBottomOf="@id/text_layout"
app:layout_constraintStart_toEndOf="@id/title" app:layout_constraintStart_toEndOf="@id/text_layout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>