New feature: "Ignore This Update".

This commit is contained in:
Daniel Martí 2013-10-10 17:49:31 +02:00
parent 1e5cda97c3
commit f2500bec15
4 changed files with 70 additions and 40 deletions

View File

@ -88,7 +88,8 @@
<string name="menu_share">Share</string>
<string name="menu_install">Install</string>
<string name="menu_uninstall">Uninstall</string>
<string name="menu_ignore">Ignore Updates</string>
<string name="menu_ignore_all">Ignore All Updates</string>
<string name="menu_ignore_this">Ignore This Update</string>
<string name="menu_website">Website</string>
<string name="menu_issues">Issues</string>
<string name="menu_source">Source Code</string>

View File

@ -162,17 +162,18 @@ public class AppDetails extends ListActivity {
private static final int INSTALL = Menu.FIRST;
private static final int UNINSTALL = Menu.FIRST + 1;
private static final int IGNORE = Menu.FIRST + 2;
private static final int WEBSITE = Menu.FIRST + 3;
private static final int ISSUES = Menu.FIRST + 4;
private static final int SOURCE = Menu.FIRST + 5;
private static final int LAUNCH = Menu.FIRST + 6;
private static final int SHARE = Menu.FIRST + 7;
private static final int DONATE = Menu.FIRST + 8;
private static final int BITCOIN = Menu.FIRST + 9;
private static final int LITECOIN = Menu.FIRST + 10;
private static final int FLATTR = Menu.FIRST + 11;
private static final int DONATE_URL = Menu.FIRST + 12;
private static final int IGNOREALL = Menu.FIRST + 2;
private static final int IGNORETHIS = Menu.FIRST + 3;
private static final int WEBSITE = Menu.FIRST + 4;
private static final int ISSUES = Menu.FIRST + 5;
private static final int SOURCE = Menu.FIRST + 6;
private static final int LAUNCH = Menu.FIRST + 7;
private static final int SHARE = Menu.FIRST + 8;
private static final int DONATE = Menu.FIRST + 9;
private static final int BITCOIN = Menu.FIRST + 10;
private static final int LITECOIN = Menu.FIRST + 11;
private static final int FLATTR = Menu.FIRST + 12;
private static final int DONATE_URL = Menu.FIRST + 13;
private DB.App app;
private int app_currentvercode;
@ -181,7 +182,9 @@ public class AppDetails extends ListActivity {
private PackageManager mPm;
private DownloadHandler downloadHandler;
private boolean stateRetained;
private boolean ignoreToggled;
private boolean ignoreAllToggled;
private boolean ignoreThisToggled;
LinearLayout headerView;
View infoView;
@ -252,7 +255,8 @@ public class AppDetails extends ListActivity {
pref_antiNonFreeNet = prefs.getBoolean("antiNonFreeNet", false);
pref_antiNonFreeDep = prefs.getBoolean("antiNonFreeDep", false);
ignoreToggled = false;
ignoreAllToggled = false;
ignoreThisToggled = false;
startViews();
@ -662,11 +666,17 @@ public class AppDetails extends ListActivity {
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
menu.add(Menu.NONE, IGNORE, 2, R.string.menu_ignore)
.setIcon(android.R.drawable.ic_menu_add)
menu.add(Menu.NONE, IGNOREALL, 2, R.string.menu_ignore_all)
.setIcon(android.R.drawable.ic_menu_close_clear_cancel)
.setCheckable(true)
.setChecked(app.ignoreUpdates);
.setChecked(app.ignoreAllUpdates);
if (app.hasUpdates) {
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);
}
if (app.detail_webURL.length() > 0) {
menu.add(Menu.NONE, WEBSITE, 3, R.string.menu_website).setIcon(
android.R.drawable.ic_menu_view);
@ -733,10 +743,16 @@ public class AppDetails extends ListActivity {
removeApk(app.id);
return true;
case IGNORE:
app.ignoreUpdates ^= true;
item.setChecked(app.ignoreUpdates);
ignoreToggled ^= true;
case IGNOREALL:
app.ignoreAllUpdates ^= true;
item.setChecked(app.ignoreAllUpdates);
ignoreAllToggled ^= true;
return true;
case IGNORETHIS:
app.ignoreThisUpdate ^= true;
item.setChecked(app.ignoreThisUpdate);
ignoreThisToggled ^= true;
return true;
case WEBSITE:
@ -1015,10 +1031,11 @@ public class AppDetails extends ListActivity {
@Override
public void finish() {
if (ignoreToggled) {
if (ignoreAllToggled || ignoreThisToggled) {
try {
DB db = DB.getDB();
db.toggleIgnoreUpdates(app.id);
db.toggleIgnoreUpdates(app.id,
ignoreAllToggled, ignoreThisToggled);
} finally {
DB.releaseDB();
}

View File

@ -98,7 +98,9 @@ public class DB {
+ "flattrID string," + "requirements string,"
+ "category string," + "added string,"
+ "lastUpdated string," + "compatible int not null,"
+ "ignoreUpdates int not null," + "primary key(id));";
+ "ignoreAllUpdates int not null,"
+ "ignoreThisUpdate int not null,"
+ "primary key(id));";
public static class App implements Comparable<App> {
@ -125,7 +127,8 @@ public class DB {
apks = new ArrayList<Apk>();
detail_Populated = false;
compatible = false;
ignoreUpdates = false;
ignoreAllUpdates = false;
ignoreThisUpdate = false;
filtered = false;
iconUrl = null;
}
@ -204,9 +207,11 @@ public class DB {
// to be notified about them
public boolean toUpdate;
// True if updates should not show up in the Updates tab for this
// application
public boolean ignoreUpdates;
// True if all updates for this app are to be ignored
public boolean ignoreAllUpdates;
// True if the current update for this app is to be ignored
public boolean ignoreThisUpdate;
// The name of the version that would be updated to.
public String updateVersion;
@ -436,7 +441,7 @@ public class DB {
public String lastetag; // last etag we updated from, null forces update
}
private final int DBVersion = 25;
private final int DBVersion = 26;
private static void createAppApk(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_APP);
@ -758,7 +763,7 @@ public class DB {
String cols[] = new String[] { "antiFeatures", "requirements",
"id", "name", "summary", "icon", "license", "category",
"curVersion", "curVercode", "added", "lastUpdated",
"compatible", "ignoreUpdates" };
"compatible", "ignoreAllUpdates", "ignoreThisUpdate" };
c = db.query(TABLE_APP, cols, null, null, null, null, null);
c.moveToFirst();
while (!c.isAfterLast()) {
@ -782,7 +787,8 @@ public class DB {
.length() == 0) ? null : mDateFormat
.parse(sLastUpdated);
app.compatible = c.getInt(12) == 1;
app.ignoreUpdates = c.getInt(13) == 1;
app.ignoreAllUpdates = c.getInt(13) == 1;
app.ignoreThisUpdate = c.getInt(14) == 1;
app.hasUpdates = false;
if (getinstalledinfo && systemApks.containsKey(app.id)) {
@ -1147,9 +1153,14 @@ public class DB {
// Values to keep if already present
if (oldapp == null) {
values.put("ignoreUpdates", upapp.ignoreUpdates ? 1 : 0);
values.put("ignoreAllUpdates", upapp.ignoreAllUpdates ? 1 : 0);
values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0);
} else {
values.put("ignoreUpdates", oldapp.ignoreUpdates ? 1 : 0);
values.put("ignoreAllUpdates", oldapp.ignoreAllUpdates ? 1 : 0);
if (upapp.curVercode > oldapp.curVercode)
values.put("ignoreThisUpdate", upapp.ignoreThisUpdate ? 1 : 0);
else
values.put("ignoreThisUpdate", oldapp.ignoreThisUpdate ? 1 : 0);
}
if (oldapp != null) {
@ -1257,10 +1268,11 @@ public class DB {
new String[] { address });
}
public void toggleIgnoreUpdates(String appid) {
db.execSQL("update " + TABLE_APP
+ " set ignoreUpdates=1-ignoreUpdates where id = ?",
new String[] { appid });
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 updateRepoByAddress(Repo repo) {

View File

@ -198,9 +198,9 @@ public class FDroidApp extends Application {
for (DB.App app : apps) {
app.filtered = appFilter.filter(app);
app.toUpdate = (
!app.ignoreUpdates
&& app.hasUpdates
app.toUpdate = (app.hasUpdates
&& !app.ignoreAllUpdates
&& !app.ignoreThisUpdate
&& !app.filtered
&& (showIncompatible || app.compatible));
}