CV == 0 means none recommended. No CV declared means latest compatible apk recommended.

This commit is contained in:
Daniel Martí 2013-07-23 18:19:04 +02:00
parent 0c1b854b69
commit 03ca3e0e05
2 changed files with 25 additions and 15 deletions

View File

@ -191,20 +191,14 @@ public class DB {
// most recent, if for example there are betas etc. // most recent, if for example there are betas etc.
public Apk getCurrentVersion() { public Apk getCurrentVersion() {
// Try and return the real current version first... // Try and return the real current version first. It will find the
// closest version smaller than the curVercode, being the same
// vercode if it exists.
if (curVercode > 0) { if (curVercode > 0) {
for (Apk apk : apks) {
if (apk.compatible && apk.vercode == curVercode)
return apk;
}
}
// If we don't know the current version, or we don't have it, we
// return the most recent version we have...
int latestcode = -1; int latestcode = -1;
Apk latestapk = null; Apk latestapk = null;
for (Apk apk : apks) { for (Apk apk : apks) {
if (apk.compatible &&apk.vercode < curVercode if (apk.compatible && apk.vercode <= curVercode
&& apk.vercode > latestcode) { && apk.vercode > latestcode) {
latestapk = apk; latestapk = apk;
latestcode = apk.vercode; latestcode = apk.vercode;
@ -213,6 +207,22 @@ public class DB {
return latestapk; return latestapk;
} }
// If the current version was not set we return the most recent apk.
if (curVercode == -1) {
int latestcode = -1;
Apk latestapk = null;
for (Apk apk : apks) {
if (apk.compatible && apk.vercode > latestcode) {
latestapk = apk;
latestcode = apk.vercode;
}
}
return latestapk;
}
return null;
}
@Override @Override
public int compareTo(App arg0) { public int compareTo(App arg0) {
return name.compareToIgnoreCase(arg0.name); return name.compareToIgnoreCase(arg0.name);

View File

@ -137,7 +137,7 @@ public class RepoXMLHandler extends DefaultHandler {
try { try {
curapk.vercode = Integer.parseInt(str); curapk.vercode = Integer.parseInt(str);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
curapk.vercode = 0; curapk.vercode = -1;
} }
} else if (curel.equals("size")) { } else if (curel.equals("size")) {
try { try {
@ -228,7 +228,7 @@ public class RepoXMLHandler extends DefaultHandler {
try { try {
curapp.curVercode = Integer.parseInt(str); curapp.curVercode = Integer.parseInt(str);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
curapp.curVercode = 0; curapp.curVercode = -1;
} }
} else if (curel.equals("antifeatures")) { } else if (curel.equals("antifeatures")) {
curapp.antiFeatures = DB.CommaSeparatedList.make(str); curapp.antiFeatures = DB.CommaSeparatedList.make(str);