Merge "Rename AudioSharingLoadingStateDialogFragment and layout" into main
This commit is contained in:
@@ -72,7 +72,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
||||||
@Nullable
|
@Nullable
|
||||||
private AlertDialog mLoadingDialog = null;
|
private AlertDialog mProgressDialog = null;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mShouldTriggerAudioSharingShareThenPairFlow = false;
|
boolean mShouldTriggerAudioSharingShareThenPairFlow = false;
|
||||||
private CopyOnWriteArrayList<BluetoothDevice> mDevicesWithMetadataChangedListener =
|
private CopyOnWriteArrayList<BluetoothDevice> mDevicesWithMetadataChangedListener =
|
||||||
@@ -89,7 +89,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
// In share then pair flow, we have to wait on this page till the device is connected.
|
// In share then pair flow, we have to wait on this page till the device is connected.
|
||||||
// The BluetoothDevicePreference summary will be blank for seconds between "Pairing..." and
|
// The BluetoothDevicePreference summary will be blank for seconds between "Pairing..." and
|
||||||
// "Connecting..." To help users better understand the process, we listen to metadata change
|
// "Connecting..." To help users better understand the process, we listen to metadata change
|
||||||
// as well and show a loading dialog with "Connecting to ...." once BluetoothDevice.getState()
|
// as well and show a progress dialog with "Connecting to ...." once BluetoothDevice.getState()
|
||||||
// gets to BOND_BONDED.
|
// gets to BOND_BONDED.
|
||||||
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
||||||
new BluetoothAdapter.OnMetadataChangedListener() {
|
new BluetoothAdapter.OnMetadataChangedListener() {
|
||||||
@@ -97,7 +97,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
public void onMetadataChanged(@NonNull BluetoothDevice device, int key,
|
public void onMetadataChanged(@NonNull BluetoothDevice device, int key,
|
||||||
@Nullable byte[] value) {
|
@Nullable byte[] value) {
|
||||||
Log.d(getLogTag(), "onMetadataChanged device = " + device + ", key = " + key);
|
Log.d(getLogTag(), "onMetadataChanged device = " + device + ", key = " + key);
|
||||||
if (mShouldTriggerAudioSharingShareThenPairFlow && mLoadingDialog == null
|
if (mShouldTriggerAudioSharingShareThenPairFlow && mProgressDialog == null
|
||||||
&& device.getBondState() == BluetoothDevice.BOND_BONDED
|
&& device.getBondState() == BluetoothDevice.BOND_BONDED
|
||||||
&& mSelectedList.contains(device)) {
|
&& mSelectedList.contains(device)) {
|
||||||
triggerAudioSharingShareThenPairFlow(device);
|
triggerAudioSharingShareThenPairFlow(device);
|
||||||
@@ -355,7 +355,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mJustBonded = device;
|
mJustBonded = device;
|
||||||
// Show connecting device loading state
|
// Show connecting device progress
|
||||||
String aliasName = device.getAlias();
|
String aliasName = device.getAlias();
|
||||||
String deviceName = TextUtils.isEmpty(aliasName) ? device.getAddress()
|
String deviceName = TextUtils.isEmpty(aliasName) ? device.getAddress()
|
||||||
: aliasName;
|
: aliasName;
|
||||||
@@ -387,9 +387,9 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
// TODO: use DialogFragment
|
// TODO: use DialogFragment
|
||||||
private void showConnectingDialog(@NonNull String message) {
|
private void showConnectingDialog(@NonNull String message) {
|
||||||
postOnMainThread(() -> {
|
postOnMainThread(() -> {
|
||||||
if (mLoadingDialog != null) {
|
if (mProgressDialog != null) {
|
||||||
Log.d(getLogTag(), "showConnectingDialog, is already showing");
|
Log.d(getLogTag(), "showConnectingDialog, is already showing");
|
||||||
TextView textView = mLoadingDialog.findViewById(R.id.message);
|
TextView textView = mProgressDialog.findViewById(R.id.message);
|
||||||
if (textView != null && !message.equals(textView.getText().toString())) {
|
if (textView != null && !message.equals(textView.getText().toString())) {
|
||||||
Log.d(getLogTag(), "showConnectingDialog, update message");
|
Log.d(getLogTag(), "showConnectingDialog, update message");
|
||||||
// TODO: use string res once finalized
|
// TODO: use string res once finalized
|
||||||
@@ -401,7 +401,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
||||||
View customView = inflater.inflate(
|
View customView = inflater.inflate(
|
||||||
R.layout.dialog_audio_sharing_loading_state, /* root= */
|
R.layout.dialog_audio_sharing_progress, /* root= */
|
||||||
null);
|
null);
|
||||||
TextView textView = customView.findViewById(R.id.message);
|
TextView textView = customView.findViewById(R.id.message);
|
||||||
if (textView != null) {
|
if (textView != null) {
|
||||||
@@ -410,15 +410,15 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
}
|
}
|
||||||
AlertDialog dialog = builder.setView(customView).setCancelable(false).create();
|
AlertDialog dialog = builder.setView(customView).setCancelable(false).create();
|
||||||
dialog.setCanceledOnTouchOutside(false);
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
mLoadingDialog = dialog;
|
mProgressDialog = dialog;
|
||||||
dialog.show();
|
dialog.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismissConnectingDialog() {
|
private void dismissConnectingDialog() {
|
||||||
postOnMainThread(() -> {
|
postOnMainThread(() -> {
|
||||||
if (mLoadingDialog != null) {
|
if (mProgressDialog != null) {
|
||||||
mLoadingDialog.dismiss();
|
mProgressDialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,8 @@ import com.google.common.base.Strings;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFragment {
|
public class AudioSharingProgressDialogFragment extends InstrumentedDialogFragment {
|
||||||
private static final String TAG = "AudioSharingLoadingDlg";
|
private static final String TAG = "AudioSharingProgressDlg";
|
||||||
|
|
||||||
private static final String BUNDLE_KEY_MESSAGE = "bundle_key_message";
|
private static final String BUNDLE_KEY_MESSAGE = "bundle_key_message";
|
||||||
private static final long AUTO_DISMISS_TIME_THRESHOLD_MS = TimeUnit.SECONDS.toMillis(15);
|
private static final long AUTO_DISMISS_TIME_THRESHOLD_MS = TimeUnit.SECONDS.toMillis(15);
|
||||||
@@ -58,7 +58,7 @@ public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the {@link AudioSharingLoadingStateDialogFragment} dialog.
|
* Display the {@link AudioSharingProgressDialogFragment} dialog.
|
||||||
*
|
*
|
||||||
* @param host The Fragment this dialog will be hosted by.
|
* @param host The Fragment this dialog will be hosted by.
|
||||||
* @param message The content to be shown on the dialog.
|
* @param message The content to be shown on the dialog.
|
||||||
@@ -85,16 +85,15 @@ public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sMessage = message;
|
sMessage = message;
|
||||||
Log.d(TAG, "Show up the loading dialog.");
|
Log.d(TAG, "Show up the progress dialog.");
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(BUNDLE_KEY_MESSAGE, message);
|
args.putString(BUNDLE_KEY_MESSAGE, message);
|
||||||
AudioSharingLoadingStateDialogFragment dialogFrag =
|
AudioSharingProgressDialogFragment dialogFrag = new AudioSharingProgressDialogFragment();
|
||||||
new AudioSharingLoadingStateDialogFragment();
|
|
||||||
dialogFrag.setArguments(args);
|
dialogFrag.setArguments(args);
|
||||||
dialogFrag.show(manager, TAG);
|
dialogFrag.show(manager, TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dismiss the {@link AudioSharingLoadingStateDialogFragment} dialog. */
|
/** Dismiss the {@link AudioSharingProgressDialogFragment} dialog. */
|
||||||
public static void dismiss(@Nullable Fragment host) {
|
public static void dismiss(@Nullable Fragment host) {
|
||||||
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
||||||
final FragmentManager manager;
|
final FragmentManager manager;
|
||||||
@@ -119,7 +118,7 @@ public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFr
|
|||||||
String message = args.getString(BUNDLE_KEY_MESSAGE, "");
|
String message = args.getString(BUNDLE_KEY_MESSAGE, "");
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
||||||
View customView = inflater.inflate(R.layout.dialog_audio_sharing_loading_state, /* root= */
|
View customView = inflater.inflate(R.layout.dialog_audio_sharing_progress, /* root= */
|
||||||
null);
|
null);
|
||||||
TextView textView = customView.findViewById(R.id.message);
|
TextView textView = customView.findViewById(R.id.message);
|
||||||
if (!Strings.isNullOrEmpty(message)) textView.setText(message);
|
if (!Strings.isNullOrEmpty(message)) textView.setText(message);
|
@@ -315,7 +315,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
if (mSinksInAdding.contains(sink)) {
|
if (mSinksInAdding.contains(sink)) {
|
||||||
mSinksInAdding.remove(sink);
|
mSinksInAdding.remove(sink);
|
||||||
}
|
}
|
||||||
dismissLoadingStateDialogIfNeeded();
|
dismissProgressDialogIfNeeded();
|
||||||
Log.d(TAG, "onReceiveStateChanged() connected, sink = " + sink
|
Log.d(TAG, "onReceiveStateChanged() connected, sink = " + sink
|
||||||
+ ", remaining sinks = " + mSinksInAdding);
|
+ ", remaining sinks = " + mSinksInAdding);
|
||||||
if (mSinksToWaitFor.contains(sink)) {
|
if (mSinksToWaitFor.contains(sink)) {
|
||||||
@@ -573,7 +573,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
mSinksInAdding.clear();
|
mSinksInAdding.clear();
|
||||||
// TODO: use string res once finalized.
|
// TODO: use string res once finalized.
|
||||||
AudioSharingUtils.postOnMainThread(mContext,
|
AudioSharingUtils.postOnMainThread(mContext,
|
||||||
() -> AudioSharingLoadingStateDialogFragment.show(mFragment,
|
() -> AudioSharingProgressDialogFragment.show(mFragment,
|
||||||
"Starting audio stream..."));
|
"Starting audio stream..."));
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mContext,
|
mContext,
|
||||||
@@ -690,7 +690,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
if (mFragment == null) {
|
if (mFragment == null) {
|
||||||
Log.d(TAG, "handleOnBroadcastReady: dialog fail to show due to null fragment.");
|
Log.d(TAG, "handleOnBroadcastReady: dialog fail to show due to null fragment.");
|
||||||
// Clean up states before early return.
|
// Clean up states before early return.
|
||||||
dismissLoadingStateDialogIfNeeded();
|
dismissProgressDialogIfNeeded();
|
||||||
cleanUpStatesForStartSharing();
|
cleanUpStatesForStartSharing();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -711,8 +711,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
new AudioSharingDialogFragment.DialogEventListener() {
|
new AudioSharingDialogFragment.DialogEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPositiveClick() {
|
public void onPositiveClick() {
|
||||||
// Could go to other pages, dismiss the loading dialog.
|
// Could go to other pages, dismiss the progress dialog.
|
||||||
dismissLoadingStateDialogIfNeeded();
|
dismissProgressDialogIfNeeded();
|
||||||
cleanUpStatesForStartSharing();
|
cleanUpStatesForStartSharing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,8 +726,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelClick() {
|
public void onCancelClick() {
|
||||||
// Could go to other pages, dismiss the loading dialog.
|
// Could go to other pages, dismiss the progress dialog.
|
||||||
dismissLoadingStateDialogIfNeeded();
|
dismissProgressDialogIfNeeded();
|
||||||
cleanUpStatesForStartSharing();
|
cleanUpStatesForStartSharing();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -831,20 +831,20 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
@NonNull String sinkName) {
|
@NonNull String sinkName) {
|
||||||
mSinksInAdding.addAll(targetActiveSinks);
|
mSinksInAdding.addAll(targetActiveSinks);
|
||||||
// TODO: move to res once finalized
|
// TODO: move to res once finalized
|
||||||
String loadingMessage = "Sharing with " + sinkName + "...";
|
String progressMessage = "Sharing with " + sinkName + "...";
|
||||||
showLoadingStateDialog(loadingMessage);
|
showProgressDialog(progressMessage);
|
||||||
AudioSharingUtils.addSourceToTargetSinks(targetActiveSinks, mBtManager);
|
AudioSharingUtils.addSourceToTargetSinks(targetActiveSinks, mBtManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showLoadingStateDialog(@NonNull String loadingMessage) {
|
private void showProgressDialog(@NonNull String progressMessage) {
|
||||||
AudioSharingUtils.postOnMainThread(mContext,
|
AudioSharingUtils.postOnMainThread(mContext,
|
||||||
() -> AudioSharingLoadingStateDialogFragment.show(mFragment, loadingMessage));
|
() -> AudioSharingProgressDialogFragment.show(mFragment, progressMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismissLoadingStateDialogIfNeeded() {
|
private void dismissProgressDialogIfNeeded() {
|
||||||
if (mSinksInAdding.isEmpty()) {
|
if (mSinksInAdding.isEmpty()) {
|
||||||
AudioSharingUtils.postOnMainThread(mContext,
|
AudioSharingUtils.postOnMainThread(mContext,
|
||||||
() -> AudioSharingLoadingStateDialogFragment.dismiss(mFragment));
|
() -> AudioSharingProgressDialogFragment.dismiss(mFragment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,7 +52,7 @@ import org.robolectric.shadows.androidx.fragment.FragmentController;
|
|||||||
ShadowAlertDialogCompat.class,
|
ShadowAlertDialogCompat.class,
|
||||||
ShadowBluetoothAdapter.class,
|
ShadowBluetoothAdapter.class,
|
||||||
})
|
})
|
||||||
public class AudioSharingLoadingStateDialogFragmentTest {
|
public class AudioSharingProgressDialogFragmentTest {
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
||||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
private static final String TEST_MESSAGE2 = "message2";
|
private static final String TEST_MESSAGE2 = "message2";
|
||||||
|
|
||||||
private Fragment mParent;
|
private Fragment mParent;
|
||||||
private AudioSharingLoadingStateDialogFragment mFragment;
|
private AudioSharingProgressDialogFragment mFragment;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -72,7 +72,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
mFragment = new AudioSharingLoadingStateDialogFragment();
|
mFragment = new AudioSharingProgressDialogFragment();
|
||||||
mParent = new Fragment();
|
mParent = new Fragment();
|
||||||
FragmentController.setupFragment(
|
FragmentController.setupFragment(
|
||||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||||
@@ -93,7 +93,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_flagOff_dialogNotExist() {
|
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNull();
|
assertThat(dialog).isNull();
|
||||||
@@ -102,7 +102,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingLoadingStateDialogFragment.show(new Fragment(), TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(new Fragment(), TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNull();
|
assertThat(dialog).isNull();
|
||||||
@@ -111,7 +111,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_flagOn_showDialog() {
|
public void onCreateDialog_flagOn_showDialog() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNotNull();
|
assertThat(dialog).isNotNull();
|
||||||
@@ -124,13 +124,13 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void dismissDialog_succeed() {
|
public void dismissDialog_succeed() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNotNull();
|
assertThat(dialog).isNotNull();
|
||||||
assertThat(dialog.isShowing()).isTrue();
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
|
|
||||||
AudioSharingLoadingStateDialogFragment.dismiss(mParent);
|
AudioSharingProgressDialogFragment.dismiss(mParent);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
assertThat(dialog.isShowing()).isFalse();
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -138,13 +138,13 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void showDialog_sameMessage_keepExistingDialog() {
|
public void showDialog_sameMessage_keepExistingDialog() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNotNull();
|
assertThat(dialog).isNotNull();
|
||||||
assertThat(dialog.isShowing()).isTrue();
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
|
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
assertThat(dialog.isShowing()).isTrue();
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void showDialog_newMessage_keepAndUpdateDialog() {
|
public void showDialog_newMessage_keepAndUpdateDialog() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE1);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNotNull();
|
assertThat(dialog).isNotNull();
|
||||||
@@ -161,7 +161,7 @@ public class AudioSharingLoadingStateDialogFragmentTest {
|
|||||||
assertThat(view).isNotNull();
|
assertThat(view).isNotNull();
|
||||||
assertThat(view.getText().toString()).isEqualTo(TEST_MESSAGE1);
|
assertThat(view.getText().toString()).isEqualTo(TEST_MESSAGE1);
|
||||||
|
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParent, TEST_MESSAGE2);
|
AudioSharingProgressDialogFragment.show(mParent, TEST_MESSAGE2);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
assertThat(dialog.isShowing()).isTrue();
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
assertThat(view.getText().toString()).isEqualTo(TEST_MESSAGE2);
|
assertThat(view.getText().toString()).isEqualTo(TEST_MESSAGE2);
|
@@ -500,7 +500,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
|
|
||||||
verify(mBroadcast).startPrivateBroadcast();
|
verify(mBroadcast).startPrivateBroadcast();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
// No loading state dialog.
|
// No progress dialog.
|
||||||
assertThat(childFragments).isEmpty();
|
assertThat(childFragments).isEmpty();
|
||||||
|
|
||||||
mController.mBroadcastCallback.onPlaybackStarted(0, 0);
|
mController.mBroadcastCallback.onPlaybackStarted(0, 0);
|
||||||
@@ -531,7 +531,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
verify(mBroadcast).startPrivateBroadcast();
|
verify(mBroadcast).startPrivateBroadcast();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
|
|
||||||
mController.mBroadcastCallback.onPlaybackStarted(0, 0);
|
mController.mBroadcastCallback.onPlaybackStarted(0, 0);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
@@ -562,7 +562,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
verify(mBroadcast).startPrivateBroadcast();
|
verify(mBroadcast).startPrivateBroadcast();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
|
|
||||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||||
when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata);
|
when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata);
|
||||||
@@ -626,12 +626,12 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
verify(mBroadcast).startPrivateBroadcast();
|
verify(mBroadcast).startPrivateBroadcast();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
AudioSharingLoadingStateDialogFragment loadingFragment =
|
AudioSharingProgressDialogFragment progressFragment =
|
||||||
(AudioSharingLoadingStateDialogFragment) Iterables.getOnlyElement(childFragments);
|
(AudioSharingProgressDialogFragment) Iterables.getOnlyElement(childFragments);
|
||||||
// TODO: use string res once finalized
|
// TODO: use string res once finalized
|
||||||
String expectedMessage = "Starting audio stream...";
|
String expectedMessage = "Starting audio stream...";
|
||||||
checkLoadingStateDialogMessage(loadingFragment, expectedMessage);
|
checkProgressDialogMessage(progressFragment, expectedMessage);
|
||||||
|
|
||||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||||
when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata);
|
when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata);
|
||||||
@@ -642,13 +642,13 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
.action(any(Context.class), eq(SettingsEnums.ACTION_AUTO_JOIN_AUDIO_SHARING));
|
.action(any(Context.class), eq(SettingsEnums.ACTION_AUTO_JOIN_AUDIO_SHARING));
|
||||||
// TODO: use string res once finalized
|
// TODO: use string res once finalized
|
||||||
expectedMessage = "Sharing with " + TEST_DEVICE_NAME2 + "...";
|
expectedMessage = "Sharing with " + TEST_DEVICE_NAME2 + "...";
|
||||||
checkLoadingStateDialogMessage(loadingFragment, expectedMessage);
|
checkProgressDialogMessage(progressFragment, expectedMessage);
|
||||||
|
|
||||||
childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
.comparingElementsUsing(CLAZZNAME_EQUALS)
|
.comparingElementsUsing(CLAZZNAME_EQUALS)
|
||||||
.containsExactly(AudioSharingDialogFragment.class.getName(),
|
.containsExactly(AudioSharingDialogFragment.class.getName(),
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
|
|
||||||
Pair<Integer, Object>[] eventData = new Pair[0];
|
Pair<Integer, Object>[] eventData = new Pair[0];
|
||||||
for (Fragment fragment : childFragments) {
|
for (Fragment fragment : childFragments) {
|
||||||
@@ -708,15 +708,15 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
|
|
||||||
verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
||||||
assertThat(dialog.isShowing()).isFalse();
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
// Loading state dialog shows sharing state for the user chosen sink.
|
// Progress dialog shows sharing progress for the user chosen sink.
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
AudioSharingLoadingStateDialogFragment loadingFragment =
|
AudioSharingProgressDialogFragment progressFragment =
|
||||||
(AudioSharingLoadingStateDialogFragment) Iterables.getOnlyElement(childFragments);
|
(AudioSharingProgressDialogFragment) Iterables.getOnlyElement(childFragments);
|
||||||
// TODO: use string res once finalized
|
// TODO: use string res once finalized
|
||||||
String expectedMessage = "Sharing with " + TEST_DEVICE_NAME1 + "...";
|
String expectedMessage = "Sharing with " + TEST_DEVICE_NAME1 + "...";
|
||||||
checkLoadingStateDialogMessage(loadingFragment, expectedMessage);
|
checkProgressDialogMessage(progressFragment, expectedMessage);
|
||||||
|
|
||||||
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
|
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
|
||||||
}
|
}
|
||||||
@@ -749,15 +749,15 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
|
|
||||||
verify(mAssistant, never()).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
verify(mAssistant, never()).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
||||||
assertThat(dialog.isShowing()).isFalse();
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
// Loading state dialog shows sharing state for the auto add active sink.
|
// Progress dialog shows sharing progress for the auto add active sink.
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
AudioSharingLoadingStateDialogFragment loadingFragment =
|
AudioSharingProgressDialogFragment progressFragment =
|
||||||
(AudioSharingLoadingStateDialogFragment) Iterables.getOnlyElement(childFragments);
|
(AudioSharingProgressDialogFragment) Iterables.getOnlyElement(childFragments);
|
||||||
// TODO: use string res once finalized
|
// TODO: use string res once finalized
|
||||||
String expectedMessage = "Sharing with " + TEST_DEVICE_NAME2 + "...";
|
String expectedMessage = "Sharing with " + TEST_DEVICE_NAME2 + "...";
|
||||||
checkLoadingStateDialogMessage(loadingFragment, expectedMessage);
|
checkProgressDialogMessage(progressFragment, expectedMessage);
|
||||||
|
|
||||||
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
|
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
|
||||||
}
|
}
|
||||||
@@ -854,7 +854,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
mDevice1, mMetadata, /* reason= */ 1);
|
mDevice1, mMetadata, /* reason= */ 1);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
|
|
||||||
// Loading state dialog shows sharing state for the user chosen sink.
|
// Progress dialog shows sharing progress for the user chosen sink.
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingRetryDialogFragment.class.getName());
|
AudioSharingRetryDialogFragment.class.getName());
|
||||||
@@ -868,12 +868,12 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAssistantCallbacks_onReceiveStateChanged_dismissLoadingDialog() {
|
public void testAssistantCallbacks_onReceiveStateChanged_dismissProgressDialog() {
|
||||||
AudioSharingLoadingStateDialogFragment.show(mParentFragment, TEST_DEVICE_NAME1);
|
AudioSharingProgressDialogFragment.show(mParentFragment, TEST_DEVICE_NAME1);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
|
|
||||||
when(mState.getBisSyncState()).thenReturn(ImmutableList.of(1L));
|
when(mState.getBisSyncState()).thenReturn(ImmutableList.of(1L));
|
||||||
mController.mBroadcastAssistantCallback.onReceiveStateChanged(mDevice1, /* sourceId= */ 1,
|
mController.mBroadcastAssistantCallback.onReceiveStateChanged(mDevice1, /* sourceId= */ 1,
|
||||||
@@ -1023,13 +1023,13 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
List<Fragment> childFragments = parentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = parentFragment.getChildFragmentManager().getFragments();
|
||||||
// Skip audio sharing dialog.
|
// Skip audio sharing dialog.
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
// The loading state dialog shows sharing state for the auto add second sink.
|
// Progress dialog shows sharing progress for the auto add second sink.
|
||||||
AudioSharingLoadingStateDialogFragment loadingFragment =
|
AudioSharingProgressDialogFragment progressFragment =
|
||||||
(AudioSharingLoadingStateDialogFragment) Iterables.getOnlyElement(childFragments);
|
(AudioSharingProgressDialogFragment) Iterables.getOnlyElement(childFragments);
|
||||||
// TODO: use string res once finalized
|
// TODO: use string res once finalized
|
||||||
String expectedMessage = "Sharing with " + TEST_DEVICE_NAME1 + "...";
|
String expectedMessage = "Sharing with " + TEST_DEVICE_NAME1 + "...";
|
||||||
checkLoadingStateDialogMessage(loadingFragment, expectedMessage);
|
checkProgressDialogMessage(progressFragment, expectedMessage);
|
||||||
|
|
||||||
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
|
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
|
||||||
}
|
}
|
||||||
@@ -1044,7 +1044,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingLoadingStateDialogFragment.class.getName());
|
AudioSharingProgressDialogFragment.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Fragment setUpFragmentWithStartSharingIntent() {
|
private Fragment setUpFragmentWithStartSharingIntent() {
|
||||||
@@ -1064,12 +1064,12 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkLoadingStateDialogMessage(
|
private void checkProgressDialogMessage(
|
||||||
@NonNull AudioSharingLoadingStateDialogFragment fragment,
|
@NonNull AudioSharingProgressDialogFragment fragment,
|
||||||
@NonNull String expectedMessage) {
|
@NonNull String expectedMessage) {
|
||||||
TextView loadingMessage = fragment.getDialog() == null ? null
|
TextView progressMessage = fragment.getDialog() == null ? null
|
||||||
: fragment.getDialog().findViewById(R.id.message);
|
: fragment.getDialog().findViewById(R.id.message);
|
||||||
assertThat(loadingMessage).isNotNull();
|
assertThat(progressMessage).isNotNull();
|
||||||
assertThat(loadingMessage.getText().toString()).isEqualTo(expectedMessage);
|
assertThat(progressMessage.getText().toString()).isEqualTo(expectedMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user