mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 01:19:18 +01:00
Remove usage of alpha color selectors (fixes #2957)
Doesn't work properly in API < 23
This commit is contained in:
parent
b25ab941ba
commit
0a509cb382
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.manga.chapter
|
package eu.kanade.tachiyomi.ui.manga.chapter
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
@ -21,7 +20,7 @@ class ChaptersAdapter(
|
|||||||
|
|
||||||
var items: List<ChapterItem> = emptyList()
|
var items: List<ChapterItem> = emptyList()
|
||||||
|
|
||||||
val readColor = ContextCompat.getColor(context, R.color.material_on_surface_disabled)
|
val readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f)
|
||||||
val unreadColor = context.getResourceColor(R.attr.colorOnSurface)
|
val unreadColor = context.getResourceColor(R.attr.colorOnSurface)
|
||||||
|
|
||||||
val bookmarkedColor = context.getResourceColor(R.attr.colorAccent)
|
val bookmarkedColor = context.getResourceColor(R.attr.colorAccent)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recent.updates
|
package eu.kanade.tachiyomi.ui.recent.updates
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
@ -27,7 +26,7 @@ import kotlinx.android.synthetic.main.updates_item.manga_title
|
|||||||
class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) :
|
class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) :
|
||||||
BaseFlexibleViewHolder(view, adapter) {
|
BaseFlexibleViewHolder(view, adapter) {
|
||||||
|
|
||||||
private var readColor = ContextCompat.getColor(view.context, R.color.material_on_surface_disabled)
|
private var readColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f)
|
||||||
private var unreadColor = view.context.getResourceColor(R.attr.colorOnSurface)
|
private var unreadColor = view.context.getResourceColor(R.attr.colorOnSurface)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.source.browse
|
package eu.kanade.tachiyomi.ui.source.browse
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
@ -23,7 +22,7 @@ import kotlinx.android.synthetic.main.source_list_item.title
|
|||||||
class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
|
class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
|
||||||
SourceHolder(view, adapter) {
|
SourceHolder(view, adapter) {
|
||||||
|
|
||||||
private val favoriteColor = ContextCompat.getColor(view.context, R.color.material_on_surface_disabled)
|
private val favoriteColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f)
|
||||||
private val unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface)
|
private val unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.source.filter
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.CheckedTextView
|
import android.widget.CheckedTextView
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
||||||
import com.google.android.material.R
|
import com.google.android.material.R
|
||||||
@ -46,7 +45,7 @@ open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem<TriS
|
|||||||
val color = if (filter.state == Filter.TriState.STATE_INCLUDE) {
|
val color = if (filter.state == Filter.TriState.STATE_INCLUDE) {
|
||||||
view.context.getResourceColor(R.attr.colorAccent)
|
view.context.getResourceColor(R.attr.colorAccent)
|
||||||
} else {
|
} else {
|
||||||
ContextCompat.getColor(view.context, R.color.material_on_background_disabled)
|
view.context.getResourceColor(R.attr.colorOnBackground, 0.38f)
|
||||||
}
|
}
|
||||||
|
|
||||||
setTint(color)
|
setTint(color)
|
||||||
|
@ -9,11 +9,13 @@ 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.Color
|
||||||
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.ColorInt
|
||||||
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
|
||||||
@ -22,6 +24,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
|||||||
import com.nononsenseapps.filepicker.FilePickerActivity
|
import com.nononsenseapps.filepicker.FilePickerActivity
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity
|
import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a toast in this context.
|
* Display a toast in this context.
|
||||||
@ -96,12 +99,22 @@ fun Context.hasPermission(permission: String) = ContextCompat.checkSelfPermissio
|
|||||||
* Returns the color for the given attribute.
|
* Returns the color for the given attribute.
|
||||||
*
|
*
|
||||||
* @param resource the attribute.
|
* @param resource the attribute.
|
||||||
|
* @param alphaFactor the alpha number [0,1].
|
||||||
*/
|
*/
|
||||||
fun Context.getResourceColor(@AttrRes resource: Int): Int {
|
@ColorInt fun Context.getResourceColor(@AttrRes resource: Int, alphaFactor: Float = 1f): Int {
|
||||||
val typedArray = obtainStyledAttributes(intArrayOf(resource))
|
val typedArray = obtainStyledAttributes(intArrayOf(resource))
|
||||||
val attrValue = typedArray.getColor(0, 0)
|
val color = typedArray.getColor(0, 0)
|
||||||
typedArray.recycle()
|
typedArray.recycle()
|
||||||
return attrValue
|
|
||||||
|
if (alphaFactor < 1f) {
|
||||||
|
val alpha = (Color.alpha(color) * alphaFactor).roundToInt()
|
||||||
|
val red = Color.red(color)
|
||||||
|
val green = Color.green(color)
|
||||||
|
val blue = Color.blue(color)
|
||||||
|
return Color.argb(alpha, red, green, blue)
|
||||||
|
}
|
||||||
|
|
||||||
|
return color
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,11 +4,11 @@ import android.graphics.drawable.Drawable
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.ImageView.ScaleType
|
import android.widget.ImageView.ScaleType
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
||||||
import com.bumptech.glide.request.target.ImageViewTarget
|
import com.bumptech.glide.request.target.ImageViewTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
import eu.kanade.tachiyomi.util.view.visible
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class StateImageViewTarget(
|
|||||||
view.scaleType = errorScaleType
|
view.scaleType = errorScaleType
|
||||||
|
|
||||||
val vector = VectorDrawableCompat.create(view.context.resources, errorDrawableRes, null)
|
val vector = VectorDrawableCompat.create(view.context.resources, errorDrawableRes, null)
|
||||||
vector?.setTint(ContextCompat.getColor(view.context, com.google.android.material.R.color.material_on_background_disabled))
|
vector?.setTint(view.context.getResourceColor(R.attr.colorOnBackground, 0.38f))
|
||||||
view.setImageDrawable(vector)
|
view.setImageDrawable(vector)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user