From c91e14f6449a5cbcba3ae146997c524e9b0e986b Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sat, 2 Sep 2017 21:45:56 +0200 Subject: [PATCH] Bip: some code deduplication --- .../AmazfitBipUpdateFirmwareOperation.java | 20 +++++-------------- .../operations/UpdateFirmwareOperation.java | 9 ++++++--- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/operations/AmazfitBipUpdateFirmwareOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/operations/AmazfitBipUpdateFirmwareOperation.java index a27c7ef0..48317d55 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/operations/AmazfitBipUpdateFirmwareOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/operations/AmazfitBipUpdateFirmwareOperation.java @@ -16,34 +16,24 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.operations; +import android.content.Context; import android.net.Uri; -import android.widget.Toast; import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipFWHelper; import nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.AmazfitBipSupport; +import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.Mi2FirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.UpdateFirmwareOperation; -import nodomain.freeyourgadget.gadgetbridge.util.GB; public class AmazfitBipUpdateFirmwareOperation extends UpdateFirmwareOperation { public AmazfitBipUpdateFirmwareOperation(Uri uri, AmazfitBipSupport support) { super(uri, support); } - @Override - protected void doPerform() throws IOException { - AmazfitBipFWHelper mFwHelper = new AmazfitBipFWHelper(uri, getContext()); - firmwareInfo = mFwHelper.getFirmwareInfo(); - if (!firmwareInfo.isGenerallyCompatibleWith(getDevice())) { - throw new IOException("Firmware is not compatible with the given device: " + getDevice().getAddress()); - } - - if (!sendFwInfo()) { - displayMessage(getContext(), "Error sending firmware info, aborting.", Toast.LENGTH_LONG, GB.ERROR); - done(); - } - //the firmware will be sent by the notification listener if the band confirms that the metadata are ok. + protected Mi2FirmwareInfo createFwInfo(Uri uri, Context context) throws IOException { + AmazfitBipFWHelper fwHelper = new AmazfitBipFWHelper(uri, getContext()); + return fwHelper.getFirmwareInfo(); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java index fd5793e8..b1d2e4bf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/operations/UpdateFirmwareOperation.java @@ -68,9 +68,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation { @Override protected void doPerform() throws IOException { - MiBand2FWHelper mFwHelper = new MiBand2FWHelper(uri, getContext()); - - firmwareInfo = mFwHelper.getFirmwareInfo(); + firmwareInfo = createFwInfo(uri, getContext()); if (!firmwareInfo.isGenerallyCompatibleWith(getDevice())) { throw new IOException("Firmware is not compatible with the given device: " + getDevice().getAddress()); } @@ -82,6 +80,11 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation { //the firmware will be sent by the notification listener if the band confirms that the metadata are ok. } + protected Mi2FirmwareInfo createFwInfo(Uri uri, Context context) throws IOException { + MiBand2FWHelper fwHelper = new MiBand2FWHelper(uri, context); + return fwHelper.getFirmwareInfo(); + } + protected void done() { LOG.info("Operation done."); operationFinished();