Fix crash on unlink device when offline.

This commit is contained in:
henry 2020-05-23 13:00:40 +08:00 committed by Greyson Parrelli
parent 5ab72fd1a9
commit cfcd451db7

View File

@ -164,25 +164,29 @@ public class DeviceListFragment extends ListFragment
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private void handleDisconnectDevice(final long deviceId) { private void handleDisconnectDevice(final long deviceId) {
new ProgressDialogAsyncTask<Void, Void, Void>(getActivity(), new ProgressDialogAsyncTask<Void, Void, Boolean>(getActivity(),
R.string.DeviceListActivity_unlinking_device_no_ellipsis, R.string.DeviceListActivity_unlinking_device_no_ellipsis,
R.string.DeviceListActivity_unlinking_device) R.string.DeviceListActivity_unlinking_device)
{ {
@Override @Override
protected Void doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
try { try {
accountManager.removeDevice(deviceId); accountManager.removeDevice(deviceId);
return true;
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, e); Log.w(TAG, e);
Toast.makeText(getActivity(), R.string.DeviceListActivity_network_failed, Toast.LENGTH_LONG).show(); return false;
} }
return null;
} }
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Boolean result) {
super.onPostExecute(result); super.onPostExecute(result);
if (result) {
getLoaderManager().restartLoader(0, null, DeviceListFragment.this); getLoaderManager().restartLoader(0, null, DeviceListFragment.this);
} else {
Toast.makeText(getActivity(), R.string.DeviceListActivity_network_failed, Toast.LENGTH_LONG).show();
}
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }