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

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

Consolidate group playback checks with `hasGroupPlayback` method.

Have a single method that checks whether there is an active group
playback performed i.e. more than one output device connected. This
check should be done on the output device list before appending the
input devices to it, therefore it's better to do in in the
MediaSwitchingController.

Bug: 422288043
Bug: 432107581
Test: atest MediaOutputAdapterTest, MediaOutputAdapterLegacyTest,
MediaSwitchingControllerTest, MediaOutputAdapterScreenshotTest
Flag: EXEMPT refactor

Change-Id: I6eae42ddaa8a0c436390a3e8e692c74f125d9d97
parent 65402ae1
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -410,6 +410,7 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
                List.of(mMediaDevice1, mMediaDevice2));
                List.of(mMediaDevice1, mMediaDevice2));
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(
                List.of(mMediaDevice1, mMediaDevice2));
                List.of(mMediaDevice1, mMediaDevice2));
        when(mMediaSwitchingController.hasGroupPlayback()).thenReturn(true);


        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        // Expand the group control.
        // Expand the group control.
@@ -1031,7 +1032,10 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
        when(mMediaSwitchingController.getSelectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getSelectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getSelectedMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getSelectedMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(selectedDevices);
        when(mMediaSwitchingController.hasGroupPlayback()).thenReturn(true);


        mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor,
                mBackgroundExecutor);
        mMediaOutputAdapter.updateItems();
        mMediaOutputAdapter.updateItems();
    }
    }
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -332,6 +332,7 @@ class MediaOutputAdapterTest : SysuiTestCase() {
        mMediaSwitchingController.stub {
        mMediaSwitchingController.stub {
            on { isGroupListCollapsed } doReturn false
            on { isGroupListCollapsed } doReturn false
            on { isVolumeControlEnabledForSession } doReturn true
            on { isVolumeControlEnabledForSession } doReturn true
            on { hasGroupPlayback() } doReturn true
        }
        }
        mMediaSwitchingController.stub {
        mMediaSwitchingController.stub {
            on { selectedMediaDevice } doReturn listOf(mMediaDevice1, mMediaDevice2)
            on { selectedMediaDevice } doReturn listOf(mMediaDevice1, mMediaDevice2)
@@ -790,6 +791,7 @@ class MediaOutputAdapterTest : SysuiTestCase() {
            on { selectableMediaDevice } doReturn selectedDevices
            on { selectableMediaDevice } doReturn selectedDevices
            on { selectedMediaDevice } doReturn selectedDevices
            on { selectedMediaDevice } doReturn selectedDevices
            on { deselectableMediaDevice } doReturn selectedDevices
            on { deselectableMediaDevice } doReturn selectedDevices
            on { hasGroupPlayback() } doReturn true
        }
        }
        mMediaOutputAdapter = MediaOutputAdapter(mMediaSwitchingController)
        mMediaOutputAdapter = MediaOutputAdapter(mMediaSwitchingController)
        updateAdapterWithDevices(listOf(mMediaDevice1, mMediaDevice2))
        updateAdapterWithDevices(listOf(mMediaDevice1, mMediaDevice2))
+1 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ class MediaOutputAdapter(controller: MediaSwitchingController) :
            // Avoid grouping broadcast devices because grouped volume control is not available for
            // Avoid grouping broadcast devices because grouped volume control is not available for
            // broadcast session.
            // broadcast session.
            mGroupSelectedItems =
            mGroupSelectedItems =
                mController.selectedMediaDevice.size > 1 &&
                mController.hasGroupPlayback() &&
                    (!Flags.enableOutputSwitcherPersonalAudioSharing() ||
                    (!Flags.enableOutputSwitcherPersonalAudioSharing() ||
                        mController.isVolumeControlEnabledForSession)
                        mController.isVolumeControlEnabledForSession)
        }
        }
