1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-10-02 03:07:09 +02:00

Core: added subject to device update intent

This commit is contained in:
Daniel Dakhno 2022-09-23 02:57:08 +02:00 committed by Gitea
parent 26999c863b
commit dfc1f164b4
3 changed files with 18 additions and 3 deletions

View File

@ -65,6 +65,7 @@ public class GBDevice implements Parcelable {
private static final short BATTERY_THRESHOLD_PERCENT = 10;
public static final String EXTRA_DEVICE = "device";
public static final String EXTRA_UUID = "extraUUID";
public static final String EXTRA_UPDATE_SUBJECT = "EXTRA_UPDATE_SUBJECT";
private static final String DEVINFO_HW_VER = "HW: ";
private static final String DEVINFO_FW_VER = "FW: ";
private static final String DEVINFO_FW2_VER = "FW2: ";
@ -99,6 +100,12 @@ public class GBDevice implements Parcelable {
private int mNotificationIconDisconnected = R.drawable.ic_notification_disconnected;
private int mNotificationIconLowBattery = R.drawable.ic_notification_low_battery;
public static enum DeviceUbdateSubject {
UNKNOWN,
NOTHING,
CONNECTION_STATE
}
public GBDevice(String address, String name, String alias, String parentFolder, DeviceType deviceType) {
this(address, null, name, alias, parentFolder, deviceType);
}
@ -479,8 +486,14 @@ public class GBDevice implements Parcelable {
// TODO: this doesn't really belong here
public void sendDeviceUpdateIntent(Context context) {
sendDeviceUpdateIntent(context, DeviceUbdateSubject.UNKNOWN);
}
// TODO: this doesn't really belong here
public void sendDeviceUpdateIntent(Context context, DeviceUbdateSubject subject) {
Intent deviceUpdateIntent = new Intent(ACTION_DEVICE_CHANGED);
deviceUpdateIntent.putExtra(EXTRA_DEVICE, this);
deviceUpdateIntent.putExtra(EXTRA_UPDATE_SUBJECT, subject);
LocalBroadcastManager.getInstance(context).sendBroadcast(deviceUpdateIntent);
}

View File

@ -437,7 +437,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
}
updateReceiversState();
if(device.isInitialized()){
GBDevice.DeviceUbdateSubject subject = (GBDevice.DeviceUbdateSubject) intent.getSerializableExtra(GBDevice.EXTRA_UPDATE_SUBJECT);
if(subject == GBDevice.DeviceUbdateSubject.CONNECTION_STATE && device.isInitialized()){
sendDeviceConnectedBroadcast(device.getAddress());
}
}
@ -682,7 +684,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
switch (action) {
case ACTION_REQUEST_DEVICEINFO:
device.sendDeviceUpdateIntent(this);
device.sendDeviceUpdateIntent(this, GBDevice.DeviceUbdateSubject.NOTHING);
break;
case ACTION_NOTIFICATION: {
int desiredId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);

View File

@ -264,7 +264,7 @@ public final class BtLEQueue {
LOG.debug("new device connection state: " + newState);
mGbDevice.setState(newState);
mGbDevice.sendDeviceUpdateIntent(mContext);
mGbDevice.sendDeviceUpdateIntent(mContext, GBDevice.DeviceUbdateSubject.CONNECTION_STATE);
}
public void disconnect() {