mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-17 12:50:54 +02:00
move installer progressbar from PebbleIoThread to GB and use that for Mi Band fw installation
This commit is contained in:
parent
9f591ef8b5
commit
732f26823b
@ -266,4 +266,36 @@ public class GB {
|
||||
.build();
|
||||
return df.format(duration, unit);
|
||||
}
|
||||
|
||||
private static Notification createInstallNotification(String text, boolean ongoing,
|
||||
int percentage, Context context) {
|
||||
Intent notificationIntent = new Intent(context, AppManagerActivity.class);
|
||||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
||||
notificationIntent, 0);
|
||||
|
||||
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setContentText(text)
|
||||
.setTicker(text)
|
||||
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setOngoing(ongoing);
|
||||
|
||||
if (ongoing) {
|
||||
nb.setProgress(100, percentage, percentage == 0);
|
||||
}
|
||||
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
public static void updateInstallNotification(String text, boolean ongoing, int percentage, Context context) {
|
||||
Notification notification = createInstallNotification(text, ongoing, percentage, context);
|
||||
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -900,10 +900,12 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
if ((i > 0) && (i % 50 == 0)) {
|
||||
if (!sendFirmwareSync()) {
|
||||
GB.updateInstallNotification("Firmware sync failed", false, 0, getContext());
|
||||
LOG.error("Firmware sync failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
GB.updateInstallNotification("Firmware update in progress", true, (firmwareProgress / len) * 100, getContext());
|
||||
LOG.info("Firmware update progress:" + firmwareProgress + " total lenL:" + len + " progress:" + firmwareProgress / len);
|
||||
}
|
||||
|
||||
@ -918,10 +920,14 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
LOG.info("Firmware update progress:" + firmwareProgress + " total lenL:" + len + " progress:" + firmwareProgress / len);
|
||||
if (firmwareProgress >= len) {
|
||||
GB.updateInstallNotification("Firmware installation complete", false, 100, getContext());
|
||||
} else {
|
||||
GB.updateInstallNotification("Firmware update in progress", true, (firmwareProgress / len) * 100, getContext());
|
||||
}
|
||||
|
||||
if (!sendFirmwareSync()) {
|
||||
LOG.error("Firmware sync failed");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@ -933,6 +939,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Unable to send fw packet to MI", ex);
|
||||
GB.updateInstallNotification("Firmware chunk write failed", false, 0, getContext());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -945,6 +952,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Unable to send firmware sync to MI", ex);
|
||||
GB.updateInstallNotification("Firmwar sync failed", false, 0, getContext());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -1,18 +1,13 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelUuid;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -24,7 +19,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@ -35,7 +30,6 @@ import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
||||
|
||||
public class PebbleIoThread extends GBDeviceIoThread {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PebbleIoThread.class);
|
||||
private static final int NOTIFICATION_ID = 2;
|
||||
private final PebbleProtocol mPebbleProtocol;
|
||||
private final PebbleSupport mPebbleSupport;
|
||||
private BluetoothAdapter mBtAdapter = null;
|
||||
@ -66,36 +60,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
mPebbleSupport = pebbleSupport;
|
||||
}
|
||||
|
||||
public static Notification createInstallNotification(String text, boolean ongoing,
|
||||
int percentage, Context context) {
|
||||
Intent notificationIntent = new Intent(context, AppManagerActivity.class);
|
||||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
||||
notificationIntent, 0);
|
||||
|
||||
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setContentText(text)
|
||||
.setTicker(text)
|
||||
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setOngoing(ongoing);
|
||||
|
||||
if (ongoing) {
|
||||
nb.setProgress(100, percentage, percentage == 0);
|
||||
}
|
||||
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
public static void updateInstallNotification(String text, boolean ongoing, int percentage, Context context) {
|
||||
Notification notification = createInstallNotification(text, ongoing, percentage, context);
|
||||
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean connect(String btDeviceAddress) {
|
||||
@ -175,7 +139,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
} while (bytes < 2000);
|
||||
|
||||
if (bytes > 0) {
|
||||
updateInstallNotification(getContext().getString(
|
||||
GB.updateInstallNotification(getContext().getString(
|
||||
R.string.installing_binary_d_d, (mCurrentInstallableIndex + 1), mPebbleInstallables.length), true, (int) (((float) mBytesWritten / mBinarySize) * 100), getContext());
|
||||
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
|
||||
mBytesWritten += bytes;
|
||||
@ -441,9 +405,9 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
return;
|
||||
}
|
||||
if (hadError) {
|
||||
updateInstallNotification(getContext().getString(R.string.installation_failed_), false, 0, getContext());
|
||||
GB.updateInstallNotification(getContext().getString(R.string.installation_failed_), false, 0, getContext());
|
||||
} else {
|
||||
updateInstallNotification(getContext().getString(R.string.installation_successful), false, 0, getContext());
|
||||
GB.updateInstallNotification(getContext().getString(R.string.installation_successful), false, 0, getContext());
|
||||
}
|
||||
mInstallState = PebbleAppInstallState.UNKNOWN;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user