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

Commit a162ceb4 authored by Alex Shabalin's avatar Alex Shabalin
Browse files

Consolidate the logic for "Connected" and "Selected" states.

- Fixed "Go to app expandable" (having both "go to app" link an a group
 status) scenario in b/355062931. Previously, the branch for "Selected"
 device didn't set the group status.
- `mController.isCurrentConnectedDeviceRemote()` replaced by
`isSelected` for the Selected scenario.
- Additionally, consolidated the "Disconnected" state.

Flag: EXEMPT refactor
Bug: 355062931, 387570618
Test: atest SystemUiRoboTests:MediaOutputAdapterTest
    atest SystemUIGoogleRoboRNGTests:MediaOutputAdapterScreenshotTest
Change-Id: Icbbe049ee9f10dc9c915ce0fd095236bf991d1f3
parent ef002248
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -240,6 +240,8 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
    @DisableFlags(Flags.FLAG_ENABLE_OUTPUT_SWITCHER_DEVICE_GROUPING)
    @Test
    public void onBindViewHolder_bindConnectedRemoteDevice_verifyView() {
        when(mMediaSwitchingController.getSelectedMediaDevice())
                .thenReturn(ImmutableList.of(mMediaDevice1));
        when(mMediaSwitchingController.getSelectableMediaDevice())
                .thenReturn(ImmutableList.of(mMediaDevice2));
        when(mMediaSwitchingController.isCurrentConnectedDeviceRemote()).thenReturn(true);
@@ -854,6 +856,8 @@ public class MediaOutputAdapterTest extends SysuiTestCase {
                .thenReturn(ImmutableList.of(mMediaDevice2));
        when(mMediaSwitchingController.getDeselectableMediaDevice())
                .thenReturn(ImmutableList.of(mMediaDevice1));
        when(mMediaSwitchingController.getSelectedMediaDevice())
                .thenReturn(ImmutableList.of(mMediaDevice1));
        when(mMediaSwitchingController.isCurrentConnectedDeviceRemote()).thenReturn(true);
        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
                .onCreateViewHolder(new LinearLayout(mContext), 0);
+25 −23
Original line number Diff line number Diff line
@@ -216,9 +216,8 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    clickListener = v -> cancelMuteAwaitConnection();
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                    connectionState = ConnectionState.CONNECTING;
                } else if (mShouldGroupSelectedMediaItems
                        && mController.getSelectedMediaDevice().size() > 1
                        && isDeviceIncluded(mController.getSelectedMediaDevice(), device)) {
                } else if (mShouldGroupSelectedMediaItems && hasMultipleSelectedDevices()
                        && isSelected) {
                    if (!mediaItem.isFirstDeviceInGroup()) {
                        mItemLayout.setVisibility(View.GONE);
                        return;
@@ -245,38 +244,33 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    deviceStatusIcon = mContext.getDrawable(R.drawable.media_output_status_failed);
                    subtitle = mContext.getString(R.string.media_output_dialog_connect_failed);
                    clickListener = v -> onItemClick(v, device);
                } else if (mController.getSelectedMediaDevice().size() > 1 && isSelected) {
                    // selected device in group
                    groupStatus = new GroupStatus(
                            true /* selected */,
                            isDeselectable /* deselectable */);
                    connectionState = ConnectionState.CONNECTED;
                } else if (currentlyConnected) {
                } else if (currentlyConnected || isSelected) {
                    connectionState = ConnectionState.CONNECTED;
                    // single selected device
                    if (device.hasOngoingSession()) {
                        ongoingSessionStatus = new OngoingSessionStatus(
                                device.isHostForOngoingSession());
                    } else if (mController.isCurrentConnectedDeviceRemote()
                            && !mController.getSelectableMediaDevice().isEmpty()) {
                    }
                    if (hasMultipleSelectedDevices() || hasSelectableDevices()) {
                        //If device is connected and there's other selectable devices, layout as
                        // one of selected devices.
                        groupStatus = new GroupStatus(
                                true /* selected */,
                                isDeselectable /* isDeselectable */);
                    }
                } else if (isSelectable) {
                } else { // disconnected
                    if (isSelectable) {
                        //groupable device
                    groupStatus = new GroupStatus(false /* selected */, true /* deselectable */);
                    if (!Flags.disableTransferWhenAppsDoNotSupport()
                            || isTransferable
                        groupStatus = new GroupStatus(false /* selected */,
                                true /* deselectable */);
                        if (!Flags.disableTransferWhenAppsDoNotSupport() || isTransferable
                                || hasRouteListingPreferenceItem) {
                            clickListener = v -> onItemClick(v, device);
                        }
                    deviceDisabled = clickListener == null;
                    } else {
                        deviceStatusIcon = getDeviceStatusIcon(device, device.hasOngoingSession());
                        clickListener = getClickListenerBasedOnSelectionBehavior(device);
                    }
                    deviceDisabled = clickListener == null;
                }
            }
@@ -308,6 +302,14 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
            }
        }

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

        private boolean hasSelectableDevices() {
            return !mController.getSelectableMediaDevice().isEmpty();
        }

        /** Renders the right side round pill button / checkbox. */
        private void updateEndArea(@NonNull MediaDevice device, ConnectionState connectionState,
                @Nullable GroupStatus groupStatus,