diff options
author | 2025-02-11 18:55:11 -0500 | |
---|---|---|
committer | 2025-02-11 19:01:30 -0500 | |
commit | 6015cc0d688f7054a0940395631b2bed94f1828b (patch) | |
tree | bbca05900f791a76b18436ddc7a4bd80240f2423 | |
parent | c11a9a338140ab8a42b0d82d05ab29f706b20f01 (diff) |
[sb] requestLayout if the number of levels changes
With new_status_bar_icons enabled, the LevelList drawable that holds the
mobile icons contains two main widths of icon: the 4-bar and 5-bar
icons.
Along with the change to SignalDrawable that no longer sets a square
intrinsicWidth/Height, this change is required to ensure that the layout
of the icons in the StatusIconContainer get the most-up-to-date width
from the icon.
Test: restart sysui with a device that uses 5-bar SIM, and with Wi-FI
on. Without the fix, the wi-fi icon will elide into a dot
Bug: 391606042
Flag: com.android.settingslib.flags.new_status_bar_icons
Change-Id: I082cae5749048d53682206e8a6b4d723f60b54d3
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt index 788f041b38c0..0eef2e1ca685 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt @@ -45,6 +45,7 @@ import com.android.systemui.statusbar.pipeline.shared.ui.binder.ModernStatusBarV import com.android.systemui.statusbar.pipeline.shared.ui.binder.ModernStatusBarViewVisibilityHelper import com.android.systemui.statusbar.pipeline.shared.ui.binder.StatusBarViewBinderConstants.ALPHA_ACTIVE import com.android.systemui.statusbar.pipeline.shared.ui.binder.StatusBarViewBinderConstants.ALPHA_INACTIVE +import com.android.systemui.util.kotlin.pairwiseBy import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.distinctUntilChanged @@ -131,19 +132,37 @@ object MobileIconBinder { // Set the icon for the triangle launch { - viewModel.icon.distinctUntilChanged().collect { icon -> - viewModel.verboseLogger?.logBinderReceivedSignalIcon( - view, - viewModel.subscriptionId, - icon, - ) - if (icon is SignalIconModel.Cellular) { - iconView.setImageDrawable(mobileDrawable) - mobileDrawable.level = icon.toSignalDrawableState() - } else if (icon is SignalIconModel.Satellite) { - IconViewBinder.bind(icon.icon, iconView) + viewModel.icon + .pairwiseBy(initialValue = null) { oldIcon, newIcon -> + // Make sure we requestLayout if the number of levels changes + val shouldRequestLayout = + when { + oldIcon == null -> true + oldIcon is SignalIconModel.Cellular && + newIcon is SignalIconModel.Cellular -> { + oldIcon.numberOfLevels != newIcon.numberOfLevels + } + else -> false + } + Pair(shouldRequestLayout, newIcon) + } + .collect { (shouldRequestLayout, newIcon) -> + viewModel.verboseLogger?.logBinderReceivedSignalIcon( + view, + viewModel.subscriptionId, + newIcon, + ) + if (newIcon is SignalIconModel.Cellular) { + iconView.setImageDrawable(mobileDrawable) + mobileDrawable.level = newIcon.toSignalDrawableState() + } else if (newIcon is SignalIconModel.Satellite) { + IconViewBinder.bind(newIcon.icon, iconView) + } + + if (shouldRequestLayout) { + iconView.requestLayout() + } } - } } launch { |