From c035745b94b6db037e04f0911fe06b1be4d14b7a Mon Sep 17 00:00:00 2001 From: CarlosEsco Date: Wed, 22 Apr 2020 12:57:03 -0400 Subject: [PATCH] add some ContextExtensions to wrap ContextCompat.getDrawable and ContextCompat.getColor --- .../tachiyomi/ui/reader/ReaderChapterItem.kt | 7 +++---- .../util/system/ContextExtensions.kt | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt index 567bd3475d..338c1c441a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterItem.kt @@ -13,6 +13,7 @@ import com.mikepenz.fastadapter.items.AbstractItem import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.util.system.contextCompatDrawable import eu.kanade.tachiyomi.util.system.getResourceColor import java.text.DecimalFormat import java.text.DecimalFormatSymbols @@ -53,10 +54,8 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B private var unreadColor = view.context.getResourceColor(android.R.attr.textColorPrimary) private var activeColor = view.context.getResourceColor(android.R.attr.colorAccent) - private var unbookmark = ContextCompat.getDrawable(view.context, R.drawable - .ic_bookmark_border_24dp) - private var bookmark = ContextCompat.getDrawable(view.context, R.drawable - .ic_bookmark_24dp) + private var unbookmark = view.context.contextCompatDrawable(R.drawable.ic_bookmark_border_24dp) + private var bookmark = view.context.contextCompatDrawable(R.drawable.ic_bookmark_24dp) override fun bindView(item: ReaderChapterItem, payloads: List) { val chapter = item.chapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 727f0d6f06..33f6eb8f60 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -9,11 +9,14 @@ import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager import android.content.res.Resources +import android.graphics.drawable.Drawable import android.net.ConnectivityManager import android.net.Uri import android.os.PowerManager import android.widget.Toast import androidx.annotation.AttrRes +import androidx.annotation.ColorRes +import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.browser.customtabs.CustomTabsIntent import androidx.core.app.NotificationCompat @@ -89,6 +92,24 @@ fun Context.getResourceColor(@AttrRes resource: Int): Int { return attrValue } +/** + * Returns the color from ContextCompat + * + * @param resource the color. + */ +fun Context.contextCompatColor(@ColorRes resource: Int): Int { + return ContextCompat.getColor(this, resource) +} + +/** + * Returns the color from ContextCompat + * + * @param resource the color. + */ +fun Context.contextCompatDrawable(@DrawableRes resource: Int): Drawable? { + return ContextCompat.getDrawable(this, resource) +} + /** * Converts to dp. */