mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: Fix fetch notification progress
This GBProgressNotification API is not elegant and needs to be refactored.
This commit is contained in:
+7
-5
@@ -630,7 +630,11 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
if (!filesToDownload.isEmpty() && !fileTransferHandler.isDownloading()) {
|
||||
if (!gbDevice.isBusy()) {
|
||||
isBusyFetching = true;
|
||||
transferNotification.start(R.string.busy_task_fetch_activity_data, 0);
|
||||
transferNotification.start(
|
||||
R.string.busy_task_fetch_activity_data,
|
||||
0,
|
||||
filesToDownload.stream().mapToLong(FileTransferHandler.DirectoryEntry::getFileSize).sum()
|
||||
);
|
||||
getDevice().setBusyTask(R.string.busy_task_fetch_activity_data, getContext());
|
||||
getDevice().sendDeviceUpdateIntent(getContext());
|
||||
}
|
||||
@@ -691,8 +695,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
// isBusyFetching so we do not start multiple processors
|
||||
isBusyFetching = false;
|
||||
|
||||
transferNotification.start(R.string.busy_task_processing_files, 0);
|
||||
transferNotification.setTotalSize(filesToProcess.size());
|
||||
transferNotification.start(R.string.busy_task_processing_files, 0, filesToProcess.size());
|
||||
|
||||
final FitAsyncProcessor fitAsyncProcessor = new FitAsyncProcessor(getContext(), getDevice());
|
||||
fitAsyncProcessor.process(filesToProcess, new FitAsyncProcessor.Callback() {
|
||||
@@ -1066,8 +1069,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
|
||||
GB.toast(getContext(), "Check notification for progress", Toast.LENGTH_LONG, GB.INFO);
|
||||
|
||||
transferNotification.start(R.string.busy_task_processing_files, 0);
|
||||
transferNotification.setTotalSize(fitFiles.size());
|
||||
transferNotification.start(R.string.busy_task_processing_files, 0, fitFiles.size());
|
||||
|
||||
//try (DBHandler handler = GBApplication.acquireDB()) {
|
||||
// final DaoSession session = handler.getDaoSession();
|
||||
|
||||
+19
-15
@@ -62,13 +62,14 @@ class GBProgressNotification(
|
||||
*/
|
||||
fun start(
|
||||
@StringRes titleRes: Int,
|
||||
@StringRes textRes: Int
|
||||
@StringRes textRes: Int,
|
||||
totalSize: Long = 0
|
||||
) {
|
||||
this.titleRes = titleRes
|
||||
this.textRes = textRes
|
||||
this.chunkProgress = 0
|
||||
this.totalProgress = 0
|
||||
this.totalSize = 0
|
||||
this.totalSize = totalSize
|
||||
|
||||
LOG.debug(
|
||||
"Started notification id={}, title={}",
|
||||
@@ -119,21 +120,18 @@ class GBProgressNotification(
|
||||
}
|
||||
|
||||
fun getProgressPercentage(): Int {
|
||||
var percentage = 0f
|
||||
|
||||
if (totalSize != 0L) {
|
||||
percentage = ((totalProgress * 100) / totalSize.toFloat())
|
||||
|
||||
if (chunkProgress != 0L) {
|
||||
percentage += ((chunkProgress * 100) / totalSize.toFloat())
|
||||
}
|
||||
if (totalSize == 0L) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return percentage.roundToInt()
|
||||
return (((totalProgress + chunkProgress) * 100f) / totalSize).roundToInt()
|
||||
}
|
||||
|
||||
fun finish() {
|
||||
visible = false
|
||||
this.visible = false
|
||||
this.chunkProgress = 0
|
||||
this.totalProgress = 0
|
||||
this.totalSize = 0
|
||||
|
||||
LOG.debug("Finishing notification id={}", notificationId)
|
||||
|
||||
@@ -143,18 +141,24 @@ class GBProgressNotification(
|
||||
private fun refresh(force: Boolean) {
|
||||
val percentage = getProgressPercentage()
|
||||
|
||||
LOG.debug("Updating notification, percentage={}", percentage)
|
||||
|
||||
if (visible) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastNotificationUpdateTs < MIN_TIME_BETWEEN_UPDATES && !force) {
|
||||
LOG.debug("Throttling notification update")
|
||||
LOG.trace("Throttling notification update")
|
||||
return
|
||||
}
|
||||
|
||||
lastNotificationUpdateTs = now
|
||||
}
|
||||
|
||||
LOG.debug(
|
||||
"Updating notification, progress=({}+{})/{}, percentage={}",
|
||||
totalProgress,
|
||||
chunkProgress,
|
||||
totalSize,
|
||||
percentage
|
||||
)
|
||||
|
||||
visible = true
|
||||
|
||||
val title: CharSequence = if (titleRes != 0) context.getString(titleRes) else "Unknown transfer"
|
||||
|
||||
Reference in New Issue
Block a user