1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

FitPro: fix crash, inactivity warning preference to string, after type enforcement in 3b348a5d5

This commit is contained in:
vanous 2022-05-29 21:18:53 +02:00
parent 4db2877a91
commit 22a9ad329e
5 changed files with 25 additions and 4 deletions

View File

@ -117,7 +117,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 = 14;
private static final int CURRENT_PREFS_VERSION = 15;
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
private static Prefs prefs;
@ -1143,6 +1143,25 @@ public class GBApplication extends Application {
}
}
if (oldVersion < 15) {
try (DBHandler db = acquireDB()) {
final DaoSession daoSession = db.getDaoSession();
final List<Device> activeDevices = DBHelper.getActiveDevices(daoSession);
for (Device dbDevice : activeDevices) {
final SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier());
final SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit();
if (DeviceType.FITPRO.equals(dbDevice.getType())) {
editor.remove("inactivity_warnings_threshold");
deviceSharedPrefsEdit.apply();
}
}
} catch (Exception e) {
Log.w(TAG, "error acquiring DB lock");
}
}
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
editor.apply();
}

View File

@ -77,6 +77,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_INACTIVITY_START = "inactivity_warnings_start";
public static final String PREF_INACTIVITY_END = "inactivity_warnings_end";
public static final String PREF_INACTIVITY_THRESHOLD = "inactivity_warnings_threshold";
public static final String PREF_INACTIVITY_THRESHOLD_EXTENDED = "inactivity_warnings_threshold_extended";
public static final String PREF_INACTIVITY_MO = "inactivity_warnings_mo";
public static final String PREF_INACTIVITY_TU = "inactivity_warnings_tu";
public static final String PREF_INACTIVITY_WE = "inactivity_warnings_we";

View File

@ -429,6 +429,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
addPreferenceHandlerFor(PREF_INACTIVITY_START);
addPreferenceHandlerFor(PREF_INACTIVITY_END);
addPreferenceHandlerFor(PREF_INACTIVITY_THRESHOLD);
addPreferenceHandlerFor(PREF_INACTIVITY_THRESHOLD_EXTENDED);
addPreferenceHandlerFor(PREF_INACTIVITY_MO);
addPreferenceHandlerFor(PREF_INACTIVITY_TU);
addPreferenceHandlerFor(PREF_INACTIVITY_WE);

View File

@ -543,7 +543,7 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport {
case DeviceSettingsPreferenceConst.PREF_LANGUAGE:
setLanguage(builder);
break;
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD_EXTENDED:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_START:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_END:
@ -1148,7 +1148,7 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport {
if (prefLongsitSwitch) {
String inactivity = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD, "4");
String inactivity = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD_EXTENDED, "4");
String start = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_START, "08:00");
String end = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_END, "16:00");
Calendar startCalendar = GregorianCalendar.getInstance();

View File

@ -21,7 +21,7 @@
android:dependency="inactivity_warnings_enable"
android:entries="@array/inactivity_minutes"
android:entryValues="@array/inactivity_minutes_values"
android:key="inactivity_warnings_threshold"
android:key="inactivity_warnings_threshold_extended"
android:summary="@string/mi2_prefs_inactivity_warnings_summary"
android:title="@string/mi2_prefs_inactivity_warnings_threshold" />