add some ContextExtensions to wrap ContextCompat.getDrawable and ContextCompat.getColor

This commit is contained in:
CarlosEsco 2020-04-22 12:57:03 -04:00
parent ca633b1f95
commit c035745b94
2 changed files with 24 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import com.mikepenz.fastadapter.items.AbstractItem
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.util.system.contextCompatDrawable
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.DecimalFormatSymbols 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 unreadColor = view.context.getResourceColor(android.R.attr.textColorPrimary)
private var activeColor = view.context.getResourceColor(android.R.attr.colorAccent) private var activeColor = view.context.getResourceColor(android.R.attr.colorAccent)
private var unbookmark = ContextCompat.getDrawable(view.context, R.drawable private var unbookmark = view.context.contextCompatDrawable(R.drawable.ic_bookmark_border_24dp)
.ic_bookmark_border_24dp) private var bookmark = view.context.contextCompatDrawable(R.drawable.ic_bookmark_24dp)
private var bookmark = ContextCompat.getDrawable(view.context, R.drawable
.ic_bookmark_24dp)
override fun bindView(item: ReaderChapterItem, payloads: List<Any>) { override fun bindView(item: ReaderChapterItem, payloads: List<Any>) {
val chapter = item.chapter val chapter = item.chapter

View File

@ -9,11 +9,14 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Resources import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.Uri import android.net.Uri
import android.os.PowerManager import android.os.PowerManager
import android.widget.Toast import android.widget.Toast
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
@ -89,6 +92,24 @@ fun Context.getResourceColor(@AttrRes resource: Int): Int {
return attrValue 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. * Converts to dp.
*/ */