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 Diff line number Diff line
@@ -410,6 +410,7 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase {
                List.of(mMediaDevice1, mMediaDevice2));
        when(mMediaSwitchingController.getDeselectableMediaDevice()).thenReturn(
                List.of(mMediaDevice1, mMediaDevice2));
        when(mMediaSwitchingController.hasGroupPlayback()).thenReturn(true);

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

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

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

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

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

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

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

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