Don't crash when updating, handle "ignore this" between updates

This commit is contained in:
Daniel Martí 2013-10-13 21:29:03 +02:00
parent ef389b90e8
commit 6ada30118e
3 changed files with 27 additions and 33 deletions

View File

@ -123,9 +123,8 @@ public class AppDetails extends ListActivity {
v.setEnabled(apk.compatible); v.setEnabled(apk.compatible);
TextView tv = (TextView) v.findViewById(R.id.version); TextView tv = (TextView) v.findViewById(R.id.version);
boolean iscurrent = apk.vercode == app_currentvercode;
tv.setText(getString(R.string.version) + " " + apk.version tv.setText(getString(R.string.version) + " " + apk.version
+ (iscurrent ? " *" : "")); + (apk == app.curApk ? " *" : ""));
tv.setEnabled(apk.compatible); tv.setEnabled(apk.compatible);
tv = (TextView) v.findViewById(R.id.status); tv = (TextView) v.findViewById(R.id.status);
@ -187,14 +186,13 @@ public class AppDetails extends ListActivity {
private static final int DONATE_URL = Menu.FIRST + 13; private static final int DONATE_URL = Menu.FIRST + 13;
private DB.App app; private DB.App app;
private int app_currentvercode;
private String appid; private String appid;
private PackageManager mPm; private PackageManager mPm;
private DownloadHandler downloadHandler; private DownloadHandler downloadHandler;
private boolean stateRetained; private boolean stateRetained;
private boolean ignoreAllToggled; private boolean startingIgnoreAll;
private boolean ignoreThisToggled; private int startingIgnoreThis;
LinearLayout headerView; LinearLayout headerView;
View infoView; View infoView;
@ -265,9 +263,6 @@ public class AppDetails extends ListActivity {
pref_antiNonFreeNet = prefs.getBoolean("antiNonFreeNet", false); pref_antiNonFreeNet = prefs.getBoolean("antiNonFreeNet", false);
pref_antiNonFreeDep = prefs.getBoolean("antiNonFreeDep", false); pref_antiNonFreeDep = prefs.getBoolean("antiNonFreeDep", false);
ignoreAllToggled = false;
ignoreThisToggled = false;
startViews(); startViews();
} }
@ -342,7 +337,6 @@ public class AppDetails extends ListActivity {
if (old.downloadHandler != null) if (old.downloadHandler != null)
downloadHandler = new DownloadHandler(old.downloadHandler); downloadHandler = new DownloadHandler(old.downloadHandler);
app = old.app; app = old.app;
app_currentvercode = old.app_currentvercode;
mInstalledSignature = old.mInstalledSignature; mInstalledSignature = old.mInstalledSignature;
mInstalledSigID = old.mInstalledSigID; mInstalledSigID = old.mInstalledSigID;
} }
@ -381,7 +375,8 @@ public class AppDetails extends ListActivity {
DB.releaseDB(); DB.releaseDB();
} }
app_currentvercode = app.curApk == null ? 0 : app.curApk.vercode; startingIgnoreAll = app.ignoreAllUpdates;
startingIgnoreThis = app.ignoreThisUpdate;
// Get the signature of the installed package... // Get the signature of the installed package...
mInstalledSignature = null; mInstalledSignature = null;
@ -692,7 +687,7 @@ public class AppDetails extends ListActivity {
menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this) menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this)
.setIcon(android.R.drawable.ic_menu_close_clear_cancel) .setIcon(android.R.drawable.ic_menu_close_clear_cancel)
.setCheckable(true) .setCheckable(true)
.setChecked(app.ignoreThisUpdate); .setChecked(app.ignoreThisUpdate >= app.curApk.vercode);
} }
if (app.detail_webURL.length() > 0) { if (app.detail_webURL.length() > 0) {
menu.add(Menu.NONE, WEBSITE, 3, R.string.menu_website).setIcon( menu.add(Menu.NONE, WEBSITE, 3, R.string.menu_website).setIcon(
@ -766,13 +761,14 @@ public class AppDetails extends ListActivity {
case IGNOREALL: case IGNOREALL:
app.ignoreAllUpdates ^= true; app.ignoreAllUpdates ^= true;
item.setChecked(app.ignoreAllUpdates); item.setChecked(app.ignoreAllUpdates);
ignoreAllToggled ^= true;
return true; return true;
case IGNORETHIS: case IGNORETHIS:
app.ignoreThisUpdate ^= true; if (app.ignoreThisUpdate >= app.curApk.vercode)
item.setChecked(app.ignoreThisUpdate); app.ignoreThisUpdate = 0;
ignoreThisToggled ^= true; else
app.ignoreThisUpdate = app.curApk.vercode;
item.setChecked(app.ignoreThisUpdate > 0);
return true; return true;
case WEBSITE: case WEBSITE:
@ -1051,11 +1047,12 @@ public class AppDetails extends ListActivity {
@Override @Override
public void finish() { public void finish() {
if (ignoreAllToggled || ignoreThisToggled) { if (app.ignoreAllUpdates != startingIgnoreAll
|| app.ignoreThisUpdate != startingIgnoreThis) {
try { try {
DB db = DB.getDB(); DB db = DB.getDB();
db.toggleIgnoreUpdates(app.id, db.setIgnoreUpdates(app.id,
ignoreAllToggled, ignoreThisToggled); app.ignoreAllUpdates, app.ignoreThisUpdate);
} finally { } finally {
DB.releaseDB(); DB.releaseDB();
} }

View File

@ -129,7 +129,7 @@ public class DB {
detail_Populated = false; detail_Populated = false;
compatible = false; compatible = false;
ignoreAllUpdates = false; ignoreAllUpdates = false;
ignoreThisUpdate = false; ignoreThisUpdate = 0;
filtered = false; filtered = false;
iconUrl = null; iconUrl = null;
} }
@ -213,7 +213,7 @@ public class DB {
public boolean ignoreAllUpdates; public boolean ignoreAllUpdates;
// 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 int ignoreThisUpdate;
// Used internally for tracking during repo updates. // Used internally for tracking during repo updates.
public boolean updated; public boolean updated;
@ -440,7 +440,7 @@ public class DB {
public String lastetag; // last etag we updated from, null forces update public String lastetag; // last etag we updated from, null forces update
} }
private final int DBVersion = 26; private final int DBVersion = 27;
private static void createAppApk(SQLiteDatabase db) { private static void createAppApk(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_APP); db.execSQL(CREATE_TABLE_APP);
@ -787,7 +787,7 @@ public class DB {
.parse(sLastUpdated); .parse(sLastUpdated);
app.compatible = c.getInt(12) == 1; app.compatible = c.getInt(12) == 1;
app.ignoreAllUpdates = c.getInt(13) == 1; app.ignoreAllUpdates = c.getInt(13) == 1;
app.ignoreThisUpdate = c.getInt(14) == 1; app.ignoreThisUpdate = c.getInt(14);
app.hasUpdates = false; app.hasUpdates = false;
if (getinstalledinfo && systemApks.containsKey(app.id)) { if (getinstalledinfo && systemApks.containsKey(app.id)) {
@ -1151,13 +1151,10 @@ public class DB {
// Values to keep if already present // Values to keep if already present
if (oldapp == null) { if (oldapp == null) {
values.put("ignoreAllUpdates", upapp.ignoreAllUpdates ? 1 : 0); values.put("ignoreAllUpdates", upapp.ignoreAllUpdates ? 1 : 0);
values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0); values.put("ignoreThisUpdate", upapp.ignoreThisUpdate);
} else { } else {
values.put("ignoreAllUpdates", oldapp.ignoreAllUpdates ? 1 : 0); values.put("ignoreAllUpdates", oldapp.ignoreAllUpdates ? 1 : 0);
if (upapp.curApk.vercode > oldapp.curApk.vercode) values.put("ignoreThisUpdate", upapp.ignoreThisUpdate);
values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0);
else
values.put("ignoreThisUpdate", oldapp.ignoreThisUpdate ? 1 : 0);
} }
if (oldapp != null) { if (oldapp != null) {
@ -1265,10 +1262,10 @@ public class DB {
new String[] { address }); new String[] { address });
} }
public void toggleIgnoreUpdates(String appid, boolean All, boolean This) { public void setIgnoreUpdates(String appid, boolean All, int This) {
db.execSQL("update " + TABLE_APP + " set" db.execSQL("update " + TABLE_APP + " set"
+ (All ? "ignoreAllUpdates=1-ignoreAllUpdates " : "") + (All ? " ignoreAllUpdates="+All : "")
+ (This ? "ignoreThisUpdate=1-ignoreThisUpdate " : "") + (This>0 ? " ignoreThisUpdate="+This : "")
+ " where id = ?", new String[] { appid }); + " where id = ?", new String[] { appid });
} }

View File

@ -200,7 +200,7 @@ public class FDroidApp extends Application {
app.toUpdate = (app.hasUpdates app.toUpdate = (app.hasUpdates
&& !app.ignoreAllUpdates && !app.ignoreAllUpdates
&& !app.ignoreThisUpdate && app.curApk.vercode > app.ignoreThisUpdate
&& !app.filtered && !app.filtered
&& (showIncompatible || app.compatible)); && (showIncompatible || app.compatible));
} }