Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6015cc0d authored by Evan Laird's avatar Evan Laird
Browse files

[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
parent c11a9a33
Loading
Loading
Loading
Loading
+31 −12
Original line number Diff line number Diff line
@@ -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,17 +132,35 @@ object MobileIconBinder {

                    // Set the icon for the triangle
                    launch {
                        viewModel.icon.distinctUntilChanged().collect { icon ->
                        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,
                                icon,
                                    newIcon,
                                )
                            if (icon is SignalIconModel.Cellular) {
                                if (newIcon is SignalIconModel.Cellular) {
                                    iconView.setImageDrawable(mobileDrawable)
                                mobileDrawable.level = icon.toSignalDrawableState()
                            } else if (icon is SignalIconModel.Satellite) {
                                IconViewBinder.bind(icon.icon, iconView)
                                    mobileDrawable.level = newIcon.toSignalDrawableState()
                                } else if (newIcon is SignalIconModel.Satellite) {
                                    IconViewBinder.bind(newIcon.icon, iconView)
                                }

                                if (shouldRequestLayout) {
                                    iconView.requestLayout()
                                }
                            }
                    }