@@ -126,6 +126,7 @@ class MainActivity : HelperBaseActivity(),
126126
127127 SubscriptionUpdater .sync()
128128 mainViewModel.reloadServerList()
129+ refreshGroupTabTitles(true )
129130
130131 checkAndRequestPermission(PermissionType .POST_NOTIFICATIONS ) {}
131132 }
@@ -434,24 +435,42 @@ class MainActivity : HelperBaseActivity(),
434435 badge.post { badge.requestLayout() }
435436 }
436437
438+ private fun setTabIcon (iconView : android.widget.ImageView ? , iconName : String? ) {
439+ iconView ? : return
440+ if (iconName.isNullOrBlank()) {
441+ iconView.visibility = android.view.View .GONE
442+ return
443+ }
444+ val resId = resources.getIdentifier(iconName, " drawable" , packageName)
445+ if (resId == 0 ) {
446+ iconView.visibility = android.view.View .GONE
447+ return
448+ }
449+ iconView.setImageResource(resId)
450+ iconView.visibility = android.view.View .VISIBLE
451+ }
452+
437453 private fun applyTabSelectedStyle (
438454 tab : com.google.android.material.tabs.TabLayout .Tab ? ,
439455 selected : Boolean ,
440456 position : Int = tab?.position ? : 0,
441457 tabCount : Int = binding.tabGroup.tabCount
442458 ) {
443459 val view = tab?.customView ? : return
460+ val icon = view.findViewById< android.widget.ImageView > (R .id.tab_icon)
444461 val label = view.findViewById<TextView >(R .id.tab_label) ? : return
445462 val badge = view.findViewById<TextView >(R .id.tab_badge) ? : return
446463
464+ val tintColor = if (selected) getColorAttr(" colorOnPrimary" ) else getColorAttr(" colorOnSurfaceVariant" )
465+ label.setTextColor(tintColor)
466+ icon?.imageTintList = android.content.res.ColorStateList .valueOf(tintColor)
467+
447468 if (selected) {
448- label.setTextColor(getColorAttr(" colorOnPrimary" ))
449469 badge.setTextColor(getColorAttr(" colorPrimary" ))
450470 badge.backgroundTintList = android.content.res.ColorStateList .valueOf(
451471 getColorAttr(" colorOnPrimary" )
452472 )
453473 } else {
454- label.setTextColor(getColorAttr(" colorOnSurfaceVariant" ))
455474 badge.setTextColor(getColorAttr(" colorOnPrimary" ))
456475 badge.backgroundTintList = android.content.res.ColorStateList .valueOf(
457476 getColorAttr(" colorPrimary" )
@@ -468,9 +487,11 @@ class MainActivity : HelperBaseActivity(),
468487 groupPagerAdapter.groups.getOrNull(position)?.let { group ->
469488 tab.tag = group.id
470489 val tabView = LayoutInflater .from(this ).inflate(R .layout.item_tab_group, null )
490+ val tabIcon = tabView.findViewById< android.widget.ImageView > (R .id.tab_icon)
471491 val tabLabel = tabView.findViewById<TextView >(R .id.tab_label)
472492 val tabBadge = tabView.findViewById<TextView >(R .id.tab_badge)
473493 tabLabel.text = group.remarks
494+ setTabIcon(tabIcon, group.icon)
474495 setBadgeVisibility(tabBadge, tabLabel, group.serverCount)
475496 tab.customView = tabView
476497 }
@@ -498,8 +519,6 @@ class MainActivity : HelperBaseActivity(),
498519 binding.layoutTabWrapper.isVisible = hasAnyGroup
499520 binding.tabGroup.isVisible = hasAnyGroup
500521 (binding.tabGroup.parent as ? View )?.isVisible = hasAnyGroup
501-
502- refreshGroupTabTitles(true )
503522 }
504523
505524 fun refreshGroupTabTitles (refreshAll : Boolean = false) {
0 commit comments