LibraryBadge clean up (#209)

* adjust badge colors to use color properties specific to badges
clean up library badge with existing and new view extensions

* fix line that should have been deleted in tracksearch
This commit is contained in:
Carlos 2020-04-23 21:02:44 -04:00 committed by GitHub
parent 5e5ab8df6b
commit d4449c1d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 36 deletions

View File

@ -1,15 +1,17 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.content.Context import android.content.Context
import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.core.content.ContextCompat
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.contextCompatColor
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.isNotGone
import eu.kanade.tachiyomi.util.view.isVisible
import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.unread_download_badge.view.* import kotlinx.android.synthetic.main.unread_download_badge.view.*
class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
@ -17,39 +19,43 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
fun setUnreadDownload(unread: Int, downloads: Int, showTotalChapters: Boolean) { fun setUnreadDownload(unread: Int, downloads: Int, showTotalChapters: Boolean) {
// Update the unread count and its visibility. // Update the unread count and its visibility.
val unreadBadgeBackground = when (showTotalChapters) {
true -> context.contextCompatColor(R.color.total_badge)
false -> context.contextCompatColor(R.color.unread_badge)
}
with(unread_text) { with(unread_text) {
visibleIf(unread > 0 || unread == -1 || showTotalChapters)
text = if (unread == -1) "0" else unread.toString() text = if (unread == -1) "0" else unread.toString()
setTextColor(if (unread == -1 && !showTotalChapters) setTextColor(
context.getResourceColor(android.R.attr.colorAccent) when (unread == -1 && !showTotalChapters) {
else Color.WHITE) true -> context.contextCompatColor(R.color.unread_badge) // hide the 0 in the badge
setBackgroundColor( false -> context.contextCompatColor(R.color.unread_badge_text)
if (showTotalChapters) ContextCompat.getColor(context, R.color.material_deep_purple_500) }
else context.getResourceColor(android.R.attr.colorAccent)) )
visibility = when { setBackgroundColor(unreadBadgeBackground)
unread > 0 || unread == -1 || showTotalChapters -> View.VISIBLE
else -> View.GONE
}
} }
// Update the download count or local status and its visibility. // Update the download count or local status and its visibility.
with(download_text) { with(download_text) {
visibility = if (downloads == -2 || downloads > 0) View.VISIBLE else View.GONE visibleIf(downloads == -2 || downloads > 0)
text = if (downloads == -2) text = if (downloads == -2) {
resources.getString(R.string.local) resources.getString(R.string.local)
else downloads.toString() } else {
downloads.toString()
}
} }
// Show the bade card if unread or downloads exists // Show the badge card if unread or downloads exists
visibility = if (download_text.visibility == View.VISIBLE || unread_text this.visibleIf(download_text.isVisible() || unread_text.isNotGone())
.visibility != View.GONE) View.VISIBLE else View.GONE
// Show the angles divider if both unread and downloads exists // Show the angles divider if both unread and downloads exists
unread_angle.visibility = if (download_text.visibility == View.VISIBLE && unread_text unread_angle.visibleIf(download_text.isVisible() && unread_text.isNotGone())
.visibility != View.GONE) View.VISIBLE else View.GONE
unread_angle.setColorFilter( unread_angle.setColorFilter(unreadBadgeBackground)
if (showTotalChapters) ContextCompat.getColor(context, R.color.material_deep_purple_500) if (unread_angle.isVisible()) {
else context.getResourceColor(android.R.attr.colorAccent))
if (unread_angle.visibility == View.VISIBLE) {
download_text.updatePaddingRelative(end = 8.dpToPx) download_text.updatePaddingRelative(end = 8.dpToPx)
unread_text.updatePaddingRelative(start = 2.dpToPx) unread_text.updatePaddingRelative(start = 2.dpToPx)
} else { } else {
@ -63,10 +69,10 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
} }
fun setInLibrary(inLibrary: Boolean) { fun setInLibrary(inLibrary: Boolean) {
visibility = if (inLibrary) View.VISIBLE else View.GONE this.visibleIf(inLibrary)
unread_angle.visibility = View.GONE unread_angle.gone()
unread_text.updatePaddingRelative(start = 5.dpToPx) unread_text.updatePaddingRelative(start = 5.dpToPx)
unread_text.visibility = if (inLibrary) View.VISIBLE else View.GONE unread_text.visibleIf(inLibrary)
unread_text.text = resources.getText(R.string.in_library) unread_text.text = resources.getText(R.string.in_library)
} }
} }

View File

@ -61,7 +61,6 @@ class TrackSearchDialog : DialogController {
val dialog = MaterialDialog(activity!!).apply { val dialog = MaterialDialog(activity!!).apply {
customView(viewRes = R.layout.track_search_dialog, scrollable = false) customView(viewRes = R.layout.track_search_dialog, scrollable = false)
negativeButton(android.R.string.cancel) negativeButton(android.R.string.cancel)
positiveButton(R.string.clear) { onPositiveButtonClick() }
if (wasPreviouslyTracked) { if (wasPreviouslyTracked) {
positiveButton(R.string.clear) { onPositiveButtonClick() } positiveButton(R.string.clear) { onPositiveButtonClick() }
} }

View File

@ -97,6 +97,14 @@ inline fun View.gone() {
visibility = View.GONE visibility = View.GONE
} }
inline fun View.isVisible(): Boolean {
return visibility == View.VISIBLE
}
inline fun View.isNotGone(): Boolean {
return visibility != View.GONE
}
inline fun View.visibleIf(show: Boolean) { inline fun View.visibleIf(show: Boolean) {
visibility = if (show) View.VISIBLE else View.GONE visibility = if (show) View.VISIBLE else View.GONE
} }

View File

@ -8,8 +8,8 @@
tools:background="@color/red_error"> tools:background="@color/red_error">
<path <path
android:fillColor="@color/colorAccent" android:fillColor="@color/unread_badge"
android:pathData="M0 20 L100 0 L100 20 Z" android:pathData="M0 20 L100 0 L100 20 Z"
android:strokeColor="@color/colorAccent" /> android:strokeColor="@color/unread_badge" />
</vector> </vector>

View File

@ -21,12 +21,12 @@
style="@style/TextAppearance.Regular.Caption.Light" style="@style/TextAppearance.Regular.Caption.Light"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/pale_green" android:background="@color/download_badge"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:textColor="@color/md_black_1000" android:textColor="@color/download_badge_text"
android:textSize="13sp" android:textSize="13sp"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
@ -44,19 +44,20 @@
android:src="@drawable/unread_angled_badge" android:src="@drawable/unread_angled_badge"
app:layout_constraintBottom_toBottomOf="@+id/unread_text" app:layout_constraintBottom_toBottomOf="@+id/unread_text"
app:layout_constraintEnd_toStartOf="@id/unread_text" app:layout_constraintEnd_toStartOf="@id/unread_text"
app:layout_constraintTop_toTopOf="@+id/unread_text" /> app:layout_constraintTop_toTopOf="@+id/unread_text"
tools:ignore="ContentDescription" />
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/unread_text" android:id="@+id/unread_text"
style="@style/TextAppearance.Regular.Caption.Light" style="@style/TextAppearance.Regular.Caption.Light"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorAccent" android:background="@color/unread_badge"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:textColor="@color/md_white_1000" android:textColor="@color/unread_badge_text"
android:textSize="13sp" android:textSize="13sp"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/download_text" app:layout_constraintBottom_toBottomOf="@+id/download_text"

View File

@ -16,6 +16,14 @@
<color name="actionModeShadow">@color/md_black_1000_38</color> <color name="actionModeShadow">@color/md_black_1000_38</color>
<color name="gray_button">#404040</color> <color name="gray_button">#404040</color>
<color name="unread_badge">@color/colorAccent</color>
<color name="unread_badge_text">@color/md_white_1000</color>
<color name="download_badge">@color/pale_green</color>
<color name="download_badge_text">@color/md_black_1000</color>
<color name="total_badge">@color/material_deep_purple_500</color>
<color name="total_badge_text">@color/md_white_1000</color>
<color name="colorAmoledPrimary">@color/md_black_1000</color> <color name="colorAmoledPrimary">@color/md_black_1000</color>
<color name="textColorPrimary">@color/md_black_1000_87</color> <color name="textColorPrimary">@color/md_black_1000_87</color>