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. 20
      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.ViewTreeObserver
import androidx.annotation.ColorInt
import io.legado.app.utils.DrawableUtils
/**
* @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.help.AppConfig
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.model.Download
import io.legado.app.ui.association.OnLineImportActivity
@ -218,7 +217,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
starMenuItem?.setIcon(R.drawable.ic_star_border)
starMenuItem?.setTitle(R.string.out_favorites)
}
DrawableUtils.setTint(starMenuItem?.icon, primaryTextColor)
starMenuItem?.icon?.setTint(primaryTextColor)
}
override fun upTtsMenu(isPlaying: Boolean) {
@ -230,7 +229,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
ttsMenuItem?.setIcon(R.drawable.ic_volume_up)
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.graphics.PorterDuff
@ -30,30 +30,24 @@ object DrawableUtils {
return TransitionDrawable(drawables)
}
fun setTintList(
drawable: Drawable?,
}
fun Drawable.setTintList(
tint: ColorStateList,
tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP
) {
drawable?.let {
val wrappedDrawable = DrawableCompat.wrap(it)
val wrappedDrawable = DrawableCompat.wrap(this)
wrappedDrawable.mutate()
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTintList(wrappedDrawable, tint)
}
}
fun setTint(
drawable: Drawable?,
fun Drawable.setTint(
@ColorInt tint: Int,
tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP
) {
drawable?.let {
val wrappedDrawable = DrawableCompat.wrap(it)
val wrappedDrawable = DrawableCompat.wrap(this)
wrappedDrawable.mutate()
DrawableCompat.setTintMode(wrappedDrawable, tintMode)
DrawableCompat.setTint(wrappedDrawable, tint)
}
}
}

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

Loading…
Cancel
Save