Fixed an inconsistency in the updates listed after a repo update

This commit is contained in:
Ciaran Gultnieks 2010-12-14 22:54:07 +00:00 committed by Ciaran Gultnieks
parent bc556e0e2b
commit 24f5f0a5d8
3 changed files with 617 additions and 606 deletions

View File

@ -259,9 +259,20 @@ public class DB {
} }
} }
// Get the number of apps that have updates available.
public int getNumUpdates() {
Vector<App> apps = getApps(null, null, false);
int count = 0;
for (App app : apps) {
if (app.hasUpdates)
count++;
}
return count;
}
// Return a list of apps matching the given criteria. // Return a list of apps matching the given criteria.
// 'appid' - specific app id to retrieve, or null // 'appid' - specific app id to retrieve, or null
// 'filter' - search text to filter on. // 'filter' - search text to filter on, or null
// 'update' - update installed version information from device, rather than // 'update' - update installed version information from device, rather than
// simply using values cached in the database. Slower. // simply using values cached in the database. Slower.
public Vector<App> getApps(String appid, String filter, boolean update) { public Vector<App> getApps(String appid, String filter, boolean update) {
@ -386,7 +397,6 @@ public class DB {
} }
private Vector<App> updateApps = null; private Vector<App> updateApps = null;
private int updateNewUpdates;
// Called before a repo update starts. // Called before a repo update starts.
public void beginUpdate() { public void beginUpdate() {
@ -397,7 +407,6 @@ public class DB {
// TODO: Need to ensure that UI and UpdateService can't both be doing // TODO: Need to ensure that UI and UpdateService can't both be doing
// an update at the same time. // an update at the same time.
updateApps = getApps(null, null, true); updateApps = getApps(null, null, true);
updateNewUpdates = 0;
Log.d("FDroid", "AppUpdate: " + updateApps.size() Log.d("FDroid", "AppUpdate: " + updateApps.size()
+ " apps before starting."); + " apps before starting.");
} }
@ -405,11 +414,9 @@ public class DB {
// Called when a repo update ends. Any applications that have not been // Called when a repo update ends. Any applications that have not been
// updated (by a call to updateApplication) are assumed to be no longer // updated (by a call to updateApplication) are assumed to be no longer
// in the repos. // in the repos.
// Returns the number of new updates (installed applications for which public void endUpdate() {
// there is a new version available)
public int endUpdate() {
if (updateApps == null) if (updateApps == null)
return 0; return;
for (App app : updateApps) { for (App app : updateApps) {
if (!app.updated) { if (!app.updated) {
// The application hasn't been updated, so it's no longer // The application hasn't been updated, so it's no longer
@ -435,7 +442,7 @@ public class DB {
Log.d("FDroid", "AppUpdate: " + updateApps.size() Log.d("FDroid", "AppUpdate: " + updateApps.size()
+ " apps on completion."); + " apps on completion.");
updateApps = null; updateApps = null;
return updateNewUpdates; return;
} }
// Called during update to supply new details for an application (or // Called during update to supply new details for an application (or
@ -474,9 +481,6 @@ public class DB {
updateApkIfDifferent(null, upapk); updateApkIfDifferent(null, upapk);
upapk.updated = true; upapk.updated = true;
app.apks.add(upapk); app.apks.add(upapk);
if (!app.hasUpdates && app.installedVersion != null)
updateNewUpdates++;
app.hasUpdates = true;
} }
} }
break; break;

View File

@ -184,8 +184,7 @@ public class RepoXMLHandler extends DefaultHandler {
} }
} }
// Returns the number of applications with updates. public static void doUpdates(Context ctx, DB db) {
public static int doUpdates(Context ctx, DB db) {
db.beginUpdate(); db.beginUpdate();
Vector<DB.Repo> repos = db.getRepos(); Vector<DB.Repo> repos = db.getRepos();
for (DB.Repo repo : repos) { for (DB.Repo repo : repos) {
@ -236,7 +235,7 @@ public class RepoXMLHandler extends DefaultHandler {
} }
} }
return db.endUpdate(); db.endUpdate();
} }

View File

@ -106,12 +106,20 @@ public class UpdateService extends Service {
DB db = null; DB db = null;
try { try {
db = new DB(getBaseContext()); db = new DB(getBaseContext());
int updateNum = RepoXMLHandler.doUpdates(getBaseContext(), boolean notify = prefs.getBoolean("updateNotify", false);
db);
if (updateNum != 0) { // Get the number of updates available before we
// We have updates. // start, so we can notify if there are new ones.
if (prefs.getBoolean("updateNotify", false)) { // (But avoid doing it if the user doesn't want
// notifications, since it may be time consuming)
int prevUpdates = 0;
if (notify)
prevUpdates = db.getNumUpdates();
RepoXMLHandler.doUpdates(getBaseContext(), db);
if (notify) {
if (db.getNumUpdates() > prevUpdates) {
// And the user wants to know. // And the user wants to know.
NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification( Notification notification = new Notification(