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

View File

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

View File

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