[Audiosharing] Update the dialog content in place
We used to dismiss the dialog and then re-show to update the dialog content. This change is to update the content in place by findViewById. Test: atest Flag: com.android.settingslib.flags.promote_audio_sharing_for_second_auto_connected_lea_device Bug: 395786392 Change-Id: I565d465c5c7d8aaef2a96f5d5f0cb70232a1d7cc
This commit is contained in:
@@ -28,6 +28,9 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AudioSharingDeviceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
@@ -35,7 +38,7 @@ public class AudioSharingDeviceAdapter extends RecyclerView.Adapter<RecyclerView
|
||||
private static final String TAG = "AudioSharingDeviceAdapter";
|
||||
|
||||
private final Context mContext;
|
||||
private final List<AudioSharingDeviceItem> mDevices;
|
||||
private List<AudioSharingDeviceItem> mDevices;
|
||||
private final OnClickListener mOnClickListener;
|
||||
private final ActionType mType;
|
||||
|
||||
@@ -113,6 +116,21 @@ public class AudioSharingDeviceAdapter extends RecyclerView.Adapter<RecyclerView
|
||||
return mDevices.size();
|
||||
}
|
||||
|
||||
/** Updates the data set and notify the change. */
|
||||
public void updateItems(@NonNull List<AudioSharingDeviceItem> items) {
|
||||
if (mDevices.size() != items.size()) {
|
||||
List<AudioSharingDeviceItem> oldItems = new ArrayList<>(mDevices);
|
||||
oldItems.removeAll(items);
|
||||
if (oldItems.isEmpty()) {
|
||||
Log.d(TAG, "Skip updateItems, no change");
|
||||
return;
|
||||
}
|
||||
}
|
||||
mDevices = ImmutableList.copyOf(items);
|
||||
Log.d(TAG, "updateItems, items = " + mDevices);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public interface OnClickListener {
|
||||
/** Called when an item has been clicked. */
|
||||
void onClick(AudioSharingDeviceItem item);
|
||||
|
@@ -20,6 +20,9 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AudioSharingDeviceItem implements Parcelable {
|
||||
private final String mName;
|
||||
@@ -80,4 +83,16 @@ public final class AudioSharingDeviceItem implements Parcelable {
|
||||
public String toString() {
|
||||
return "AudioSharingDeviceItem groupId = " + mGroupId + ", isActive = " + mIsActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (!(obj instanceof AudioSharingDeviceItem other)) return false;
|
||||
return mName.equals(other.getName()) && mGroupId == other.getGroupId()
|
||||
&& mIsActive == other.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mName, mGroupId, mIsActive);
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.CheckReturnValue;
|
||||
|
||||
public class AudioSharingDialogFactory {
|
||||
@@ -50,6 +52,53 @@ public class AudioSharingDialogFactory {
|
||||
return new AudioSharingDialogFactory.DialogBuilder(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the title of the dialog custom title.
|
||||
*
|
||||
* @param dialog The dialog to update
|
||||
* @param titleText The text to be used for the title..
|
||||
*/
|
||||
public static void updateTitle(@NonNull AlertDialog dialog,
|
||||
@NonNull CharSequence titleText) {
|
||||
TextView title = dialog.findViewById(R.id.title_text);
|
||||
if (title != null) {
|
||||
title.setText(titleText);
|
||||
title.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the custom message of the dialog custom body.
|
||||
*
|
||||
* @param dialog The dialog to update
|
||||
* @param message The text to be used for the custom message body.
|
||||
*/
|
||||
public static void updateCustomMessage(@NonNull AlertDialog dialog,
|
||||
@NonNull CharSequence message) {
|
||||
TextView subTitle = dialog.findViewById(R.id.description_text);
|
||||
if (subTitle != null) {
|
||||
subTitle.setText(message);
|
||||
subTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the custom device actions of the dialog custom body.
|
||||
*
|
||||
* @param dialog The dialog to update
|
||||
* @param deviceItems device items to build dialog actions.
|
||||
*/
|
||||
public static void updateCustomDeviceActions(
|
||||
@NonNull AlertDialog dialog, @NonNull List<AudioSharingDeviceItem> deviceItems) {
|
||||
RecyclerView recyclerView = dialog.findViewById(R.id.device_btn_list);
|
||||
if (recyclerView != null && recyclerView.getVisibility() == View.VISIBLE) {
|
||||
RecyclerView.Adapter adapter = recyclerView.getAdapter();
|
||||
if (adapter instanceof AudioSharingDeviceAdapter) {
|
||||
((AudioSharingDeviceAdapter) adapter).updateItems(deviceItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Builder class with configurable options for the dialog to be shown for audio sharing. */
|
||||
public static class DialogBuilder {
|
||||
private Context mContext;
|
||||
|
@@ -33,21 +33,19 @@ import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "AudioSharingDisconnectDialog";
|
||||
|
||||
private static final String BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS =
|
||||
"bundle_key_device_to_disconnect_items";
|
||||
private static final String BUNDLE_KEY_NEW_DEVICE_NAME = "bundle_key_new_device_name";
|
||||
|
||||
// The host creates an instance of this dialog fragment must implement this interface to receive
|
||||
// event callbacks.
|
||||
@@ -80,8 +78,10 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
|
||||
* @param newDevice The latest connected device triggered this dialog.
|
||||
* @param listener The callback to handle the user action on this dialog.
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*
|
||||
* @return whether the dialog is shown
|
||||
*/
|
||||
public static void show(
|
||||
public static boolean show(
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull CachedBluetoothDevice newDevice,
|
||||
@@ -89,60 +89,46 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
int newGroupId = BluetoothUtils.getGroupId(newDevice);
|
||||
if (sNewDevice != null && newGroupId == BluetoothUtils.getGroupId(sNewDevice)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for the same device group %d, "
|
||||
+ "update the content.",
|
||||
newGroupId));
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
return;
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for new device group %d, "
|
||||
+ "dismiss current dialog.",
|
||||
newGroupId));
|
||||
dialog.dismiss();
|
||||
logDialogAutoDismiss(dialog);
|
||||
}
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingDisconnectDialogFragment dialogFrag =
|
||||
new AudioSharingDisconnectDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
Log.d(TAG, "Fail to show dialog, feature disabled");
|
||||
return false;
|
||||
}
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return false;
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
AudioSharingUtils.postOnMainThread(
|
||||
host.getContext(),
|
||||
() -> {
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, update the content.");
|
||||
updateDialog(ImmutableList.copyOf(deviceItems), dialog);
|
||||
} else {
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS,
|
||||
deviceItems);
|
||||
AudioSharingDisconnectDialogFragment dialogFrag =
|
||||
new AudioSharingDisconnectDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Return the tag of {@link AudioSharingDisconnectDialogFragment} dialog. */
|
||||
@@ -226,16 +212,9 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
|
||||
}
|
||||
}
|
||||
|
||||
private static void logDialogAutoDismiss(AlertDialog dialog) {
|
||||
var unused =
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> FeatureFactory.getFeatureFactory()
|
||||
.getMetricsFeatureProvider()
|
||||
.action(
|
||||
dialog.getContext(),
|
||||
SettingsEnums
|
||||
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
|
||||
SettingsEnums
|
||||
.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
|
||||
private static void updateDialog(
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull AlertDialog dialog) {
|
||||
AudioSharingDialogFactory.updateCustomDeviceActions(dialog, deviceItems);
|
||||
}
|
||||
}
|
||||
|
@@ -77,8 +77,10 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
|
||||
* @param newDevice The latest connected device triggered this dialog.
|
||||
* @param listener The callback to handle the user action on this dialog.
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*
|
||||
* @return whether the dialog is shown
|
||||
*/
|
||||
public static void show(
|
||||
public static boolean show(
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull CachedBluetoothDevice newDevice,
|
||||
@@ -86,39 +88,47 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, update the content.");
|
||||
updateDialog(deviceItems, newDevice.getName(), dialog);
|
||||
} else {
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
final AudioSharingJoinDialogFragment dialogFrag =
|
||||
new AudioSharingJoinDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
Log.d(TAG, "Fail to show dialog, feature disabled");
|
||||
return false;
|
||||
}
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return false;
|
||||
}
|
||||
sListener = listener;
|
||||
sNewDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
AudioSharingUtils.postOnMainThread(
|
||||
host.getContext(),
|
||||
() -> {
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager,
|
||||
TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, update the content.");
|
||||
updateDialog(deviceItems, newDevice.getName(), dialog);
|
||||
} else {
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
final AudioSharingJoinDialogFragment dialogFrag =
|
||||
new AudioSharingJoinDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Return the tag of {@link AudioSharingJoinDialogFragment} dialog. */
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
@@ -33,16 +34,13 @@ import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "AudioSharingStopDialog";
|
||||
@@ -77,8 +75,10 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
* @param newDevice The latest connected device triggered this dialog.
|
||||
* @param listener The callback to handle the user action on this dialog.
|
||||
* @param eventData The eventData to log with for dialog onClick events.
|
||||
*
|
||||
* @return whether the dialog is shown
|
||||
*/
|
||||
public static void show(
|
||||
public static boolean show(
|
||||
@Nullable Fragment host,
|
||||
@NonNull List<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull CachedBluetoothDevice newDevice,
|
||||
@@ -86,59 +86,47 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (host == null) {
|
||||
Log.d(TAG, "Fail to show dialog, host is null");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return;
|
||||
}
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
int newGroupId = BluetoothUtils.getGroupId(newDevice);
|
||||
if (sCachedDevice != null
|
||||
&& newGroupId == BluetoothUtils.getGroupId(sCachedDevice)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for the same device group %d, return.",
|
||||
newGroupId));
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
return;
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
Locale.US,
|
||||
"Dialog is showing for new device group %d, "
|
||||
+ "dismiss current dialog.",
|
||||
newGroupId));
|
||||
dialog.dismiss();
|
||||
logDialogAutoDismiss(dialog);
|
||||
}
|
||||
}
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingStopDialogFragment dialogFrag = new AudioSharingStopDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
|
||||
Log.d(TAG, "Fail to show dialog, feature disabled");
|
||||
return false;
|
||||
}
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
|
||||
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
Log.d(TAG, "Fail to show dialog with state: " + currentState);
|
||||
return false;
|
||||
}
|
||||
sListener = listener;
|
||||
sCachedDevice = newDevice;
|
||||
sEventData = eventData;
|
||||
AudioSharingUtils.postOnMainThread(
|
||||
host.getContext(),
|
||||
() -> {
|
||||
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
|
||||
if (dialog != null) {
|
||||
Log.d(TAG, "Dialog is showing, update the content.");
|
||||
updateDialog(host.getContext(), deviceItems, newDevice.getName(), dialog);
|
||||
} else {
|
||||
Log.d(TAG, "Show up the dialog.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelableList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS,
|
||||
deviceItems);
|
||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDevice.getName());
|
||||
AudioSharingStopDialogFragment dialogFrag =
|
||||
new AudioSharingStopDialogFragment();
|
||||
dialogFrag.setArguments(bundle);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Return the tag of {@link AudioSharingStopDialogFragment} dialog. */
|
||||
@@ -172,28 +160,10 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
List<AudioSharingDeviceItem> deviceItems =
|
||||
arguments.getParcelable(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, List.class);
|
||||
String newDeviceName = arguments.getString(BUNDLE_KEY_NEW_DEVICE_NAME);
|
||||
String customMessage = "";
|
||||
if (deviceItems != null) {
|
||||
customMessage =
|
||||
deviceItems.size() == 1
|
||||
? getString(
|
||||
R.string.audio_sharing_stop_dialog_content,
|
||||
Iterables.getOnlyElement(deviceItems).getName())
|
||||
: (deviceItems.size() == 2
|
||||
? getString(
|
||||
R.string.audio_sharing_stop_dialog_with_two_content,
|
||||
deviceItems.get(0).getName(),
|
||||
deviceItems.get(1).getName())
|
||||
: getString(
|
||||
R.string.audio_sharing_stop_dialog_with_more_content));
|
||||
}
|
||||
AlertDialog dialog =
|
||||
AudioSharingDialogFactory.newBuilder(getActivity())
|
||||
.setTitle(
|
||||
getString(R.string.audio_sharing_stop_dialog_title, newDeviceName))
|
||||
.setTitleIcon(com.android.settings.R.drawable.ic_warning_24dp)
|
||||
.setIsCustomBodyEnabled(true)
|
||||
.setCustomMessage(customMessage)
|
||||
.setPositiveButton(
|
||||
R.string.audio_sharing_connect_button_label,
|
||||
(dlg, which) -> {
|
||||
@@ -216,7 +186,7 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
sEventData))
|
||||
.build();
|
||||
dialog.show();
|
||||
AudioSharingDialogHelper.updateMessageStyle(dialog);
|
||||
updateDialog(getContext(), deviceItems, newDeviceName, dialog);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@@ -232,15 +202,29 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private static void logDialogAutoDismiss(AlertDialog dialog) {
|
||||
var unused =
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> FeatureFactory.getFeatureFactory()
|
||||
.getMetricsFeatureProvider()
|
||||
.action(
|
||||
dialog.getContext(),
|
||||
SettingsEnums
|
||||
.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
|
||||
SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
|
||||
private static void updateDialog(
|
||||
@NonNull Context context,
|
||||
@Nullable List<AudioSharingDeviceItem> deviceItems,
|
||||
String newDeviceName,
|
||||
@NonNull AlertDialog dialog) {
|
||||
String title = context.getString(R.string.audio_sharing_stop_dialog_title, newDeviceName);
|
||||
String customMessage = "";
|
||||
if (deviceItems != null) {
|
||||
if (deviceItems.size() == 1) {
|
||||
customMessage = context.getString(
|
||||
R.string.audio_sharing_stop_dialog_content,
|
||||
Iterables.getOnlyElement(deviceItems).getName());
|
||||
} else if (deviceItems.size() == 2) {
|
||||
customMessage = context.getString(
|
||||
R.string.audio_sharing_stop_dialog_with_two_content,
|
||||
deviceItems.get(0).getName(),
|
||||
deviceItems.get(1).getName());
|
||||
} else {
|
||||
customMessage = context.getString(
|
||||
R.string.audio_sharing_stop_dialog_with_more_content);
|
||||
}
|
||||
}
|
||||
AudioSharingDialogFactory.updateTitle(dialog, title);
|
||||
AudioSharingDialogFactory.updateCustomMessage(dialog, customMessage);
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AudioSharingDeviceItemTest {
|
||||
private static final String TEST_NAME = "test";
|
||||
@@ -87,4 +89,28 @@ public class AudioSharingDeviceItemTest {
|
||||
"AudioSharingDeviceItem groupId = " + TEST_GROUP_ID + ", isActive = "
|
||||
+ TEST_IS_ACTIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_returnsFalse() {
|
||||
AudioSharingDeviceItem item =
|
||||
new AudioSharingDeviceItem(TEST_NAME, TEST_GROUP_ID, TEST_IS_ACTIVE);
|
||||
assertThat(item.equals(null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_returnsTrue() {
|
||||
AudioSharingDeviceItem item1 =
|
||||
new AudioSharingDeviceItem(TEST_NAME, TEST_GROUP_ID, TEST_IS_ACTIVE);
|
||||
AudioSharingDeviceItem item2 =
|
||||
new AudioSharingDeviceItem(TEST_NAME, TEST_GROUP_ID, TEST_IS_ACTIVE);
|
||||
assertThat(item1.equals(item2)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hash() {
|
||||
AudioSharingDeviceItem item = new AudioSharingDeviceItem(TEST_NAME, TEST_GROUP_ID,
|
||||
TEST_IS_ACTIVE);
|
||||
assertThat(item.hashCode()).isEqualTo(
|
||||
Objects.hash(TEST_NAME, TEST_GROUP_ID, TEST_IS_ACTIVE));
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
@@ -231,11 +230,6 @@ public class AudioSharingDisconnectDialogFragmentTest {
|
||||
shadowMainLooper().idle();
|
||||
dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
verify(mFeatureFactory.metricsFeatureProvider, times(0))
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
|
||||
|
||||
btn1 = view.findViewHolderForAdapterPosition(0).itemView.findViewById(R.id.device_button);
|
||||
btn1.performClick();
|
||||
@@ -251,7 +245,7 @@ public class AudioSharingDisconnectDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
public void onCreateDialog_dialogIsShowingForNewGroup_showNewDialog() {
|
||||
public void onCreateDialog_dialogIsShowingForNewGroup_updateDialog() {
|
||||
mDeviceItems = new ArrayList<>();
|
||||
mDeviceItems.add(TEST_DEVICE_ITEM1);
|
||||
mDeviceItems.add(TEST_DEVICE_ITEM2);
|
||||
@@ -265,7 +259,7 @@ public class AudioSharingDisconnectDialogFragmentTest {
|
||||
assertThat(view).isNotNull();
|
||||
assertThat(view.getAdapter().getItemCount()).isEqualTo(2);
|
||||
|
||||
// Show new dialog for device with new group
|
||||
// Update dialog content for device with new group
|
||||
ArrayList<AudioSharingDeviceItem> newDeviceItems = new ArrayList<>();
|
||||
newDeviceItems.add(TEST_DEVICE_ITEM2);
|
||||
newDeviceItems.add(TEST_DEVICE_ITEM3);
|
||||
@@ -278,11 +272,6 @@ public class AudioSharingDisconnectDialogFragmentTest {
|
||||
shadowMainLooper().idle();
|
||||
dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
|
||||
|
||||
view = dialog.findViewById(R.id.device_btn_list);
|
||||
assertThat(view).isNotNull();
|
||||
@@ -323,11 +312,6 @@ public class AudioSharingDisconnectDialogFragmentTest {
|
||||
|
||||
assertThat(dialog.isShowing()).isFalse();
|
||||
assertThat(mParent.getActivity().isFinishing()).isFalse();
|
||||
verify(mFeatureFactory.metricsFeatureProvider, times(0))
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_DEVICE));
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
any(Context.class),
|
||||
|
@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||
@@ -238,11 +237,6 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
verify(mFeatureFactory.metricsFeatureProvider, times(0))
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
|
||||
|
||||
View btnView = dialog.findViewById(android.R.id.button1);
|
||||
assertThat(btnView).isNotNull();
|
||||
@@ -259,7 +253,7 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
public void onCreateDialog_dialogIsShowingForNewDevice_showNewDialog() {
|
||||
public void onCreateDialog_dialogIsShowingForNewDevice_updateDialog() {
|
||||
AudioSharingStopDialogFragment.show(
|
||||
mParent,
|
||||
ImmutableList.of(),
|
||||
@@ -281,7 +275,7 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
mParent.getString(
|
||||
R.string.audio_sharing_stop_dialog_title, TEST_DEVICE_NAME1));
|
||||
|
||||
// Show new dialog
|
||||
// Update the dialog content
|
||||
AudioSharingStopDialogFragment.show(
|
||||
mParent,
|
||||
ImmutableList.of(),
|
||||
@@ -292,11 +286,6 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.isShowing()).isTrue();
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
|
||||
|
||||
view = dialog.findViewById(R.id.description_text);
|
||||
assertThat(view).isNotNull();
|
||||
@@ -329,11 +318,6 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
shadowMainLooper().idle();
|
||||
assertThat(dialog.isShowing()).isFalse();
|
||||
assertThat(mParent.getActivity().isFinishing()).isFalse();
|
||||
verify(mFeatureFactory.metricsFeatureProvider, times(0))
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
any(Context.class),
|
||||
@@ -362,11 +346,6 @@ public class AudioSharingStopDialogFragmentTest {
|
||||
assertThat(dialog.isShowing()).isFalse();
|
||||
assertThat(isStopBtnClicked.get()).isTrue();
|
||||
assertThat(mParent.getActivity().isFinishing()).isFalse();
|
||||
verify(mFeatureFactory.metricsFeatureProvider, times(0))
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS),
|
||||
eq(SettingsEnums.DIALOG_STOP_AUDIO_SHARING));
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
any(Context.class),
|
||||
|
Reference in New Issue
Block a user