diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetProgressAction.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetProgressAction.java new file mode 100644 index 00000000..4dcc2120 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/btle/SetProgressAction.java @@ -0,0 +1,35 @@ +package nodomain.freeyourgadget.gadgetbridge.btle; + +import android.bluetooth.BluetoothGatt; +import android.content.Context; + +import nodomain.freeyourgadget.gadgetbridge.GB; + +public class SetProgressAction extends PlainAction { + + private String text; + private boolean ongoing; + private int percentage; + private final Context context; + + /** + * When run, will update the progress notification. + * @param text + * @param ongoing + * @param percentage + * @param context + */ + + public SetProgressAction(String text, boolean ongoing, int percentage, Context context) { + this.text = text; + this.ongoing = ongoing; + this.percentage = percentage; + this.context = context; + } + + @Override + public boolean run(BluetoothGatt gatt) { + GB.updateInstallNotification(this.text, this.ongoing, this.percentage, this.context); + return true; + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java index 31b989b4..61253996 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java @@ -30,6 +30,7 @@ import nodomain.freeyourgadget.gadgetbridge.btle.AbortTransactionAction; import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.btle.BtLEAction; import nodomain.freeyourgadget.gadgetbridge.btle.SetDeviceBusyAction; +import nodomain.freeyourgadget.gadgetbridge.btle.SetProgressAction; import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler; import nodomain.freeyourgadget.gadgetbridge.model.SampleProvider; @@ -906,7 +907,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { if ((i > 0) && (i % 50 == 0)) { builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[]{MiBandService.COMMAND_SYNC}); - GB.updateInstallNotification("Firmware update in progress", true, (firmwareProgress / len) * 100, getContext()); + builder.add(new SetProgressAction("Firmware update in progress", true, (firmwareProgress / len) * 100, getContext())); } LOG.info("Firmware update progress:" + firmwareProgress + " total len:" + len + " progress:" + (firmwareProgress / len)); @@ -922,7 +923,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { LOG.info("Firmware update progress:" + firmwareProgress + " total len:" + len + " progress:" + (firmwareProgress / len)); if (firmwareProgress >= len) { builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[]{MiBandService.COMMAND_SYNC}); - GB.updateInstallNotification("Firmware installation complete", false, 100, getContext()); + builder.add(new SetProgressAction("Firmware installation complete", false, 100, getContext())); } else { GB.updateInstallNotification("Firmware write failed", false, 0, getContext()); }