Only calculate the current Apk (recommended version) once

This commit is contained in:
Daniel Martí 2013-10-11 16:20:07 +02:00
parent f205b67cd5
commit 1d319009c4
3 changed files with 22 additions and 30 deletions

View File

@ -179,7 +179,6 @@ public class AppDetails extends ListActivity {
private DB.App app; private DB.App app;
private int app_currentvercode; private int app_currentvercode;
private DB.Apk curapk;
private String appid; private String appid;
private PackageManager mPm; private PackageManager mPm;
private DownloadHandler downloadHandler; private DownloadHandler downloadHandler;
@ -373,8 +372,7 @@ public class AppDetails extends ListActivity {
DB.releaseDB(); DB.releaseDB();
} }
DB.Apk curver = app.getCurrentVersion(); app_currentvercode = app.curApk == null ? 0 : app.curApk.vercode;
app_currentvercode = curver == null ? 0 : curver.vercode;
// Get the signature of the installed package... // Get the signature of the installed package...
mInstalledSignature = null; mInstalledSignature = null;
@ -599,10 +597,10 @@ public class AppDetails extends ListActivity {
@Override @Override
protected void onListItemClick(ListView l, View v, int position, long id) { protected void onListItemClick(ListView l, View v, int position, long id) {
curapk = app.apks.get(position - l.getHeaderViewsCount()); app.curApk = app.apks.get(position - l.getHeaderViewsCount());
if (app.installedVerCode == curapk.vercode) if (app.installedVerCode == app.curApk.vercode)
removeApk(app.id); removeApk(app.id);
else if (app.installedVerCode > curapk.vercode) { else if (app.installedVerCode > app.curApk.vercode) {
AlertDialog.Builder ask_alrt = new AlertDialog.Builder(this); AlertDialog.Builder ask_alrt = new AlertDialog.Builder(this);
ask_alrt.setMessage(getString(R.string.installDowngrade)); ask_alrt.setMessage(getString(R.string.installDowngrade));
ask_alrt.setPositiveButton(getString(R.string.yes), ask_alrt.setPositiveButton(getString(R.string.yes),
@ -632,7 +630,6 @@ public class AppDetails extends ListActivity {
menu.clear(); menu.clear();
if (app == null) if (app == null)
return true; return true;
DB.Apk curver = app.getCurrentVersion();
if (app.toUpdate) { if (app.toUpdate) {
MenuItemCompat.setShowAsAction(menu.add( MenuItemCompat.setShowAsAction(menu.add(
Menu.NONE, INSTALL, 0, R.string.menu_update) Menu.NONE, INSTALL, 0, R.string.menu_update)
@ -640,7 +637,7 @@ public class AppDetails extends ListActivity {
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_ALWAYS |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
} }
if (app.installedVersion == null && curver != null) { if (app.installedVersion == null && app.curApk != null) {
MenuItemCompat.setShowAsAction(menu.add( MenuItemCompat.setShowAsAction(menu.add(
Menu.NONE, INSTALL, 1, R.string.menu_install) Menu.NONE, INSTALL, 1, R.string.menu_install)
.setIcon(android.R.drawable.ic_menu_add), .setIcon(android.R.drawable.ic_menu_add),
@ -740,8 +737,7 @@ public class AppDetails extends ListActivity {
case INSTALL: case INSTALL:
// Note that this handles updating as well as installing. // Note that this handles updating as well as installing.
curapk = app.getCurrentVersion(); if (app.curApk != null)
if (curapk != null)
install(); install();
return true; return true;
@ -793,13 +789,13 @@ public class AppDetails extends ListActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
// Install the version of this app denoted by 'curapk'. // Install the version of this app denoted by 'app.curApk'.
private void install() { private void install() {
String ra = null; String ra = null;
try { try {
DB db = DB.getDB(); DB db = DB.getDB();
DB.Repo repo = db.getRepo(curapk.repo); DB.Repo repo = db.getRepo(app.curApk.repo);
if (repo != null) if (repo != null)
ra = repo.address; ra = repo.address;
} catch (Exception ex) { } catch (Exception ex) {
@ -811,14 +807,14 @@ public class AppDetails extends ListActivity {
return; return;
final String repoaddress = ra; final String repoaddress = ra;
if (!curapk.compatible) { if (!app.curApk.compatible) {
AlertDialog.Builder ask_alrt = new AlertDialog.Builder(this); AlertDialog.Builder ask_alrt = new AlertDialog.Builder(this);
ask_alrt.setMessage(getString(R.string.installIncompatible)); ask_alrt.setMessage(getString(R.string.installIncompatible));
ask_alrt.setPositiveButton(getString(R.string.yes), ask_alrt.setPositiveButton(getString(R.string.yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int whichButton) { int whichButton) {
downloadHandler = new DownloadHandler(curapk, downloadHandler = new DownloadHandler(app.curApk,
repoaddress, DB repoaddress, DB
.getDataPath(getBaseContext())); .getDataPath(getBaseContext()));
} }
@ -834,8 +830,8 @@ public class AppDetails extends ListActivity {
alert.show(); alert.show();
return; return;
} }
if (mInstalledSigID != null && curapk.sig != null if (mInstalledSigID != null && app.curApk.sig != null
&& !curapk.sig.equals(mInstalledSigID)) { && !app.curApk.sig.equals(mInstalledSigID)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.SignatureMismatch).setPositiveButton( builder.setMessage(R.string.SignatureMismatch).setPositiveButton(
getString(R.string.ok), getString(R.string.ok),
@ -848,7 +844,7 @@ public class AppDetails extends ListActivity {
alert.show(); alert.show();
return; return;
} }
downloadHandler = new DownloadHandler(curapk, repoaddress, downloadHandler = new DownloadHandler(app.curApk, repoaddress,
DB.getDataPath(this)); DB.getDataPath(this));
} }

View File

@ -177,6 +177,7 @@ public class DB {
public String curVersion; public String curVersion;
public int curVercode; public int curVercode;
public Apk curApk;
public Date added; public Date added;
public Date lastUpdated; public Date lastUpdated;
@ -213,9 +214,6 @@ public class DB {
// True if the current update for this app is to be ignored // True if the current update for this app is to be ignored
public boolean ignoreThisUpdate; public boolean ignoreThisUpdate;
// The name of the version that would be updated to.
public String updateVersion;
// Used internally for tracking during repo updates. // Used internally for tracking during repo updates.
public boolean updated; public boolean updated;
@ -864,12 +862,11 @@ public class DB {
// We'll say an application has updates if it's installed AND the // We'll say an application has updates if it's installed AND the
// version is older than the current one // version is older than the current one
for (App app : result) { for (App app : result) {
Apk curver = app.getCurrentVersion(); app.curApk = app.getCurrentVersion();
if (curver != null if (app.curApk != null
&& app.installedVerCode > 0 && app.installedVerCode > 0
&& app.installedVerCode < curver.vercode) { && app.installedVerCode < app.curApk.vercode) {
app.hasUpdates = true; app.hasUpdates = true;
app.updateVersion = curver.version;
} }
} }
} }
@ -921,12 +918,11 @@ public class DB {
} }
app.hasUpdates = false; app.hasUpdates = false;
Apk curver = app.getCurrentVersion(); app.curApk = app.getCurrentVersion();
if (curver != null if (app.curApk != null
&& app.installedVersion != null && app.installedVersion != null
&& app.installedVerCode < curver.vercode) { && app.installedVerCode < app.curApk.vercode) {
app.hasUpdates = true; app.hasUpdates = true;
app.updateVersion = curver.version;
} }
apps.set(index, app); apps.set(index, app);
@ -1157,7 +1153,7 @@ public class DB {
values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0); values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0);
} else { } else {
values.put("ignoreAllUpdates", oldapp.ignoreAllUpdates ? 1 : 0); values.put("ignoreAllUpdates", oldapp.ignoreAllUpdates ? 1 : 0);
if (upapp.curVercode > oldapp.curVercode) if (upapp.curApk.vercode > oldapp.curApk.vercode)
values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0); values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0);
else else
values.put("ignoreThisUpdate", oldapp.ignoreThisUpdate ? 1 : 0); values.put("ignoreThisUpdate", oldapp.ignoreThisUpdate ? 1 : 0);

View File

@ -154,7 +154,7 @@ abstract public class AppListAdapter extends BaseAdapter {
version.append(app.installedVersion); version.append(app.installedVersion);
if (app.toUpdate) { if (app.toUpdate) {
version.append(" -> "); version.append(" -> ");
version.append(app.updateVersion); version.append(app.curApk.version);
} }
} else { } else {
int numav = app.apks.size(); int numav = app.apks.size();