mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-07 15:05:25 +02:00
Improved error handling, display errors when deleting device
This commit is contained in:
parent
09502f96c9
commit
2a0d97b39a
@ -37,6 +37,7 @@ import java.util.List;
|
||||
import de.cketti.library.changelog.ChangeLog;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
||||
@ -354,12 +355,17 @@ public class ControlCenter extends GBActivity {
|
||||
.setPositiveButton(R.string.Delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try {
|
||||
deleteDevice(selectedDevice);
|
||||
DeviceHelper.getInstance().removeBond(selectedDevice);
|
||||
} catch (Exception ex) {
|
||||
GB.toast(ControlCenter.this, "Error deleting device: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
} finally {
|
||||
selectedDevice = null;
|
||||
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@ -370,7 +376,7 @@ public class ControlCenter extends GBActivity {
|
||||
.show();
|
||||
}
|
||||
|
||||
private void deleteDevice(final GBDevice gbDevice) {
|
||||
private void deleteDevice(final GBDevice gbDevice) throws GBException {
|
||||
LOG.info("will try to delete device: " + gbDevice.getName());
|
||||
if (gbDevice.isConnected() || gbDevice.isConnecting()) {
|
||||
GBApplication.deviceService().disconnect();
|
||||
@ -404,10 +410,10 @@ public class ControlCenter extends GBActivity {
|
||||
qb.where(DeviceAttributesDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
||||
session.getDeviceDao().delete(device);
|
||||
} else {
|
||||
LOG.warn("device not found while deleting");
|
||||
LOG.info("device to delete not found in db: " + gbDevice);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Database exception while deleting device " + e.getMessage());
|
||||
throw new GBException("Error deleting device: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
@ -243,7 +244,7 @@ public class DeviceHelper {
|
||||
* @param device
|
||||
* @return
|
||||
*/
|
||||
public boolean removeBond(GBDevice device) {
|
||||
public boolean removeBond(GBDevice device) throws GBException {
|
||||
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (defaultAdapter != null) {
|
||||
BluetoothDevice remoteDevice = defaultAdapter.getRemoteDevice(device.getAddress());
|
||||
@ -253,8 +254,7 @@ public class DeviceHelper {
|
||||
Object result = method.invoke(remoteDevice, (Object[]) null);
|
||||
return Boolean.TRUE.equals(result);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Error removing bond to device: " + device);
|
||||
return false;
|
||||
throw new GBException("Error removing bond to device: " + device, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user