Change setting "Incompatible apps" to "Incompatible versions"

Rather large rewrite, basically doing:
* Always show incompatible apps
* Don't fetch incompatible apks if the new setting is off
* Start using result codes when returning from PreferencesActivity
This commit is contained in:
Daniel Martí 2013-11-02 18:27:02 +01:00
parent 6a62b7979e
commit ed49eced45
8 changed files with 80 additions and 88 deletions

View File

@ -117,8 +117,8 @@
<string name="db_sync_mode_long">Set the value of SQLite\'s "synchronous" flag</string> <string name="db_sync_mode_long">Set the value of SQLite\'s "synchronous" flag</string>
<string name="appcompatibility">Application compatibility</string> <string name="appcompatibility">Application compatibility</string>
<string name="showincompat">Incompatible apps</string> <string name="show_incompat_versions">Incompatible versions</string>
<string name="showincompat_long">Show apps written for newer Android versions or different hardware</string> <string name="show_incompat_versions_l">Show versions of apps that are incompatible with the device</string>
<string name="rooted">Root</string> <string name="rooted">Root</string>
<string name="rooted_long">Show apps that require root privileges</string> <string name="rooted_long">Show apps that require root privileges</string>
<string name="ignoreTouch">Ignore Touchscreen</string> <string name="ignoreTouch">Ignore Touchscreen</string>

View File

@ -28,9 +28,9 @@
android:key="compactlayout"/> android:key="compactlayout"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/appcompatibility"> <PreferenceCategory android:title="@string/appcompatibility">
<CheckBoxPreference android:title="@string/showincompat" <CheckBoxPreference android:title="@string/show_incompat_versions"
android:defaultValue="false" android:summary="@string/showincompat_long" android:defaultValue="false" android:summary="@string/show_incompat_versions_l"
android:key="showIncompatible" /> android:key="incompatibleVersions" />
<CheckBoxPreference android:title="@string/rooted" <CheckBoxPreference android:title="@string/rooted"
android:defaultValue="true" android:summary="@string/rooted_long" android:defaultValue="true" android:summary="@string/rooted_long"
android:key="rooted" /> android:key="rooted" />

View File

