pull/1391/head
gedoor 3 years ago
parent 4da829864f
commit c2bc2ae34d
  1. 1
      app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt
  2. 5
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  3. 0
      app/src/main/java/io/legado/app/utils/DocumentExtensions.kt
  4. 44
      app/src/main/java/io/legado/app/utils/DrawableUtils.kt
  5. 12
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt

@ -6,6 +6,7 @@ import android.graphics.drawable.TransitionDrawable
import android.view.View import android.view.View
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import io.legado.app.utils.DrawableUtils
/** /**
* @author Karim Abou Zeid (kabouzeid) * @author Karim Abou Zeid (kabouzeid)

@ -16,7 +16,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityRssReadBinding import io.legado.app.databinding.ActivityRssReadBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.model.Download import io.legado.app.model.Download
import io.legado.app.ui.association.OnLineImportActivity import io.legado.app.ui.association.OnLineImportActivity
@ -218,7 +217,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
starMenuItem?.setIcon(R.drawable.ic_star_border) starMenuItem?.setIcon(R.drawable.ic_star_border)
starMenuItem?.setTitle(R.string.out_favorites) starMenuItem?.setTitle(R.string.out_favorites)
} }
DrawableUtils.setTint(starMenuItem?.icon, primaryTextColor) starMenuItem?.icon?.setTint(primaryTextColor)
} }
override fun upTtsMenu(isPlaying: Boolean) { override fun upTtsMenu(isPlaying: Boolean) {
@ -230,7 +229,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
ttsMenuItem?.setIcon(R.drawable.ic_volume_up) ttsMenuItem?.setIcon(R.drawable.ic_volume_up)
ttsMenuItem?.setTitle(R.string.read_aloud) ttsMenuItem?.setTitle(R.string.read_aloud)
} }
DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) ttsMenuItem?.icon?.setTint(primaryTextColor)
} }
} }

@ -1,4 +1,4 @@
package io.legado.app.lib.theme package io.legado.app.utils
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.PorterDuff import android.graphics.PorterDuff
@ -30,30 +30,24 @@ object DrawableUtils {
return TransitionDrawable(drawables) return TransitionDrawable(drawables)
} }
fun setTintList( }
drawable: Drawable?,
tint: ColorStateList,
tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP
) {
drawable?.let {
val wrappedDrawable = DrawableCompat.wrap(it)
wrappedDrawable.mutate()
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTintList(wrappedDrawable, tint)
}
}
fun Drawable.setTintList(
tint: ColorStateList,
tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP
) {
val wrappedDrawable = DrawableCompat.wrap(this)
wrappedDrawable.mutate()
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTintList(wrappedDrawable, tint)
}
fun setTint( fun Drawable.setTint(
drawable: Drawable?, @ColorInt tint: Int,
@ColorInt tint: Int, tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP
tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP ) {
) { val wrappedDrawable = DrawableCompat.wrap(this)
drawable?.let { wrappedDrawable.mutate()
val wrappedDrawable = DrawableCompat.wrap(it) DrawableCompat.setTintMode(wrappedDrawable, tintMode)
wrappedDrawable.mutate() DrawableCompat.setTint(wrappedDrawable, tint)
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTint(wrappedDrawable, tint)
}
}
} }

@ -9,7 +9,6 @@ import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.view.forEach import androidx.core.view.forEach
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.lib.theme.DrawableUtils
import java.lang.reflect.Method import java.lang.reflect.Method
import java.util.* import java.util.*
@ -23,10 +22,8 @@ fun Menu.applyTint(context: Context, theme: Theme = Theme.Auto): Menu = this.let
menu.forEach { item -> menu.forEach { item ->
(item as MenuItemImpl).let { impl -> (item as MenuItemImpl).let { impl ->
//overflow:展开的item //overflow:展开的item
DrawableUtils.setTint( impl.icon.setTint(
impl.icon, if (impl.requiresOverflow()) defaultTextColor else tintColor
if (impl.requiresOverflow()) defaultTextColor
else tintColor
) )
} }
} }
@ -47,10 +44,7 @@ fun Menu.applyOpenTint(context: Context) {
if (menuItems is ArrayList<*>) { if (menuItems is ArrayList<*>) {
for (menuItem in menuItems) { for (menuItem in menuItems) {
if (menuItem is MenuItem) { if (menuItem is MenuItem) {
DrawableUtils.setTint( menuItem.icon.setTint(defaultTextColor)
menuItem.icon,
defaultTextColor
)
} }
} }
} }

Loading…
Cancel
Save