From 765e6950dc03b50a6ef5076d8a2e1eab1dbb7906 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 947f51c29..282041260 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 = 43; + private static final int CURRENT_PREFS_VERSION = 44; private static final LimitedQueue mIDSenderLookup = new LimitedQueue<>(16); private static GBPrefs prefs; @@ -1868,6 +1868,20 @@ public class GBApplication extends Application { } } + if (oldVersion < 44) { + // 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 44", e); + } + } + editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION)); editor.apply(); }