From 6039cb3fea541a2cf310a43a8465137b7ec1c108 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Tue, 29 Jan 2013 14:39:04 +0530 Subject: [PATCH] Fix performance problems with notifications freezing the phone. I am a geraffe. --- commons/pom.xml | 2 +- .../wikimedia/commons/CommonsApplication.java | 2 ++ .../org/wikimedia/commons/UploadService.java | 23 ++++++++----------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/commons/pom.xml b/commons/pom.xml index 773205e57..841db0285 100644 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -19,7 +19,7 @@ org.mediawiki api - 1.1 + 1.2 com.actionbarsherlock diff --git a/commons/src/main/java/org/wikimedia/commons/CommonsApplication.java b/commons/src/main/java/org/wikimedia/commons/CommonsApplication.java index c5de14df4..af261b791 100644 --- a/commons/src/main/java/org/wikimedia/commons/CommonsApplication.java +++ b/commons/src/main/java/org/wikimedia/commons/CommonsApplication.java @@ -33,6 +33,8 @@ public class CommonsApplication extends Application { public void onCreate() { // TODO Auto-generated method stub super.onCreate(); + // Fire progress callbacks for every 3% of uploaded content + System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0"); api = createMWApi(); } diff --git a/commons/src/main/java/org/wikimedia/commons/UploadService.java b/commons/src/main/java/org/wikimedia/commons/UploadService.java index 33324f49e..46e71a074 100644 --- a/commons/src/main/java/org/wikimedia/commons/UploadService.java +++ b/commons/src/main/java/org/wikimedia/commons/UploadService.java @@ -55,9 +55,7 @@ public class UploadService extends IntentService { String notificationProgressTitle; String notificationFinishingTitle; - - private int lastPercent = 0; - + public NotificationUpdateProgressListener(Notification curNotification, String notificationTag, String notificationProgressTitle, String notificationFinishingTitle) { this.curNotification = curNotification; this.notificationTag = notificationTag; @@ -66,22 +64,21 @@ public class UploadService extends IntentService { } @Override public void onProgress(long transferred, long total) { + Log.d("Commons", String.format("Uploaded %d of %d", transferred, total)); RemoteViews curView = curNotification.contentView; if(!notificationTitleChanged) { curView.setTextViewText(R.id.uploadNotificationTitle, notificationProgressTitle); - notificationTitleChanged = false; - startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); + notificationTitleChanged = true; + notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); + return; } - int percent =(int) ((double)transferred / (double)total * 100); - if(percent > lastPercent) { - curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, percent, false); - startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); - lastPercent = percent; - } - if(percent == 100) { + if(transferred == total) { // Completed! curView.setTextViewText(R.id.uploadNotificationTitle, notificationFinishingTitle); - startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); + notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); + } else { + curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, (int)(((double)transferred / (double)total) * 100), false); + notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); } }