1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-30 05:52:57 +01:00

Add preference migration for existing users

This commit is contained in:
Arjan Schrijver 2024-09-14 21:14:58 +02:00
parent 0c984ad400
commit 97cba3f5e6

View File

@ -127,7 +127,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 = 42;
private static final int CURRENT_PREFS_VERSION = 43;
private static final LimitedQueue<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
private static GBPrefs prefs;
@ -1838,6 +1838,20 @@ public class GBApplication extends Application {
}
}
if (oldVersion < 43) {
// Users upgrading to this version don't need to see the welcome screen
try (DBHandler db = acquireDB()) {
final DaoSession daoSession = db.getDaoSession();
final List<Device> activeDevices = DBHelper.getActiveDevices(daoSession);
if (!activeDevices.isEmpty()) {
editor.putBoolean("first_run", false);
}
} catch (final Exception e) {
Log.e(TAG, "Failed to migrate prefs to version 42", e);
}
}
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
editor.apply();
}