@ -232,13 +232,6 @@ public class AppDetails extends ListActivity {
appid = i.getStringExtra("appid"); appid = i.getStringExtra("appid");
} }
// Set up the list...
headerView = new LinearLayout(this);
ListView lv = (ListView) findViewById(android.R.id.list);
lv.addHeaderView(headerView);
ApkListAdapter la = new ApkListAdapter(this, null);
setListAdapter(la);
mPm = getPackageManager(); mPm = getPackageManager();
// Get the preferences we're going to use in this Activity... // Get the preferences we're going to use in this Activity...
AppDetails old = (AppDetails) getLastNonConfigurationInstance(); AppDetails old = (AppDetails) getLastNonConfigurationInstance();
@ -252,11 +245,17 @@ public class AppDetails extends ListActivity {
resetRequired = false; resetRequired = false;
} }
// Set up the list...
headerView = new LinearLayout(this);
ListView lv = (ListView) findViewById(android.R.id.list);
lv.addHeaderView(headerView);
ApkListAdapter la = new ApkListAdapter(this, app.apks);
setListAdapter(la);
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
pref_expert = prefs.getBoolean("expert", false); pref_expert = prefs.getBoolean("expert", false);
pref_permissions = prefs.getBoolean("showPermissions", false); pref_permissions = prefs.getBoolean("showPermissions", false);
pref_incompatible = prefs.getBoolean("showIncompatible", false);
startViews(); startViews();
@ -264,7 +263,6 @@ public class AppDetails extends ListActivity {
private boolean pref_expert; private boolean pref_expert;
private boolean pref_permissions; private boolean pref_permissions;
private boolean pref_incompatible;
private boolean resetRequired; private boolean resetRequired;
// The signature of the installed version. // The signature of the installed version.
@ -391,13 +389,6 @@ public class AppDetails extends ListActivity {
private void startViews() { private void startViews() {
// Populate the list...
ApkListAdapter la = (ApkListAdapter) getListAdapter();
for (DB.Apk apk : app.apks)
if (pref_incompatible || apk.compatible)
la.addItem(apk);
la.notifyDataSetChanged();
// Insert the 'infoView' (which contains the summary, various odds and // Insert the 'infoView' (which contains the summary, various odds and
// ends, and the description) into the appropriate place, if we're in // ends, and the description) into the appropriate place, if we're in
// landscape mode. In portrait mode, we put it in the listview's // landscape mode. In portrait mode, we put it in the listview's

View File

@ -184,9 +184,6 @@ public class AppListManager {
private boolean updateApps() { private boolean updateApps() {
allApps = ((FDroidApp)fdroidActivity.getApplication()).getApps(); allApps = ((FDroidApp)fdroidActivity.getApplication()).getApps();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(fdroidActivity.getBaseContext());
boolean showIncompatible = prefs.getBoolean("showIncompatible", false);
if (allApps.isEmpty()) { if (allApps.isEmpty()) {
// If its the first time we've run the app, this should update // If its the first time we've run the app, this should update
@ -201,8 +198,7 @@ public class AppListManager {
// Add it to the list(s). Always to installed and updates, but // Add it to the list(s). Always to installed and updates, but
// only to available if it's not filtered. // only to available if it's not filtered.
if (!app.filtered && (showIncompatible || app.compatible) if (isInCategory(app, currentCategory, recentDate)) {
&& isInCategory(app, currentCategory, recentDate)) {
availApps.add(app); availApps.add(app);
} }
if (app.installedVersion != null) { if (app.installedVersion != null) {

View File

@ -819,6 +819,11 @@ public class DB {
Log.d("FDroid", "Read app data from database " + " (took " Log.d("FDroid", "Read app data from database " + " (took "
+ (System.currentTimeMillis() - startTime) + " ms)"); + (System.currentTimeMillis() - startTime) + " ms)");
List<Repo> repos = getRepos();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(mContext);
boolean incompatibleVersions = prefs
.getBoolean("incompatibleVersions", false);
cols = new String[] { "id", "version", "vercode", "sig", "srcname", cols = new String[] { "id", "version", "vercode", "sig", "srcname",
"apkName", "minSdkVersion", "added", "features", "nativecode", "apkName", "minSdkVersion", "added", "features", "nativecode",
"compatible", "repo" }; "compatible", "repo" };
@ -826,22 +831,37 @@ public class DB {
"vercode desc"); "vercode desc");
c.moveToFirst(); c.moveToFirst();
while (!c.isAfterLast()) { while (!c.isAfterLast()) {
Apk apk = new Apk(); String id = c.getString(0);
apk.id = c.getString(0); App app = apps.get(id);
apk.version = c.getString(1); boolean compatible = c.getInt(10) == 1;
apk.vercode = c.getInt(2); int repoid = c.getInt(11);
apk.sig = c.getString(3); if (compatible || incompatibleVersions) {
apk.srcname = c.getString(4); Apk apk = new Apk();
apk.apkName = c.getString(5); apk.id = id;
apk.minSdkVersion = c.getInt(6); apk.version = c.getString(1);
String sApkAdded = c.getString(7); apk.vercode = c.getInt(2);
apk.added = (sApkAdded == null || sApkAdded.length() == 0) ? null apk.sig = c.getString(3);
: mDateFormat.parse(sApkAdded); apk.srcname = c.getString(4);
apk.features = CommaSeparatedList.make(c.getString(8)); apk.apkName = c.getString(5);
apk.nativecode = CommaSeparatedList.make(c.getString(9)); apk.minSdkVersion = c.getInt(6);
apk.compatible = c.getInt(10) == 1; String sApkAdded = c.getString(7);
apk.repo = c.getInt(11); apk.added = (sApkAdded == null || sApkAdded.length() == 0) ? null
apps.get(apk.id).apks.add(apk); : mDateFormat.parse(sApkAdded);
apk.features = CommaSeparatedList.make(c.getString(8));
apk.nativecode = CommaSeparatedList.make(c.getString(9));
apk.compatible = compatible;
apk.repo = repoid;
app.apks.add(apk);
}
if (app.iconUrl == null && app.icon != null) {
for (DB.Repo repo : repos) {
if (repo.id == repoid) {
app.iconUrl =
repo.address + "/icons/" + app.icon;
break;
}
}
}
c.moveToNext(); c.moveToNext();
} }
c.close(); c.close();
@ -1065,12 +1085,10 @@ public class DB {
// Called during update to supply new details for an application (or // Called during update to supply new details for an application (or
// details of a completely new one). Calls to this must be wrapped by // details of a completely new one). Calls to this must be wrapped by
// a call to beginUpdate and a call to endUpdate. // a call to beginUpdate and a call to endUpdate.
// Returns true if the app was accepted. If it wasn't, it's probably public void updateApplication(App upapp) {
// because it's not compatible with the device.
public boolean updateApplication(App upapp) {
if (updateApps == null) { if (updateApps == null) {
return false; return;
} }
// Lazy initialise this... // Lazy initialise this...
@ -1125,7 +1143,6 @@ public class DB {
upapp.updated = true; upapp.updated = true;
updateApps.add(upapp); updateApps.add(upapp);
} }
return true;
} }

View File

@ -234,13 +234,18 @@ public class FDroid extends FragmentActivity {
} }
break; break;
case REQUEST_PREFS: case REQUEST_PREFS:
((FDroidApp) getApplication()).filterApps();
// The automatic update settings may have changed, so reschedule (or // The automatic update settings may have changed, so reschedule (or
// unschedule) the service accordingly. It's cheap, so no need to // unschedule) the service accordingly. It's cheap, so no need to
// check if the particular setting has actually been changed. // check if the particular setting has actually been changed.
UpdateService.schedule(getBaseContext()); UpdateService.schedule(getBaseContext());
break;
if ((resultCode & PreferencesActivity.RESULT_RELOAD) != 0) {
((FDroidApp) getApplication()).invalidateAllApps();
} else if ((resultCode & PreferencesActivity.RESULT_REFILTER) != 0) {
((FDroidApp) getApplication()).filterApps();
}
break;
} }
} }

View File

@ -58,7 +58,6 @@ public class FDroidApp extends Application {
// because the install intent says it's finished when it hasn't. // because the install intent says it's finished when it hasn't.
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
showIncompatible = prefs.getBoolean("showIncompatible", false);
if (!prefs.getBoolean("cacheDownloaded", false)) { if (!prefs.getBoolean("cacheDownloaded", false)) {
File local_path = DB.getDataPath(this); File local_path = DB.getDataPath(this);
@ -110,8 +109,6 @@ public class FDroidApp extends Application {
// Global list of all known applications. // Global list of all known applications.
private List<DB.App> apps; private List<DB.App> apps;
private boolean showIncompatible;
// Set when something has changed (database or installed apps) so we know // Set when something has changed (database or installed apps) so we know
// we should invalidate the apps. // we should invalidate the apps.
private volatile boolean appsAllInvalid = false; private volatile boolean appsAllInvalid = false;
@ -161,18 +158,6 @@ public class FDroidApp extends Application {
DB db = DB.getDB(); DB db = DB.getDB();
apps = db.getApps(true); apps = db.getApps(true);
List<DB.Repo> repos = db.getRepos();
for (DB.App app : apps) {
if (app.icon == null) continue;
for (DB.Repo repo : repos) {
int latestRepo = app.apks.get(0).repo;
if (repo.id == latestRepo) {
app.iconUrl = repo.address + "/icons/" + app.icon;
break;
}
}
}
} finally { } finally {
DB.releaseDB(); DB.releaseDB();
} }
@ -181,19 +166,6 @@ public class FDroidApp extends Application {
DB db = DB.getDB(); DB db = DB.getDB();
apps = db.refreshApps(apps, invalidApps); apps = db.refreshApps(apps, invalidApps);
List<DB.Repo> repos = db.getRepos();
for (DB.App app : apps) {
if (app.icon == null) continue;
if (!invalidApps.contains(app.id)) continue;
for (DB.Repo repo : repos) {
int latestRepo = app.apks.get(0).repo;
if (repo.id == latestRepo) {
app.iconUrl = repo.address + "/icons/" + app.icon;
break;
}
}
}
invalidApps.clear(); invalidApps.clear();
} finally { } finally {
DB.releaseDB(); DB.releaseDB();
@ -213,8 +185,7 @@ public class FDroidApp extends Application {
app.toUpdate = (app.hasUpdates app.toUpdate = (app.hasUpdates
&& !app.ignoreAllUpdates && !app.ignoreAllUpdates
&& app.curApk.vercode > app.ignoreThisUpdate && app.curApk.vercode > app.ignoreThisUpdate
&& !app.filtered && !app.filtered);
&& (showIncompatible || app.compatible));
} }
} }

View File

@ -18,7 +18,6 @@
package org.fdroid.fdroid; package org.fdroid.fdroid;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
@ -34,21 +33,24 @@ import org.fdroid.fdroid.compat.ActionBarCompat;
public class PreferencesActivity extends PreferenceActivity implements public class PreferencesActivity extends PreferenceActivity implements
OnPreferenceChangeListener { OnPreferenceChangeListener {
Intent ret; public static final int RESULT_RELOAD = 1;
public static final int RESULT_REFILTER = 2;
private int result = 0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true); ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
for (String prefkey : new String[] { "updateInterval" }) { for (String prefkey : new String[] {
Preference pref = findPreference(prefkey); "updateInterval", "rooted", "incompatibleVersions" }) {
pref.setOnPreferenceChangeListener(this); findPreference(prefkey).setOnPreferenceChangeListener(this);
CheckBoxPreference onlyOnWifi = (CheckBoxPreference)
findPreference("updateOnWifiOnly");
onlyOnWifi.setEnabled(Integer.parseInt(
((ListPreference)pref).getValue()) > 0);
} }
CheckBoxPreference onlyOnWifi = (CheckBoxPreference)
findPreference("updateOnWifiOnly");
onlyOnWifi.setEnabled(Integer.parseInt(
((ListPreference)findPreference("updateInterval"))
.getValue()) > 0);
} }
@Override @Override
@ -71,6 +73,16 @@ public class PreferencesActivity extends PreferenceActivity implements
onlyOnWifi.setEnabled(interval > 0); onlyOnWifi.setEnabled(interval > 0);
return true; return true;
} }
if (key.equals("incompatibleVersions")) {
result ^= RESULT_RELOAD;
setResult(result);
return true;
}
if (key.equals("rooted")) {
result ^= RESULT_REFILTER;
setResult(result);
return true;
}
return false; return false;
} }