1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Unset dynamic device state (like battery level, etc.) when disconnected

This commit is contained in:
cpfeiffer 2015-05-10 00:05:29 +02:00
parent 1a7c3c42e4
commit 39d84831ed
2 changed files with 13 additions and 4 deletions

View File

@ -23,6 +23,7 @@ public class GBDevice implements Parcelable {
};
private static final String TAG = GBDevice.class.getSimpleName();
public static final short RSSI_UNKNOWN = 0;
public static final short BATTERY_UNKNOWN = -1;
public static final String EXTRA_DEVICE = "device";
private final String mName;
private final String mAddress;
@ -30,7 +31,7 @@ public class GBDevice implements Parcelable {
private String mFirmwareVersion = null;
private String mHardwareVersion = null;
private State mState = State.NOT_CONNECTED;
private short mBatteryLevel = -1; // unknown
private short mBatteryLevel = BATTERY_UNKNOWN;
private String mBatteryState;
private short mRssi = RSSI_UNKNOWN;
@ -115,6 +116,14 @@ public class GBDevice implements Parcelable {
public void setState(State state) {
mState = state;
unsetDynamicState();
}
private void unsetDynamicState() {
setBatteryLevel(BATTERY_UNKNOWN);
setBatteryState(null);
setFirmwareVersion(null);
setRssi(RSSI_UNKNOWN);
}
public String getStateString() {
@ -195,9 +204,9 @@ public class GBDevice implements Parcelable {
}
/**
* Ranges from 0-100 (percent)
* Ranges from 0-100 (percent), or -1 if unknown
*
* @return the battery level in range 0-100
* @return the battery level in range 0-100, or -1 if unknown
*/
public short getBatteryLevel() {
return mBatteryLevel;

View File

@ -44,7 +44,7 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
deviceInfoLabel.setText(device.getInfoString());
short batteryLevel = device.getBatteryLevel();
if (batteryLevel > -1) {
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
batteryStatusLabel.setText("BAT: " + device.getBatteryLevel() + "%");
} else {
batteryStatusLabel.setText("");