From 9951991e5600226695cb880edc39031ef0546c44 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 7 Dec 2011 18:02:43 +0300 Subject: better download progress notification, prevent notification spam --- res/values/strings.xml | 3 ++- src/org/fox/ttrss/ImageCacheService.java | 24 ++++++++++++++++++++++++ src/org/fox/ttrss/OfflineDownloadService.java | 9 ++++++--- src/org/fox/ttrss/OfflineUploadService.java | 3 +++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 91b545d3..9a7adf46 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -103,7 +103,7 @@ Cancel Synchronizing offline data... Download unread articles and go offline? - Downloading articles... + Downloading articles (%1$d)... Starting download... Downloading feeds... Sending data to server... @@ -113,4 +113,5 @@ Offline mode Cache images Download images to sdcard. This might significantly increase time it takes to go offline. + Downloading images (%1$d)... \ No newline at end of file diff --git a/src/org/fox/ttrss/ImageCacheService.java b/src/org/fox/ttrss/ImageCacheService.java index 999b7437..94937b24 100644 --- a/src/org/fox/ttrss/ImageCacheService.java +++ b/src/org/fox/ttrss/ImageCacheService.java @@ -12,7 +12,9 @@ import java.util.Date; import android.app.ActivityManager; import android.app.IntentService; +import android.app.Notification; import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.ActivityManager.RunningServiceInfo; import android.content.Intent; import android.os.Environment; @@ -117,6 +119,26 @@ public class ImageCacheService extends IntentService { return null; } } + + private void updateNotification(String msg) { + Notification notification = new Notification(R.drawable.icon, + getString(R.string.notify_downloading_title), System.currentTimeMillis()); + + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, + new Intent(this, MainActivity.class), 0); + + notification.flags |= Notification.FLAG_ONGOING_EVENT; + notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; + + notification.setLatestEventInfo(this, getString(R.string.notify_downloading_title), msg, contentIntent); + + m_nmgr.notify(NOTIFY_DOWNLOADING, notification); + } + + private void updateNotification(int msgResId) { + updateNotification(getString(msgResId)); + } + @Override protected void onHandleIntent(Intent intent) { String url = intent.getStringExtra("url"); @@ -156,6 +178,8 @@ public class ImageCacheService extends IntentService { m_imagesDownloaded++; + updateNotification(getString(R.string.notify_downloading_images, m_imagesDownloaded)); + } catch (IOException e) { e.printStackTrace(); } diff --git a/src/org/fox/ttrss/OfflineDownloadService.java b/src/org/fox/ttrss/OfflineDownloadService.java index 489df927..ba5aba1f 100644 --- a/src/org/fox/ttrss/OfflineDownloadService.java +++ b/src/org/fox/ttrss/OfflineDownloadService.java @@ -75,6 +75,9 @@ public class OfflineDownloadService extends IntentService { PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); + notification.flags |= Notification.FLAG_ONGOING_EVENT; + notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; + notification.setLatestEventInfo(this, getString(R.string.notify_downloading_title), msg, contentIntent); m_nmgr.notify(NOTIFY_DOWNLOADING, notification); @@ -115,7 +118,7 @@ public class OfflineDownloadService extends IntentService { intent.addCategory(Intent.CATEGORY_DEFAULT); sendBroadcast(intent); } else { - updateNotification("Downloading images..."); + updateNotification(getString(R.string.notify_downloading_images, 0)); } m_readableDb.close(); @@ -140,6 +143,8 @@ public class OfflineDownloadService extends IntentService { private void downloadArticles() { Log.d(TAG, "offline: downloading articles... offset=" + m_articleOffset); + updateNotification(getString(R.string.notify_downloading_articles, m_articleOffset)); + OfflineArticlesRequest req = new OfflineArticlesRequest(this); @SuppressWarnings("serial") @@ -195,8 +200,6 @@ public class OfflineDownloadService extends IntentService { getWritableDb().execSQL("DELETE FROM articles;"); - updateNotification(R.string.notify_downloading_articles); - downloadArticles(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/org/fox/ttrss/OfflineUploadService.java b/src/org/fox/ttrss/OfflineUploadService.java index 90e0543b..9eb028ac 100644 --- a/src/org/fox/ttrss/OfflineUploadService.java +++ b/src/org/fox/ttrss/OfflineUploadService.java @@ -50,6 +50,9 @@ public class OfflineUploadService extends IntentService { PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); + notification.flags |= Notification.FLAG_ONGOING_EVENT; + notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; + notification.setLatestEventInfo(this, getString(R.string.notify_uploading_title), msg, contentIntent); m_nmgr.notify(NOTIFY_UPLOADING, notification); -- cgit v1.2.3