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

View File

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

View File

@ -97,6 +97,14 @@ inline fun 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) {
visibility = if (show) View.VISIBLE else View.GONE
}

View File

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

View File

@ -21,12 +21,12 @@
style="@style/TextAppearance.Regular.Caption.Light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/pale_green"
android:background="@color/download_badge"
android:gravity="center"
android:maxLines="1"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:textColor="@color/md_black_1000"
android:textColor="@color/download_badge_text"
android:textSize="13sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
@ -44,19 +44,20 @@
android:src="@drawable/unread_angled_badge"
app:layout_constraintBottom_toBottomOf="@+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
android:id="@+id/unread_text"
style="@style/TextAppearance.Regular.Caption.Light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:background="@color/unread_badge"
android:gravity="center"
android:maxLines="1"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:textColor="@color/md_white_1000"
android:textColor="@color/unread_badge_text"
android:textSize="13sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/download_text"

View File

@ -16,6 +16,14 @@
<color name="actionModeShadow">@color/md_black_1000_38</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="textColorPrimary">@color/md_black_1000_87</color>