PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/views/BottomNavigationBarTinted.kt

61 lines
2.3 KiB
Kotlin
Raw Normal View History

2019-03-03 09:29:03 +00:00
/*
* 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.
*/
2019-03-03 09:20:15 +00:00
package code.name.monkey.retromusic.views
import android.content.Context
2019-11-21 05:59:33 +00:00
import android.content.res.ColorStateList
2019-12-06 17:13:09 +00:00
import android.graphics.drawable.ColorDrawable
2019-03-03 09:20:15 +00:00
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.R
2020-06-06 18:57:28 +00:00
import code.name.monkey.retromusic.util.PreferenceUtil
2019-03-03 09:20:15 +00:00
import com.google.android.material.bottomnavigation.BottomNavigationView
2019-08-02 13:08:47 +00:00
class BottomNavigationBarTinted @JvmOverloads constructor(
2020-01-09 20:53:18 +00:00
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
2019-08-02 13:08:47 +00:00
) : BottomNavigationView(context, attrs, defStyleAttr) {
2019-03-03 09:20:15 +00:00
init {
2020-06-06 18:57:28 +00:00
labelVisibilityMode = PreferenceUtil.tabTitleMode
2019-03-03 09:20:15 +00:00
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
)
itemRippleColor = ColorStateList.valueOf(accentColor.addAlpha(0.08F))
background = ColorDrawable(ATHUtil.resolveColor(context, R.attr.bottomSheetTint))
itemActiveIndicatorColor = ColorStateList.valueOf(accentColor.addAlpha(0.12F))
}
2019-03-03 09:20:15 +00:00
}
2019-11-21 05:59:33 +00:00
}
fun Int.addAlpha(alpha: Float): Int {
return ColorUtil.withAlpha(this, alpha)
2019-11-21 05:59:33 +00:00
}