From 082802cbba01168cf3b5334af8b7bbba2746e273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 28 Sep 2013 21:13:32 +0200 Subject: [PATCH] Fix remaining issues with notifications --- src/org/fdroid/fdroid/DB.java | 11 ----------- src/org/fdroid/fdroid/UpdateService.java | 24 ++++++++++++++++++------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/org/fdroid/fdroid/DB.java b/src/org/fdroid/fdroid/DB.java index 5d7f7e03e..319c37f5e 100644 --- a/src/org/fdroid/fdroid/DB.java +++ b/src/org/fdroid/fdroid/DB.java @@ -607,17 +607,6 @@ public class DB { } } - // Get the number of apps that have updates available. This can be a - // time consuming operation. - public int getNumUpdates(List apps) { - int count = 0; - for (App app : apps) { - if (!app.ignoreUpdates && app.hasUpdates) - count++; - } - return count; - } - public List getCategories() { List result = new ArrayList(); Cursor c = null; diff --git a/src/org/fdroid/fdroid/UpdateService.java b/src/org/fdroid/fdroid/UpdateService.java index c564f6091..64aa88c5f 100644 --- a/src/org/fdroid/fdroid/UpdateService.java +++ b/src/org/fdroid/fdroid/UpdateService.java @@ -100,6 +100,16 @@ public class UpdateService extends IntentService implements ProgressListener { return receiver == null; } + // Get the number of apps that have updates available. + public int getNumUpdates(List apps) { + int count = 0; + for (DB.App app : apps) { + if (!app.ignoreUpdates && app.hasUpdates) + count++; + } + return count; + } + protected void onHandleIntent(Intent intent) { receiver = intent.getParcelableExtra("receiver"); @@ -144,6 +154,7 @@ public class UpdateService extends IntentService implements ProgressListener { } // Process each repo... + List apps; List updatingApps = new ArrayList(); List keeprepos = new ArrayList(); boolean success = true; @@ -184,7 +195,7 @@ public class UpdateService extends IntentService implements ProgressListener { sendStatus(STATUS_INFO, getString(R.string.status_checking_compatibility)); - List apps = ((FDroidApp) getApplication()).getApps(); + apps = ((FDroidApp) getApplication()).getApps(); DB db = DB.getDB(); try { @@ -227,10 +238,6 @@ public class UpdateService extends IntentService implements ProgressListener { db.updateApplication(app); } db.endUpdate(); - if (notify) { - apps = ((FDroidApp) getApplication()).getApps(); - updates = db.getNumUpdates(apps); - } for (DB.Repo repo : repos) db.writeLastEtag(repo); } catch (Exception ex) { @@ -245,8 +252,13 @@ public class UpdateService extends IntentService implements ProgressListener { } - if (success && changes) + if (success && changes) { ((FDroidApp) getApplication()).invalidateAllApps(); + if (notify) { + apps = ((FDroidApp) getApplication()).getApps(); + updates = getNumUpdates(apps); + } + } if (success && changes && notify && updates > 0) { Log.d("FDroid", "Notifying "+updates+" updates.");