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

View File

@ -184,8 +184,7 @@ public class RepoXMLHandler extends DefaultHandler {
}
}
// Returns the number of applications with updates.
public static int doUpdates(Context ctx, DB db) {
public static void doUpdates(Context ctx, DB db) {
db.beginUpdate();
Vector<DB.Repo> repos = db.getRepos();
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;
try {
db = new DB(getBaseContext());
int updateNum = RepoXMLHandler.doUpdates(getBaseContext(),
db);
boolean notify = prefs.getBoolean("updateNotify", false);
if (updateNum != 0) {
// We have updates.
if (prefs.getBoolean("updateNotify", false)) {
// Get the number of updates available before we
// start, so we can notify if there are new ones.
// (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.
NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(