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 ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
||||
@Nullable
|
||||
private AlertDialog mLoadingDialog = null;
|
||||
private AlertDialog mProgressDialog = null;
|
||||
@VisibleForTesting
|
||||
boolean mShouldTriggerAudioSharingShareThenPairFlow = false;
|
||||
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.
|
||||
// The BluetoothDevicePreference summary will be blank for seconds between "Pairing..." and
|
||||
// "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.
|
||||
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
||||
new BluetoothAdapter.OnMetadataChangedListener() {
|
||||
@@ -97,7 +97,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
public void onMetadataChanged(@NonNull BluetoothDevice device, int key,
|
||||
@Nullable byte[] value) {
|
||||
Log.d(getLogTag(), "onMetadataChanged device = " + device + ", key = " + key);
|
||||
if (mShouldTriggerAudioSharingShareThenPairFlow && mLoadingDialog == null
|
||||
if (mShouldTriggerAudioSharingShareThenPairFlow && mProgressDialog == null
|
||||
&& device.getBondState() == BluetoothDevice.BOND_BONDED
|
||||
&& mSelectedList.contains(device)) {
|
||||
triggerAudioSharingShareThenPairFlow(device);
|
||||
@@ -355,7 +355,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
return;
|
||||
}
|
||||
mJustBonded = device;
|
||||
// Show connecting device loading state
|
||||
// Show connecting device progress
|
||||
String aliasName = device.getAlias();
|
||||
String deviceName = TextUtils.isEmpty(aliasName) ? device.getAddress()
|
||||
: aliasName;
|
||||
@@ -387,9 +387,9 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
// TODO: use DialogFragment
|
||||
private void showConnectingDialog(@NonNull String message) {
|
||||
postOnMainThread(() -> {
|
||||
if (mLoadingDialog != null) {
|
||||
if (mProgressDialog != null) {
|
||||
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())) {
|
||||
Log.d(getLogTag(), "showConnectingDialog, update message");
|
||||
// TODO: use string res once finalized
|
||||
@@ -401,7 +401,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
||||
View customView = inflater.inflate(
|
||||
R.layout.dialog_audio_sharing_loading_state, /* root= */
|
||||
R.layout.dialog_audio_sharing_progress, /* root= */
|
||||
null);
|
||||
TextView textView = customView.findViewById(R.id.message);
|
||||
if (textView != null) {
|
||||
@@ -410,15 +410,15 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
}
|
||||
AlertDialog dialog = builder.setView(customView).setCancelable(false).create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
mLoadingDialog = dialog;
|
||||
mProgressDialog = dialog;
|
||||
dialog.show();
|
||||
});
|
||||
}
|
||||
|
||||
private void dismissConnectingDialog() {
|
||||
postOnMainThread(() -> {
|
||||
if (mLoadingDialog != null) {
|
||||
mLoadingDialog.dismiss();
|
||||
if (mProgressDialog != null) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ import com.google.common.base.Strings;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "AudioSharingLoadingDlg";
|
||||
public class AudioSharingProgressDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "AudioSharingProgressDlg";
|
||||
|
||||
private static final String BUNDLE_KEY_MESSAGE = "bundle_key_message";
|
||||
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 message The content to be shown on the dialog.
|
||||
@@ -85,16 +85,15 @@ public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFr
|
||||
return;
|
||||
}
|
||||
sMessage = message;
|
||||
Log.d(TAG, "Show up the loading dialog.");
|
||||
Log.d(TAG, "Show up the progress dialog.");
|
||||
Bundle args = new Bundle();
|
||||
args.putString(BUNDLE_KEY_MESSAGE, message);
|
||||
AudioSharingLoadingStateDialogFragment dialogFrag =
|
||||
new AudioSharingLoadingStateDialogFragment();
|
||||
AudioSharingProgressDialogFragment dialogFrag = new AudioSharingProgressDialogFragment();
|
||||
dialogFrag.setArguments(args);
|
||||
dialogFrag.show(manager, TAG);
|
||||
}
|
||||
|
||||
/** Dismiss the {@link AudioSharingLoadingStateDialogFragment} dialog. */
|
||||
/** Dismiss the {@link AudioSharingProgressDialogFragment} dialog. */
|
||||
public static void dismiss(@Nullable Fragment host) {
|
||||
if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
@@ -119,7 +118,7 @@ public class AudioSharingLoadingStateDialogFragment extends InstrumentedDialogFr
|
||||
String message = args.getString(BUNDLE_KEY_MESSAGE, "");
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
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);
|
||||
TextView textView = customView.findViewById(R.id.message);
|
||||
if (!Strings.isNullOrEmpty(message)) textView.setText(message);
|
||||
@@ -315,7 +315,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
if (mSinksInAdding.contains(sink)) {
|
||||
mSinksInAdding.remove(sink);
|
||||
}
|
||||
dismissLoadingStateDialogIfNeeded();
|
||||
dismissProgressDialogIfNeeded();
|
||||
Log.d(TAG, "onReceiveStateChanged() connected, sink = " + sink
|
||||
+ ", remaining sinks = " + mSinksInAdding);
|
||||
if (mSinksToWaitFor.contains(sink)) {
|
||||
@@ -573,7 +573,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
mSinksInAdding.clear();
|
||||
// TODO: use string res once finalized.
|
||||
AudioSharingUtils.postOnMainThread(mContext,
|
||||
() -> AudioSharingLoadingStateDialogFragment.show(mFragment,
|
||||
() -> AudioSharingProgressDialogFragment.show(mFragment,
|
||||
"Starting audio stream..."));
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext,
|
||||
@@ -690,7 +690,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
if (mFragment == null) {
|
||||
Log.d(TAG, "handleOnBroadcastReady: dialog fail to show due to null fragment.");
|
||||
// Clean up states before early return.
|
||||
dismissLoadingStateDialogIfNeeded();
|
||||
dismissProgressDialogIfNeeded();
|
||||
cleanUpStatesForStartSharing();
|
||||
return;
|
||||
}
|
||||
@@ -711,8 +711,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
new AudioSharingDialogFragment.DialogEventListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
// Could go to other pages, dismiss the loading dialog.
|
||||
dismissLoadingStateDialogIfNeeded();
|
||||
// Could go to other pages, dismiss the progress dialog.
|
||||
dismissProgressDialogIfNeeded();
|
||||
cleanUpStatesForStartSharing();
|
||||
}
|
||||
|
||||
@@ -726,8 +726,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public void onCancelClick() {
|
||||
// Could go to other pages, dismiss the loading dialog.
|
||||
dismissLoadingStateDialogIfNeeded();
|
||||
// Could go to other pages, dismiss the progress dialog.
|
||||
dismissProgressDialogIfNeeded();
|
||||
cleanUpStatesForStartSharing();
|
||||
}
|
||||
};
|
||||
@@ -831,20 +831,20 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
@NonNull String sinkName) {
|
||||
mSinksInAdding.addAll(targetActiveSinks);
|
||||
// TODO: move to res once finalized
|
||||
String loadingMessage = "Sharing with " + sinkName + "...";
|
||||
showLoadingStateDialog(loadingMessage);
|
||||
String progressMessage = "Sharing with " + sinkName + "...";
|
||||
showProgressDialog(progressMessage);
|
||||
AudioSharingUtils.addSourceToTargetSinks(targetActiveSinks, mBtManager);
|
||||
}
|
||||
|
||||
private void showLoadingStateDialog(@NonNull String loadingMessage) {
|
||||
private void showProgressDialog(@NonNull String progressMessage) {
|
||||
AudioSharingUtils.postOnMainThread(mContext,
|
||||
() -> AudioSharingLoadingStateDialogFragment.show(mFragment, loadingMessage));
|
||||
() -> AudioSharingProgressDialogFragment.show(mFragment, progressMessage));
|
||||
}
|
||||
|
||||
private void dismissLoadingStateDialogIfNeeded() {
|
||||
private void dismissProgressDialogIfNeeded() {
|
||||
if (mSinksInAdding.isEmpty()) {
|
||||
AudioSharingUtils.postOnMainThread(mContext,
|
||||
() -> AudioSharingLoadingStateDialogFragment.dismiss(mFragment));
|
||||
() -> AudioSharingProgressDialogFragment.dismiss(mFragment));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user