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

56 lines
2.6 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-11-21 05:59:33 +00:00
import android.graphics.drawable.RippleDrawable
2019-03-03 09:20:15 +00:00
import android.util.AttributeSet
2019-11-21 05:59:33 +00:00
import androidx.core.content.ContextCompat
2019-03-03 09:20:15 +00:00
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
import code.name.monkey.retromusic.util.PreferenceUtil
2019-11-21 05:59:33 +00:00
import code.name.monkey.retromusic.util.RippleUtils
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(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : BottomNavigationView(context, attrs, defStyleAttr) {
2019-03-03 09:20:15 +00:00
init {
labelVisibilityMode = PreferenceUtil.getInstance(context).tabTitleMode
selectedItemId = PreferenceUtil.getInstance(context).lastPage
2019-03-03 09:20:15 +00:00
2019-12-01 15:27:01 +00:00
val iconColor = ATHUtil.resolveColor(context, android.R.attr.colorControlNormal)
2019-03-03 09:20:15 +00:00
val accentColor = ThemeStore.accentColor(context)
NavigationViewUtil.setItemIconColors(this, ColorUtil.withAlpha(iconColor, 0.5f), accentColor)
NavigationViewUtil.setItemTextColors(this, ColorUtil.withAlpha(iconColor, 0.5f), accentColor)
2019-12-05 18:18:54 +00:00
itemBackground = RippleDrawable(RippleUtils.convertToRippleDrawableColor(ColorStateList.valueOf(ThemeStore.accentColor(context).addAlpha())), ContextCompat.getDrawable(context, R.drawable.bottom_navigation_item_background), ContextCompat.getDrawable(context, R.drawable.bottom_navigation_item_background_mask))
2019-09-01 13:32:36 +00:00
setOnApplyWindowInsetsListener(null)
2019-12-01 15:27:01 +00:00
//itemRippleColor = ColorStateList.valueOf(accentColor)
2019-12-06 17:13:09 +00:00
background = ColorDrawable(ATHUtil.resolveColor(context, R.attr.colorSurface))
2019-03-03 09:20:15 +00:00
}
2019-11-21 05:59:33 +00:00
}
private fun Int.addAlpha(): Int {
return ColorUtil.withAlpha(this, 0.12f)
}