From 97cba3f5e64b39542f177d81127bfbaaf31314cb Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Sat, 14 Sep 2024 21:14:58 +0200 Subject: [PATCH] Add preference migration for existing users --- .../gadgetbridge/GBApplication.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 6d5d3e12d..2c3531b50 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -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 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 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(); }