Use strings to store activity shared preferences.
System has trouble with accessing integer in the preferences, so let's not use them.
This commit is contained in:
parent
c436c4c055
commit
b858e50804
|
@ -6,6 +6,7 @@
|
|||
* Pebble: Allow to select the preferred activity tracker via settings activity (Health, Misfit, Morpheuz)
|
||||
* Pebble: Fix wrong(previous) contact being displayed on the pebble
|
||||
* Mi Band: improvements to pairing
|
||||
* Fix a problem related to shared preferences storage of activity settings.
|
||||
|
||||
####Version 0.7.4
|
||||
* Refactored the settings activity: User details are now generic instead of miband specific. Old settings are preserved.
|
||||
|
|
|
@ -48,7 +48,7 @@ public class GBApplication extends Application {
|
|||
private static SharedPreferences sharedPrefs;
|
||||
private static final String PREFS_VERSION = "shared_preferences_version";
|
||||
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
|
||||
private static final int CURRENT_PREFS_VERSION = 1;
|
||||
private static final int CURRENT_PREFS_VERSION = 2;
|
||||
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
|
||||
|
||||
public static final String ACTION_QUIT
|
||||
|
@ -251,20 +251,25 @@ public class GBApplication extends Application {
|
|||
}
|
||||
|
||||
private int getPrefsFileVersion() {
|
||||
return sharedPrefs.getInt(PREFS_VERSION, 0); //0 is legacy
|
||||
try {
|
||||
return Integer.parseInt(sharedPrefs.getString(PREFS_VERSION, "0")); //0 is legacy
|
||||
} catch (Exception e) {
|
||||
//in version 1 this was an int
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void migratePrefs(int oldVersion) {
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
switch (oldVersion) {
|
||||
case 0:
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
String legacyGender = sharedPrefs.getString("mi_user_gender", null);
|
||||
String legacyHeight = sharedPrefs.getString("mi_user_height_cm", null);
|
||||
String legacyWeigth = sharedPrefs.getString("mi_user_weight_kg", null);
|
||||
String legacyYOB = sharedPrefs.getString("mi_user_year_of_birth",null);
|
||||
if(legacyGender != null) {
|
||||
int gender = "male".equals(legacyGender) ? 1 : "female".equals(legacyGender) ? 0 : 2;
|
||||
editor.putInt(ActivityUser.PREF_USER_GENDER, gender);
|
||||
editor.putString(ActivityUser.PREF_USER_GENDER, Integer.toString(gender));
|
||||
editor.remove("mi_user_gender");
|
||||
}
|
||||
if(legacyHeight != null) {
|
||||
|
@ -279,10 +284,18 @@ public class GBApplication extends Application {
|
|||
editor.putString(ActivityUser.PREF_USER_YEAR_OF_BIRTH, legacyYOB);
|
||||
editor.remove("mi_user_year_of_birth");
|
||||
}
|
||||
editor.putInt(PREFS_VERSION, CURRENT_PREFS_VERSION);
|
||||
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
||||
editor.commit();
|
||||
break;
|
||||
case 1:
|
||||
Integer legacyGender_1 = sharedPrefs.getInt(ActivityUser.PREF_USER_GENDER, 2);
|
||||
if(legacyGender_1 != null) {
|
||||
editor.putString(ActivityUser.PREF_USER_GENDER, Integer.toString(legacyGender_1));
|
||||
}
|
||||
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
||||
break;
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static LimitedQueue getIDSenderLookup() {
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ActivityUser {
|
|||
|
||||
private void fetchPreferences() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
||||
activityUserGender = prefs.getInt(PREF_USER_GENDER, defaultUserGender);
|
||||
activityUserGender = Integer.parseInt(prefs.getString(PREF_USER_GENDER, Integer.toString(defaultUserGender)));
|
||||
activityUserHeightCm = Integer.parseInt(prefs.getString(PREF_USER_HEIGHT_CM, Integer.toString(defaultUserHeightCm)));
|
||||
activityUserWeightKg = Integer.parseInt(prefs.getString(PREF_USER_WEIGHT_KG, Integer.toString(defaultUserWeightKg)));
|
||||
activityUserYearOfBirth = Integer.parseInt(prefs.getString(PREF_USER_YEAR_OF_BIRTH, Integer.toString(defaultUserYearOfBirth)));
|
||||
|
|
|
@ -135,7 +135,7 @@
|
|||
android:title="@string/activity_prefs_year_birth" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="male"
|
||||
android:defaultValue="2"
|
||||
android:entries="@array/gender"
|
||||
android:entryValues="@array/gender_values"
|
||||
android:key="activity_user_gender"
|
||||
|
|
Loading…
Reference in New Issue