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="appcompatibility">Application compatibility</string>
<string name="showincompat">Incompatible apps</string>
<string name="showincompat_long">Show apps written for newer Android versions or different hardware</string>
<string name="show_incompat_versions">Incompatible versions</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_long">Show apps that require root privileges</string>
<string name="ignoreTouch">Ignore Touchscreen</string>

View File

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

View File

@ -232,13 +232,6 @@ public class AppDetails extends ListActivity {
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();
// Get the preferences we're going to use in this Activity...
AppDetails old = (AppDetails) getLastNonConfigurationInstance();
@ -252,11 +245,17 @@ public class AppDetails extends ListActivity {
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
.getDefaultSharedPreferences(getBaseContext());
pref_expert = prefs.getBoolean("expert", false);
pref_permissions = prefs.getBoolean("showPermissions", false);
pref_incompatible = prefs.getBoolean("showIncompatible", false);
startViews();
@ -264,7 +263,6 @@ public class AppDetails extends ListActivity {
private boolean pref_expert;
private boolean pref_permissions;
private boolean pref_incompatible;
private boolean resetRequired;
// The signature of the installed version.
@ -391,13 +389,6 @@ public class AppDetails extends ListActivity {
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
// ends, and the description) into the appropriate place, if we're in
// landscape mode. In portrait mode, we put it in the listview's

View File

@ -184,9 +184,6 @@ public class AppListManager {
private boolean updateApps() {
allApps = ((FDroidApp)fdroidActivity.getApplication()).getApps();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(fdroidActivity.getBaseContext());
boolean showIncompatible = prefs.getBoolean("showIncompatible", false);
if (allApps.isEmpty()) {
// 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
// only to available if it's not filtered.
if (!app.filtered && (showIncompatible || app.compatible)
&& isInCategory(app, currentCategory, recentDate)) {
if (isInCategory(app, currentCategory, recentDate)) {
availApps.add(app);
}
if (app.installedVersion != null) {

View File

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

View File

@ -234,13 +234,18 @@ public class FDroid extends FragmentActivity {
}
break;
case REQUEST_PREFS:
((FDroidApp) getApplication()).filterApps();
// The automatic update settings may have changed, so reschedule (or
// unschedule) the service accordingly. It's cheap, so no need to
// check if the particular setting has actually been changed.
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.
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
showIncompatible = prefs.getBoolean("showIncompatible", false);
if (!prefs.getBoolean("cacheDownloaded", false)) {
File local_path = DB.getDataPath(this);
@ -110,8 +109,6 @@ public class FDroidApp extends Application {
// Global list of all known applications.
private List<DB.App> apps;
private boolean showIncompatible;
// Set when something has changed (database or installed apps) so we know
// we should invalidate the apps.
private volatile boolean appsAllInvalid = false;
@ -161,18 +158,6 @@ public class FDroidApp extends Application {
DB db = DB.getDB();
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 {
DB.releaseDB();
}
@ -181,19 +166,6 @@ public class FDroidApp extends Application {
DB db = DB.getDB();
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();
} finally {
DB.releaseDB();
@ -213,8 +185,7 @@ public class FDroidApp extends Application {
app.toUpdate = (app.hasUpdates
&& !app.ignoreAllUpdates
&& app.curApk.vercode > app.ignoreThisUpdate
&& !app.filtered
&& (showIncompatible || app.compatible));
&& !app.filtered);
}
}

View File

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