Bip: some code deduplication
parent
eaf7b76715
commit
c91e14f644
|
@ -16,34 +16,24 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.operations;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.operations;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipFWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.AmazfitBipSupport;
|
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.service.devices.miband2.operations.UpdateFirmwareOperation;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
|
||||||
|
|
||||||
public class AmazfitBipUpdateFirmwareOperation extends UpdateFirmwareOperation {
|
public class AmazfitBipUpdateFirmwareOperation extends UpdateFirmwareOperation {
|
||||||
public AmazfitBipUpdateFirmwareOperation(Uri uri, AmazfitBipSupport support) {
|
public AmazfitBipUpdateFirmwareOperation(Uri uri, AmazfitBipSupport support) {
|
||||||
super(uri, support);
|
super(uri, support);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doPerform() throws IOException {
|
|
||||||
AmazfitBipFWHelper mFwHelper = new AmazfitBipFWHelper(uri, getContext());
|
|
||||||
|
|
||||||
firmwareInfo = mFwHelper.getFirmwareInfo();
|
protected Mi2FirmwareInfo createFwInfo(Uri uri, Context context) throws IOException {
|
||||||
if (!firmwareInfo.isGenerallyCompatibleWith(getDevice())) {
|
AmazfitBipFWHelper fwHelper = new AmazfitBipFWHelper(uri, getContext());
|
||||||
throw new IOException("Firmware is not compatible with the given device: " + getDevice().getAddress());
|
return fwHelper.getFirmwareInfo();
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,9 +68,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPerform() throws IOException {
|
protected void doPerform() throws IOException {
|
||||||
MiBand2FWHelper mFwHelper = new MiBand2FWHelper(uri, getContext());
|
firmwareInfo = createFwInfo(uri, getContext());
|
||||||
|
|
||||||
firmwareInfo = mFwHelper.getFirmwareInfo();
|
|
||||||
if (!firmwareInfo.isGenerallyCompatibleWith(getDevice())) {
|
if (!firmwareInfo.isGenerallyCompatibleWith(getDevice())) {
|
||||||
throw new IOException("Firmware is not compatible with the given device: " + getDevice().getAddress());
|
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.
|
//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() {
|
protected void done() {
|
||||||
LOG.info("Operation done.");
|
LOG.info("Operation done.");
|
||||||
operationFinished();
|
operationFinished();
|
||||||
|
|
Loading…
Reference in New Issue