Only refresh when deletion of device was confirmed

master
cpfeiffer 2016-09-30 21:54:16 +02:00
parent 5e63b7ce04
commit b890242c4f
1 changed files with 9 additions and 5 deletions

View File

@ -300,10 +300,11 @@ public class ControlCenter extends GBActivity {
return true; return true;
case R.id.controlcenter_delete_device: case R.id.controlcenter_delete_device:
if (selectedDevice != null) { if (selectedDevice != null) {
showDeleteDeviceDialog(selectedDevice); if (confirmDeleteDevice(selectedDevice)) {
selectedDevice = null; selectedDevice = null;
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST); Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
}
} }
return true; return true;
default: default:
@ -350,7 +351,8 @@ public class ControlCenter extends GBActivity {
startActivity(new Intent(this, DiscoveryActivity.class)); startActivity(new Intent(this, DiscoveryActivity.class));
} }
private void showDeleteDeviceDialog(final GBDevice gbDevice) { private boolean confirmDeleteDevice(final GBDevice gbDevice) {
final boolean[] result = new boolean[1];
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setCancelable(true) .setCancelable(true)
.setTitle(R.string.controlcenter_delete_device) .setTitle(R.string.controlcenter_delete_device)
@ -359,6 +361,7 @@ public class ControlCenter extends GBActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
deleteDevice(gbDevice); deleteDevice(gbDevice);
result[0] = true;
} }
}) })
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
@ -368,6 +371,7 @@ public class ControlCenter extends GBActivity {
} }
}) })
.show(); .show();
return result[0];
} }
private void deleteDevice(final GBDevice gbDevice) { private void deleteDevice(final GBDevice gbDevice) {