Created setTextColorRes Extension method

This commit is contained in:
Jay 2020-04-25 18:18:13 -04:00
parent 1c51a4c499
commit ad2e14bf1a
2 changed files with 17 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.util.system.contextCompatColor
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.isVisible
import eu.kanade.tachiyomi.util.view.setTextColorRes
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.unread_download_badge.view.*
@ -24,15 +25,17 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
with(unread_text) {
visibleIf(unread > 0 || unread == -1 || showTotalChapters)
if (!isVisible()) { return@with }
if (!isVisible()) {
return@with
}
text = if (unread == -1) "0" else unread.toString()
setTextColor(
context.contextCompatColor(
setTextColorRes(
// hide the badge text when preference is only show badge
if (unread == -1 && !showTotalChapters) R.color.unread_badge
else if (showTotalChapters) R.color.total_badge_text
else R.color.unread_badge_text
)
when {
unread == -1 && !showTotalChapters -> R.color.unread_badge
showTotalChapters -> R.color.total_badge_text
else -> R.color.unread_badge_text
}
)
setBackgroundColor(unreadBadgeBackground)
}

View File

@ -18,6 +18,7 @@ import android.widget.Button
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorRes
import androidx.annotation.IdRes
import androidx.annotation.Px
import androidx.appcompat.view.menu.MenuBuilder
@ -34,6 +35,7 @@ import com.google.android.material.snackbar.Snackbar
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.contextCompatColor
import eu.kanade.tachiyomi.util.system.getResourceColor
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -330,6 +332,10 @@ fun MaterialButton.resetStrokeColor() {
)
}
fun TextView.setTextColorRes(@ColorRes id: Int) {
setTextColor(context.contextCompatColor(id))
}
@SuppressLint("RestrictedApi")
fun BottomNavigationView.getItemView(@IdRes id: Int): BottomNavigationItemView? {
val order = (menu as MenuBuilder).findItemIndex(id)