Finish getting rid of hard-coded preferences

This commit is contained in:
Daniel Martí 2014-01-16 09:32:34 +01:00
parent 305daf5a10
commit 9500c987cc
7 changed files with 17 additions and 15 deletions

View File

@ -327,9 +327,9 @@ public class AppDetails extends ListActivity {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
pref_smallDensity = prefs.getBoolean("smallDensity", false);
pref_expert = prefs.getBoolean("expert", false);
pref_permissions = prefs.getBoolean("showPermissions", false);
pref_smallDensity = prefs.getBoolean(Preferences.PREF_SMALL_DENSITY, false);
pref_expert = prefs.getBoolean(Preferences.PREF_EXPERT, false);
pref_permissions = prefs.getBoolean(Preferences.PREF_PERMISSIONS, false);
pref_incompatibleVersions = prefs.getBoolean(
Preferences.PREF_INCOMP_VER, false);

View File

@ -31,7 +31,7 @@ public class AppFilter {
// Read preferences and cache them so we can do quick lookups.
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(ctx);
pref_rooted = prefs.getBoolean("rooted", true);
pref_rooted = prefs.getBoolean(Preferences.PREF_ROOTED, true);
}
// Return true if the given app should be filtered out based on user

View File

@ -143,7 +143,7 @@ public class AppListManager {
private Date calcMaxHistory() {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(fdroidActivity.getBaseContext());
String daysPreference = prefs.getString("updateHistoryDays", "14");
String daysPreference = prefs.getString(Preferences.PREF_UPD_HISTORY, "14");
int maxHistoryDays = Integer.parseInt(daysPreference);
Calendar recent = Calendar.getInstance();
recent.add(Calendar.DAY_OF_YEAR, -maxHistoryDays);

View File

@ -68,7 +68,7 @@ public class FDroidApp extends Application {
public void reloadTheme() {
curTheme = Theme.valueOf(PreferenceManager
.getDefaultSharedPreferences(getBaseContext())
.getString("theme", "dark"));
.getString(Preferences.PREF_THEME, "dark"));
}
public void applyTheme(Activity activity) {
switch (curTheme) {
@ -96,8 +96,8 @@ public class FDroidApp extends Application {
// because the install intent says it's finished when it hasn't.
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
curTheme = Theme.valueOf(prefs.getString("theme", "dark"));
if (!prefs.getBoolean("cacheDownloaded", false)) {
curTheme = Theme.valueOf(prefs.getString(Preferences.PREF_THEME, "dark"));
if (!prefs.getBoolean(Preferences.PREF_CACHE_APK, false)) {
File local_path = Utils.getApkCacheDir(this);
// Things can be null if the SD card is not ready - we'll just

View File

@ -92,7 +92,7 @@ public class ManageRepo extends ListActivity {
.getDefaultSharedPreferences(getBaseContext());
TextView tv_lastCheck = (TextView)findViewById(R.id.lastUpdateCheck);
long lastUpdate = prefs.getLong("lastUpdateCheck", 0);
long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0);
String s_lastUpdateCheck = "";
if (lastUpdate == 0) {
s_lastUpdateCheck = getString(R.string.never);

View File

@ -40,6 +40,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
public static final String PREF_CACHE_APK = "cacheDownloaded";
public static final String PREF_EXPERT = "expert";
public static final String PREF_DB_SYNC = "dbSyncMode";
public static final String PREF_UPD_LAST = "lastUpdateCheck";
private static final boolean DEFAULT_COMPACT_LAYOUT = false;
private static final boolean DEFAULT_SMALL_DENSITY = false;

View File

@ -42,6 +42,7 @@ public class UpdateService extends IntentService implements ProgressListener {
public static final String RESULT_MESSAGE = "msg";
public static final String RESULT_EVENT = "event";
public static final int STATUS_COMPLETE_WITH_CHANGES = 0;
public static final int STATUS_COMPLETE_AND_SAME = 1;
public static final int STATUS_ERROR = 2;
@ -130,7 +131,7 @@ public class UpdateService extends IntentService implements ProgressListener {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(ctx);
String sint = prefs.getString("updateInterval", "0");
String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
int interval = Integer.parseInt(sint);
Intent intent = new Intent(ctx, UpdateService.class);
@ -203,8 +204,8 @@ public class UpdateService extends IntentService implements ProgressListener {
// See if it's time to actually do anything yet...
if (isScheduledRun()) {
long lastUpdate = prefs.getLong("lastUpdateCheck", 0);
String sint = prefs.getString("updateInterval", "0");
long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0);
String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
int interval = Integer.parseInt(sint);
if (interval == 0) {
Log.d("FDroid", "Skipping update - disabled");
@ -219,7 +220,7 @@ public class UpdateService extends IntentService implements ProgressListener {
// If we are to update the repos only on wifi, make sure that
// connection is active
if (prefs.getBoolean("updateOnWifiOnly", false)) {
if (prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) {
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo.State wifi = conMan.getNetworkInfo(1).getState();
if (wifi != NetworkInfo.State.CONNECTED &&
@ -232,7 +233,7 @@ public class UpdateService extends IntentService implements ProgressListener {
Log.d("FDroid", "Unscheduled (manually requested) update");
}
boolean notify = prefs.getBoolean("updateNotify", false);
boolean notify = prefs.getBoolean(Preferences.PREF_UPD_NOTIFY, false);
// Grab some preliminary information, then we can release the
// database while we do all the downloading, etc...
@ -385,7 +386,7 @@ public class UpdateService extends IntentService implements ProgressListener {
sendStatus(STATUS_ERROR, errmsg);
} else {
Editor e = prefs.edit();
e.putLong("lastUpdateCheck", System.currentTimeMillis());
e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis());
e.commit();
if (changes) {
sendStatus(STATUS_COMPLETE_WITH_CHANGES);