Tint NavigationRailView

This commit is contained in:
Prathamesh More 2022-06-16 16:43:10 +05:30
parent 17eb5bff05
commit 2f818ce65f
8 changed files with 69 additions and 70 deletions

View file

@ -1,6 +1,9 @@
package code.name.monkey.retromusic.billing
class BillingManager {
import android.content.Context
@Suppress("UNUSED_PARAMETER")
class BillingManager(context: Context) {
fun release() {}

View file

@ -14,9 +14,11 @@
*/
package code.name.monkey.retromusic.extensions
import android.R
import android.animation.Animator
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.content.res.ColorStateList
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
@ -25,6 +27,7 @@ import android.view.ViewTreeObserver
import android.view.animation.AnimationUtils
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.annotation.ColorInt
import androidx.annotation.LayoutRes
import androidx.annotation.Px
import androidx.core.animation.doOnEnd
@ -67,6 +70,15 @@ fun EditText.appHandleColor(): EditText {
return this
}
fun NavigationBarView.setItemColors(@ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val csl = ColorStateList(
arrayOf(intArrayOf(-R.attr.state_checked), intArrayOf(R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)
)
itemIconTintList = csl
itemTextColor = csl
}
/**
* Potentially animate showing a [BottomNavigationView].
*

View file

@ -472,10 +472,10 @@ object PreferenceUtil {
val tabTitleMode: Int
get() {
return when (sharedPreferences.getStringOrDefault(
TAB_TEXT_MODE, "1"
TAB_TEXT_MODE, "0"
).toInt()) {
1 -> BottomNavigationView.LABEL_VISIBILITY_LABELED
0 -> BottomNavigationView.LABEL_VISIBILITY_AUTO
1 -> BottomNavigationView.LABEL_VISIBILITY_LABELED
2 -> BottomNavigationView.LABEL_VISIBILITY_SELECTED
3 -> BottomNavigationView.LABEL_VISIBILITY_UNLABELED
else -> BottomNavigationView.LABEL_VISIBILITY_LABELED

View file

@ -19,14 +19,13 @@ import android.content.res.ColorStateList
import android.util.AttributeSet
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.NavigationViewUtil
import code.name.monkey.retromusic.extensions.addAlpha
import code.name.monkey.retromusic.extensions.setItemColors
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.bottomnavigation.BottomNavigationView
import dev.chrisbanes.insetter.applyInsetter
class BottomNavigationBarTinted @JvmOverloads constructor(
class TintedBottomNavigationView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
@ -55,16 +54,7 @@ class BottomNavigationBarTinted @JvmOverloads constructor(
if (!PreferenceUtil.materialYou) {
val iconColor = ATHUtil.resolveColor(context, android.R.attr.colorControlNormal)
val accentColor = ThemeStore.accentColor(context)
NavigationViewUtil.setItemIconColors(
this,
ColorUtil.withAlpha(iconColor, 0.5f),
accentColor
)
NavigationViewUtil.setItemTextColors(
this,
ColorUtil.withAlpha(iconColor, 0.5f),
accentColor
)
setItemColors(iconColor, accentColor)
itemRippleColor = ColorStateList.valueOf(accentColor.addAlpha(0.08F))
itemActiveIndicatorColor = ColorStateList.valueOf(accentColor.addAlpha(0.12F))
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.views
import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.addAlpha
import code.name.monkey.retromusic.extensions.setItemColors
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.navigationrail.NavigationRailView
class TintedNavigationRailView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : NavigationRailView(context, attrs, defStyleAttr) {
init {
if (!isInEditMode) {
labelVisibilityMode = PreferenceUtil.tabTitleMode
if (!PreferenceUtil.materialYou) {
val iconColor = ATHUtil.resolveColor(context, android.R.attr.colorControlNormal)
val accentColor = context.accentColor()
setItemColors(iconColor, accentColor)
itemRippleColor = ColorStateList.valueOf(accentColor.addAlpha(0.08F))
itemActiveIndicatorColor = ColorStateList.valueOf(accentColor.addAlpha(0.12F))
}
}
}
}

View file

@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.navigationrail.NavigationRailView
<code.name.monkey.retromusic.views.TintedNavigationRailView
android:id="@+id/navigationView"
style="@style/Widget.Material3.NavigationRailView"
android:layout_width="wrap_content"

View file

@ -42,7 +42,7 @@
</FrameLayout>
<code.name.monkey.retromusic.views.BottomNavigationBarTinted
<code.name.monkey.retromusic.views.TintedBottomNavigationView
android:id="@+id/navigationView"
style="@style/Widget.Material3.BottomNavigationView"
android:layout_width="match_parent"

View file

@ -1,52 +0,0 @@
package code.name.monkey.appthemehelper.util
import android.content.res.ColorStateList
import androidx.annotation.ColorInt
import code.name.monkey.appthemehelper.ThemeStore
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.navigation.NavigationView
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object NavigationViewUtil {
fun setItemIconColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val iconSl = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
), intArrayOf(normalColor, selectedColor)
)
navigationView.itemIconTintList = iconSl
val drawable = navigationView.itemBackground
navigationView.itemBackground = TintHelper.createTintedDrawable(
drawable,
ColorUtil.withAlpha(ThemeStore.accentColor(navigationView.context), 0.2f)
)
}
fun setItemTextColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val textSl = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)
)
navigationView.itemTextColor = textSl
}
fun setItemIconColors(bottomNavigationView: BottomNavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val iconSl = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)
)
bottomNavigationView.itemIconTintList = iconSl
}
fun setItemTextColors(bottomNavigationView: BottomNavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) {
val textSl = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)),
intArrayOf(normalColor, selectedColor)
)
bottomNavigationView.itemTextColor = textSl
}
}