mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Bip: some code deduplication
This commit is contained in:
parent
eaf7b76715
commit
c91e14f644
@ -16,34 +16,24 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user