use some helper functions at updating bottom tab colors

This commit is contained in:
tibbi 2022-06-22 22:16:32 +02:00
parent 3f4f83fdbb
commit 0784c94815
2 changed files with 7 additions and 14 deletions

View File

@ -62,7 +62,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:b2167e4b2a' implementation 'com.github.SimpleMobileTools:Simple-Commons:d1d5402388'
implementation 'org.greenrobot:eventbus:3.3.1' implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.github.Armen101:AudioRecordView:1.0.4' implementation 'com.github.Armen101:AudioRecordView:1.0.4'
implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'androidx.documentfile:documentfile:1.0.1'

View File

@ -116,13 +116,11 @@ class MainActivity : SimpleActivity() {
main_tabs_holder.onTabSelectionChanged( main_tabs_holder.onTabSelectionChanged(
tabUnselectedAction = { tabUnselectedAction = {
it.customView?.findViewById<ImageView>(R.id.tab_item_icon)?.applyColorFilter(getProperTextColor()) updateBottomTabItemColors(it.customView, false)
it.customView?.findViewById<TextView>(R.id.tab_item_label)?.setTextColor(getProperTextColor())
}, },
tabSelectedAction = { tabSelectedAction = {
view_pager.currentItem = it.position view_pager.currentItem = it.position
it.customView?.findViewById<ImageView>(R.id.tab_item_icon)?.applyColorFilter(getProperPrimaryColor()) updateBottomTabItemColors(it.customView, true)
it.customView?.findViewById<TextView>(R.id.tab_item_label)?.setTextColor(getProperPrimaryColor())
} }
) )
@ -139,15 +137,10 @@ class MainActivity : SimpleActivity() {
private fun getPagerAdapter() = (view_pager.adapter as? ViewPagerAdapter) private fun getPagerAdapter() = (view_pager.adapter as? ViewPagerAdapter)
private fun setupTabColors() { private fun setupTabColors() {
main_tabs_holder.getTabAt(getInactiveTabIndex())?.customView?.apply { val activeView = main_tabs_holder.getTabAt(view_pager.currentItem)?.customView
findViewById<ImageView>(R.id.tab_item_icon)?.applyColorFilter(getProperTextColor()) val inactiveView = main_tabs_holder.getTabAt(getInactiveTabIndex())?.customView
findViewById<TextView>(R.id.tab_item_label)?.setTextColor(getProperTextColor()) updateBottomTabItemColors(activeView, true)
} updateBottomTabItemColors(inactiveView, false)
main_tabs_holder.getTabAt(view_pager.currentItem)?.customView?.apply {
findViewById<ImageView>(R.id.tab_item_icon)?.applyColorFilter(getProperPrimaryColor())
findViewById<TextView>(R.id.tab_item_label)?.setTextColor(getProperPrimaryColor())
}
} }
private fun getInactiveTabIndex() = if (view_pager.currentItem == 0) 1 else 0 private fun getInactiveTabIndex() = if (view_pager.currentItem == 0) 1 else 0