+4 −8
Original line number Original line Diff line number Diff line
@@ -75,7 +75,7 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
    boolean isCurrentlyConnected(MediaDevice device) {
    boolean isCurrentlyConnected(MediaDevice device) {
        return TextUtils.equals(device.getId(),
        return TextUtils.equals(device.getId(),
                mController.getCurrentConnectedMediaDevice().getId())
                mController.getCurrentConnectedMediaDevice().getId())
                || (mController.getSelectedMediaDevice().size() == 1
                || (!mController.hasGroupPlayback()
                && isDeviceIncluded(mController.getSelectedMediaDevice(), device));
                && isDeviceIncluded(mController.getSelectedMediaDevice(), device));
    }
    }


@@ -105,7 +105,7 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
        mMediaItemList.clear();
        mMediaItemList.clear();
        mMediaItemList.addAll(mController.getMediaItemList());
        mMediaItemList.addAll(mController.getMediaItemList());
        if (mShouldGroupSelectedMediaItems) {
        if (mShouldGroupSelectedMediaItems) {
            if (mController.getSelectedMediaDevice().size() == 1) {
            if (!mController.hasGroupPlayback()) {
                // Don't group devices if initially there isn't more than one selected.
                // Don't group devices if initially there isn't more than one selected.
                mShouldGroupSelectedMediaItems = false;
                mShouldGroupSelectedMediaItems = false;
            }
            }
@@ -197,7 +197,7 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                    connectionState = ConnectionState.CONNECTING;
                    connectionState = ConnectionState.CONNECTING;
                } else if (!enableOutputSwitcherRedesign() && mShouldGroupSelectedMediaItems
                } else if (!enableOutputSwitcherRedesign() && mShouldGroupSelectedMediaItems
                        && hasMultipleSelectedDevices()
                        && mController.hasGroupPlayback()
                        && isSelected) {
                        && isSelected) {
                    if (mediaItem.isFirstDeviceInGroup()) {
                    if (mediaItem.isFirstDeviceInGroup()) {
                        isDeviceGroup = true;
                        isDeviceGroup = true;
@@ -263,17 +263,13 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl
            // A device should either be selectable or, when the device selected, the list should
            // A device should either be selectable or, when the device selected, the list should
            // have other selectable or selected devices.
            // have other selectable or selected devices.
            boolean selectedWithOtherGroupDevices =
            boolean selectedWithOtherGroupDevices =
                    isSelected && (hasMultipleSelectedDevices() || hasSelectableDevices());
                    isSelected && (mController.hasGroupPlayback() || hasSelectableDevices());
            if (isSelectable || selectedWithOtherGroupDevices) {
            if (isSelectable || selectedWithOtherGroupDevices) {
                return new GroupStatus(isSelected, isDeselectable);
                return new GroupStatus(isSelected, isDeselectable);
            }
            }
            return null;
            return null;
        }
        }


        private boolean hasMultipleSelectedDevices() {
            return mController.getSelectedMediaDevice().size() > 1;
        }

        private boolean hasSelectableDevices() {
        private boolean hasSelectableDevices() {
            return !mController.getSelectableMediaDevice().isEmpty();
            return !mController.getSelectableMediaDevice().isEmpty();
        }
        }
+5 −3
Original line number Original line Diff line number Diff line
@@ -647,12 +647,14 @@ public class MediaSwitchingController
                mContext.getString(R.string.media_output_group_title_connected_speakers));
                mContext.getString(R.string.media_output_group_title_connected_speakers));
    }
    }


    boolean hasGroupPlayback() {
        return getSelectedMediaDevice().size() > 1;
    }

    @Nullable
    @Nullable
    MediaItem getConnectNewDeviceItem() {
    MediaItem getConnectNewDeviceItem() {
        boolean isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() == 1;

        // Attach "Connect a device" item only when current output is not remote and not a group
        // Attach "Connect a device" item only when current output is not remote and not a group
        return (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup)
        return (!isCurrentConnectedDeviceRemote() && !hasGroupPlayback())
                ? MediaItem.createPairNewDeviceMediaItem()
                ? MediaItem.createPairNewDeviceMediaItem()
                : null;
                : null;
    }
    }
Loading