mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 07:15:08 +01:00
Created setTextColorRes Extension method
This commit is contained in:
parent
1c51a4c499
commit
ad2e14bf1a
@ -8,6 +8,7 @@ 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.view.gone
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
import eu.kanade.tachiyomi.util.view.isVisible
|
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.updatePaddingRelative
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
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.*
|
||||||
@ -24,15 +25,17 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
|
|||||||
|
|
||||||
with(unread_text) {
|
with(unread_text) {
|
||||||
visibleIf(unread > 0 || unread == -1 || showTotalChapters)
|
visibleIf(unread > 0 || unread == -1 || showTotalChapters)
|
||||||
if (!isVisible()) { return@with }
|
if (!isVisible()) {
|
||||||
|
return@with
|
||||||
|
}
|
||||||
text = if (unread == -1) "0" else unread.toString()
|
text = if (unread == -1) "0" else unread.toString()
|
||||||
setTextColor(
|
setTextColorRes(
|
||||||
context.contextCompatColor(
|
|
||||||
// hide the badge text when preference is only show badge
|
// hide the badge text when preference is only show badge
|
||||||
if (unread == -1 && !showTotalChapters) R.color.unread_badge
|
when {
|
||||||
else if (showTotalChapters) R.color.total_badge_text
|
unread == -1 && !showTotalChapters -> R.color.unread_badge
|
||||||
else R.color.unread_badge_text
|
showTotalChapters -> R.color.total_badge_text
|
||||||
)
|
else -> R.color.unread_badge_text
|
||||||
|
}
|
||||||
)
|
)
|
||||||
setBackgroundColor(unreadBadgeBackground)
|
setBackgroundColor(unreadBadgeBackground)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import android.widget.Button
|
|||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
import androidx.annotation.Px
|
import androidx.annotation.Px
|
||||||
import androidx.appcompat.view.menu.MenuBuilder
|
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.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||||
|
import eu.kanade.tachiyomi.util.system.contextCompatColor
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
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")
|
@SuppressLint("RestrictedApi")
|
||||||
fun BottomNavigationView.getItemView(@IdRes id: Int): BottomNavigationItemView? {
|
fun BottomNavigationView.getItemView(@IdRes id: Int): BottomNavigationItemView? {
|
||||||
val order = (menu as MenuBuilder).findItemIndex(id)
|
val order = (menu as MenuBuilder).findItemIndex(id)
|
||||||
|
Loading…
Reference in New Issue
Block a user