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

Commit 66384da3 authored by Alex Shabalin's avatar Alex Shabalin Committed by Alexandr Shabalin
Browse files

Fix UI glitches in the refreshed design.

 - Prevent group control from flickering by returning a stable value
 from `MediaOutputAdapter#getItemId`. The flicker was caused by the
 RecyclerView's add/remove animation.
 - Make the background of the items in the list to be non-transparent.
 This prevents visual overlap of RecyclerView elements whenever item
 dimension changes.

Bug: 406707984
Fix: 406707984
Flag: com.android.media.flags.enable_output_switcher_redesign
Test:  atest SystemUiRoboTests:MediaOutputAdapterTest,
On a physical device.

Change-Id: Id8e6353623f9bdeafab09d999be7590358efc02f
parent 466b5ed8
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class MediaOutputAdapterTest : SysuiTestCase() {
    }

    @Test
    fun getItemId_forDifferentItemsTypes_returnCorrespondingHashCode() {
    fun getItemId_forDevice_returnsIdHashCode() {
        updateAdapterWithDevices(listOf(mMediaDevice1, mMediaDevice2))

        assertThat(mMediaOutputAdapter.getItemId(0))
@@ -132,7 +132,24 @@ class MediaOutputAdapterTest : SysuiTestCase() {
    }

    @Test
    fun getItemId_invalidPosition_returnPosition() {
    fun getItemId_forGroupSeparator_returnsTitleHashCode() {
        mMediaItems.add(MediaItem.createGroupDividerMediaItem("Suggested Devices"))
        mMediaOutputAdapter.updateItems()

        assertThat(mMediaOutputAdapter.getItemId(0)).isEqualTo("Suggested Devices".hashCode())
    }

    @Test
    fun getItemId_forDeviceGroup_returnsItemType() {
        mMediaSwitchingController.stub { on { isGroupListCollapsed } doReturn true }
        initializeSession()

        assertThat(mMediaOutputAdapter.getItemId(1))
            .isEqualTo(MediaItemType.TYPE_DEVICE_GROUP.toLong())
    }

    @Test
    fun getItemId_invalidPosition_returnsNoId() {
        updateAdapterWithDevices(listOf(mMediaDevice1, mMediaDevice2))
        val invalidPosition = mMediaItems.size + 1

+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
  ~ limitations under the License.
  -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="@dimen/media_output_dialog_margin_horizontal"
+9 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
                currentMediaItem.mediaDevice.getOrNull()?.id?.hashCode()?.toLong()
                    ?: RecyclerView.NO_ID
            TYPE_GROUP_DIVIDER -> currentMediaItem.title.hashCode().toLong()
            TYPE_DEVICE_GROUP -> currentMediaItem.hashCode().toLong()
            TYPE_DEVICE_GROUP -> currentMediaItem.mediaItemType.toLong()
            else -> RecyclerView.NO_ID
        }
    }
@@ -253,6 +253,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
            val fixedVolumeConnected = connectionState == CONNECTED && restrictVolumeAdjustment
            val colorTheme = ColorTheme(fixedVolumeConnected, deviceDisabled)

            updateItemBackground()
            updateTitle(device.name, connectionState, colorTheme)
            updateTitleIcon(device, connectionState, restrictVolumeAdjustment, colorTheme)
            updateSubtitle(subtitle, colorTheme)
@@ -267,6 +268,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
        override fun renderDeviceGroupItem() {
            mTitleIcon.visibility = GONE
            val colorTheme = ColorTheme()
            updateItemBackground()
            updateTitle(
                title = mController.sessionName ?: "",
                connectionState = CONNECTED,
@@ -299,6 +301,10 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
            }
        }

        private fun updateItemBackground() {
            mItemLayout.setBackgroundColor(mController.colorScheme.getSurfaceContainer())
        }

        private fun updateContentPadding(verticalPadding: Float) {
            mMainContent.setPadding(0, verticalPadding.toInt(), 0, verticalPadding.toInt())
        }
@@ -595,6 +601,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :

    inner class MediaGroupDividerViewHolder(itemView: View, val mContext: Context) :
        RecyclerView.ViewHolder(itemView) {
        private val mItemLayout: ViewGroup = itemView.requireViewById(R.id.item_layout)
        private val mTopSeparator: View = itemView.requireViewById(R.id.top_separator)
        private val mTitleText: TextView = itemView.requireViewById(R.id.title)
        @VisibleForTesting
@@ -614,6 +621,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
            } else {
                mTopSeparator.visibility = GONE
            }
            mItemLayout.setBackgroundColor(mController.colorScheme.getSurfaceContainer())
            updateExpandButton(isExpandableDivider)
        }