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)
set(value) {
field = value
activeColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.background),
0.05f,
)
downloadedColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.colorOnBackground),
0.3f,
)
activeColor = colorSecondary
downloadedColor = colorSecondary
}
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 var activeColor = colorSecondary
set(value) {
ColorUtils.blendARGB(value, context.getResourceColor(R.attr.background), 0.05f)
}
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 val downloadedTextColor = context.getResourceColor(R.attr.background)
private val errorColor = ContextCompat.getColor(
context,
R.color.material_red_500,
)
private val filledCircle = ContextCompat.getDrawable(
context,
R.drawable.filled_circle,
)?.mutate()
private val borderCircle = ContextCompat.getDrawable(
context,
R.drawable.border_circle,
)?.mutate()
private val downloadDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_arrow_downward_24dp,
)?.mutate()
private val checkDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_check_24dp,
)?.mutate()
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 val errorColor by lazy {
ContextCompat.getColor(context, R.color.material_red_500)
}
private val filledCircle by lazy {
ContextCompat.getDrawable(context, R.drawable.filled_circle)?.mutate()
}
private val borderCircle by lazy {
ContextCompat.getDrawable(context, R.drawable.border_circle)?.mutate()
}
private val downloadDrawable by lazy {
ContextCompat.getDrawable(context, R.drawable.ic_arrow_downward_24dp)?.mutate()
}
private val checkDrawable by lazy {
ContextCompat.getDrawable(context, R.drawable.ic_check_24dp)?.mutate()
}
private val filledAnim by lazy {
AnimatedVectorDrawableCompat.create(context, R.drawable.anim_outline_to_filled)
}
private val checkAnim by lazy {
AnimatedVectorDrawableCompat.create(context, R.drawable.anim_dl_to_check_to_dl)
}
private var isAnimating = false
private var iconAnimation: ObjectAnimator? = null

View file

@ -59,12 +59,15 @@ class RecentMangaHolder(
)
if (moreVisible) {
binding.moreChaptersLayout.children.forEach { view ->
try {
RecentSubChapterItemBinding.bind(view).updateDivider()
} catch (_: Exception) {
}
RecentSubChapterItemBinding.bind(view).updateDivider()
}
}
if (binding.moreChaptersLayout.children.any { view ->
!RecentSubChapterItemBinding.bind(view).subtitle.text.isNullOrBlank()
}
) {
showScanlatorInBody(moreVisible)
}
binding.endView.updateLayoutParams<ViewGroup.LayoutParams> {
height = binding.mainView.height
}
@ -223,15 +226,34 @@ class RecentMangaHolder(
RecentSubChapterItemBinding.bind(binding.moreChaptersLayout.getChildAt(index))
.configureView(chapter, item)
}
if (binding.moreChaptersLayout.children.any { view ->
!RecentSubChapterItemBinding.bind(view).subtitle.text.isNullOrBlank()
}
) {
showScanlatorInBody(moreVisible, item)
}
} else {
binding.moreChaptersLayout.removeAllViews()
var hasSameChapter = false
if (item.mch.extraChapters.isNotEmpty()) {
item.mch.extraChapters.forEach { chapter ->
RecentSubChapterItemBinding.inflate(
val binding = RecentSubChapterItemBinding.inflate(
LayoutInflater.from(context),
binding.moreChaptersLayout,
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 {
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")
private fun RecentSubChapterItemBinding.configureView(chapter: Chapter, item: RecentMangaItem) {
val context = itemView.context
@ -282,7 +327,7 @@ class RecentMangaHolder(
false
}
}
title.updatePaddingRelative(start = if (isSmallUpdates) 64.dpToPx else 84.dpToPx)
textLayout.updatePaddingRelative(start = if (isSmallUpdates) 64.dpToPx else 84.dpToPx)
updateDivider()
root.transitionName = "recents sub chapter ${chapter.id ?: 0L} transition"
root.tag = "sub ${chapter.id}"

View file

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

View file

@ -1,6 +1,7 @@
<?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:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -17,11 +18,10 @@
android:layout_width="0dp"
android:layout_height="1dp"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
style="?textAppearanceTitleMedium"
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/text_layout"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingStart="84dp"
@ -30,19 +30,41 @@
app:layout_constraintEnd_toStartOf="@id/download_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?attr/colorOnBackground"
app:layout_constraintVertical_chainStyle="packed"/>
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:maxLines="1"
tools:text="Chapter name"
android:textColor="?attr/colorOnBackground"
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
android:id="@+id/download_button"
layout="@layout/download_button"
android:layout_width="45dp"
android:layout_marginEnd="8dp"
app:layout_constraintTop_toTopOf="@id/title"
app:layout_constraintBottom_toBottomOf="@id/title"
app:layout_constraintStart_toEndOf="@id/title"
app:layout_constraintTop_toTopOf="@id/text_layout"
app:layout_constraintBottom_toBottomOf="@id/text_layout"
app:layout_constraintStart_toEndOf="@id/text_layout"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content" />
</androidx.constraintlayout.widget.ConstraintLayout>