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 SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
pref_smallDensity = prefs.getBoolean("smallDensity", false); pref_smallDensity = prefs.getBoolean(Preferences.PREF_SMALL_DENSITY, false);
pref_expert = prefs.getBoolean("expert", false); pref_expert = prefs.getBoolean(Preferences.PREF_EXPERT, false);
pref_permissions = prefs.getBoolean("showPermissions", false); pref_permissions = prefs.getBoolean(Preferences.PREF_PERMISSIONS, false);
pref_incompatibleVersions = prefs.getBoolean( pref_incompatibleVersions = prefs.getBoolean(
Preferences.PREF_INCOMP_VER, false); 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. // Read preferences and cache them so we can do quick lookups.
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(ctx); .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 // 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() { private Date calcMaxHistory() {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(fdroidActivity.getBaseContext()); .getDefaultSharedPreferences(fdroidActivity.getBaseContext());
String daysPreference = prefs.getString("updateHistoryDays", "14"); String daysPreference = prefs.getString(Preferences.PREF_UPD_HISTORY, "14");
int maxHistoryDays = Integer.parseInt(daysPreference); int maxHistoryDays = Integer.parseInt(daysPreference);
Calendar recent = Calendar.getInstance(); Calendar recent = Calendar.getInstance();
recent.add(Calendar.DAY_OF_YEAR, -maxHistoryDays); recent.add(Calendar.DAY_OF_YEAR, -maxHistoryDays);

View File

@ -68,7 +68,7 @@ public class FDroidApp extends Application {
public void reloadTheme() { public void reloadTheme() {
curTheme = Theme.valueOf(PreferenceManager curTheme = Theme.valueOf(PreferenceManager
.getDefaultSharedPreferences(getBaseContext()) .getDefaultSharedPreferences(getBaseContext())
.getString("theme", "dark")); .getString(Preferences.PREF_THEME, "dark"));
} }
public void applyTheme(Activity activity) { public void applyTheme(Activity activity) {
switch (curTheme) { switch (curTheme) {
@ -96,8 +96,8 @@ 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());
curTheme = Theme.valueOf(prefs.getString("theme", "dark")); curTheme = Theme.valueOf(prefs.getString(Preferences.PREF_THEME, "dark"));
if (!prefs.getBoolean("cacheDownloaded", false)) { if (!prefs.getBoolean(Preferences.PREF_CACHE_APK, false)) {
File local_path = Utils.getApkCacheDir(this); File local_path = Utils.getApkCacheDir(this);
// Things can be null if the SD card is not ready - we'll just // 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()); .getDefaultSharedPreferences(getBaseContext());
TextView tv_lastCheck = (TextView)findViewById(R.id.lastUpdateCheck); 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 = ""; String s_lastUpdateCheck = "";
if (lastUpdate == 0) { if (lastUpdate == 0) {
s_lastUpdateCheck = getString(R.string.never); 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_CACHE_APK = "cacheDownloaded";
public static final String PREF_EXPERT = "expert"; public static final String PREF_EXPERT = "expert";
public static final String PREF_DB_SYNC = "dbSyncMode"; 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_COMPACT_LAYOUT = false;
private static final boolean DEFAULT_SMALL_DENSITY = 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_MESSAGE = "msg";
public static final String RESULT_EVENT = "event"; public static final String RESULT_EVENT = "event";
public static final int STATUS_COMPLETE_WITH_CHANGES = 0; public static final int STATUS_COMPLETE_WITH_CHANGES = 0;
public static final int STATUS_COMPLETE_AND_SAME = 1; public static final int STATUS_COMPLETE_AND_SAME = 1;
public static final int STATUS_ERROR = 2; public static final int STATUS_ERROR = 2;
@ -130,7 +131,7 @@ public class UpdateService extends IntentService implements ProgressListener {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(ctx); .getDefaultSharedPreferences(ctx);
String sint = prefs.getString("updateInterval", "0"); String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
int interval = Integer.parseInt(sint); int interval = Integer.parseInt(sint);
Intent intent = new Intent(ctx, UpdateService.class); 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... // See if it's time to actually do anything yet...
if (isScheduledRun()) { if (isScheduledRun()) {
long lastUpdate = prefs.getLong("lastUpdateCheck", 0); long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0);
String sint = prefs.getString("updateInterval", "0"); String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
int interval = Integer.parseInt(sint); int interval = Integer.parseInt(sint);
if (interval == 0) { if (interval == 0) {
Log.d("FDroid", "Skipping update - disabled"); 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 // If we are to update the repos only on wifi, make sure that
// connection is active // connection is active
if (prefs.getBoolean("updateOnWifiOnly", false)) { if (prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) {
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo.State wifi = conMan.getNetworkInfo(1).getState(); NetworkInfo.State wifi = conMan.getNetworkInfo(1).getState();
if (wifi != NetworkInfo.State.CONNECTED && if (wifi != NetworkInfo.State.CONNECTED &&
@ -232,7 +233,7 @@ public class UpdateService extends IntentService implements ProgressListener {
Log.d("FDroid", "Unscheduled (manually requested) update"); 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 // Grab some preliminary information, then we can release the
// database while we do all the downloading, etc... // database while we do all the downloading, etc...
@ -385,7 +386,7 @@ public class UpdateService extends IntentService implements ProgressListener {
sendStatus(STATUS_ERROR, errmsg); sendStatus(STATUS_ERROR, errmsg);
} else { } else {
Editor e = prefs.edit(); Editor e = prefs.edit();
e.putLong("lastUpdateCheck", System.currentTimeMillis()); e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis());
e.commit(); e.commit();
if (changes) { if (changes) {
sendStatus(STATUS_COMPLETE_WITH_CHANGES); sendStatus(STATUS_COMPLETE_WITH_CHANGES);