From 4dcf4199f13ef61563a18545cb9577f81f9fccd1 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Tue, 4 Jul 2017 19:05:04 +0200 Subject: [PATCH] Minor code refactoring --- .../updater/controller/UpdaterService.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index 66632666..d29ef9c6 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -90,21 +90,7 @@ public class UpdaterService extends Service { handleUpdateStatusChange(update); } else if (UpdaterController.ACTION_DOWNLOAD_PROGRESS.equals(intent.getAction())) { UpdateDownload update = mUpdaterController.getUpdate(downloadId); - int progress = update.getProgress(); - mNotificationBuilder.setProgress(100, progress, false); - - String percent = NumberFormat.getPercentInstance().format(progress / 100.f); - mNotificationStyle.setSummaryText(percent); - - mNotificationStyle.setBigContentTitle(update.getName()); - mNotificationBuilder.setContentTitle(update.getName()); - - String speed = Formatter.formatFileSize(context, update.getSpeed()); - CharSequence eta = DateUtils.formatDuration(update.getEta() * 1000); - mNotificationStyle.bigText( - getString(R.string.text_download_speed, eta, speed)); - - mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); + handleDownloadProgressChange(update); } } }; @@ -274,6 +260,24 @@ public class UpdaterService extends Service { } } + private void handleDownloadProgressChange(UpdateDownload update) { + int progress = update.getProgress(); + mNotificationBuilder.setProgress(100, progress, false); + + String percent = NumberFormat.getPercentInstance().format(progress / 100.f); + mNotificationStyle.setSummaryText(percent); + + mNotificationStyle.setBigContentTitle(update.getName()); + mNotificationBuilder.setContentTitle(update.getName()); + + String speed = Formatter.formatFileSize(this, update.getSpeed()); + CharSequence eta = DateUtils.formatDuration(update.getEta() * 1000); + mNotificationStyle.bigText( + getString(R.string.text_download_speed, eta, speed)); + + mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); + } + private PendingIntent getResumePendingIntent(String downloadId) { final Intent intent = new Intent(this, UpdaterService.class); intent.setAction(ACTION_DOWNLOAD_CONTROL);