From 6479a868405689bc28f877dd09c858c4d10f0534 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 18 May 2020 13:08:26 +0300 Subject: [PATCH] Fix favorites default icon and background --- .../src/net/osmand/plus/AppInitializer.java | 22 ++++++++++++++---- .../osmand/plus/AppVersionUpgradeOnInit.java | 23 ++++--------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 73ac9d998f..ab7a807e37 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -117,6 +117,7 @@ public class AppInitializer implements IProgress { private List warnings = new ArrayList<>(); private String taskName; private List listeners = new ArrayList<>(); + private SharedPreferences startPrefs; public enum InitEvents { FAVORITES_INITIALIZED, NATIVE_INITIALIZED, @@ -158,21 +159,23 @@ public class AppInitializer implements IProgress { return; } ApplicationMode.onApplicationStart(app); - - appVersionUpgrade.upgradeVersion(LAST_APP_VERSION); + startPrefs = app.getSharedPreferences( + getLocalClassName(app.getAppCustomization().getMapActivity().getName()), + Context.MODE_PRIVATE); + appVersionUpgrade.upgradeVersion(startPrefs, LAST_APP_VERSION); initSettings = true; } public int getNumberOfStarts() { - return appVersionUpgrade.getNumberOfStarts(); + return appVersionUpgrade.getNumberOfStarts(startPrefs); } public long getFirstInstalledDays() { - return appVersionUpgrade.getFirstInstalledDays(); + return appVersionUpgrade.getFirstInstalledDays(startPrefs); } public void resetFirstTimeRun() { - appVersionUpgrade.resetFirstTimeRun(); + appVersionUpgrade.resetFirstTimeRun(startPrefs); } public boolean isFirstTime() { @@ -927,4 +930,13 @@ public class AppInitializer implements IProgress { this.listeners.remove(listener); } + private String getLocalClassName(String cls) { + final String pkg = app.getPackageName(); + int packageLen = pkg.length(); + if (!cls.startsWith(pkg) || cls.length() <= packageLen + || cls.charAt(packageLen) != '.') { + return cls; + } + return cls.substring(packageLen + 1); + } } diff --git a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java index ffa23333b3..e4f720fa14 100644 --- a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java +++ b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java @@ -1,7 +1,6 @@ package net.osmand.plus; import android.annotation.SuppressLint; -import android.content.Context; import android.content.SharedPreferences; class AppVersionUpgradeOnInit { @@ -33,20 +32,16 @@ class AppVersionUpgradeOnInit { static final String VERSION_INSTALLED = "VERSION_INSTALLED"; private OsmandApplication app; - private SharedPreferences startPrefs; private int prevAppVersion; private boolean appVersionChanged; private boolean firstTime; AppVersionUpgradeOnInit(OsmandApplication app) { this.app = app; - startPrefs = app.getSharedPreferences( - getLocalClassName(app.getAppCustomization().getMapActivity().getName()), - Context.MODE_PRIVATE); } @SuppressLint("ApplySharedPref") - void upgradeVersion(int lastVersion) { + void upgradeVersion(SharedPreferences startPrefs, int lastVersion) { if(!startPrefs.contains(NUMBER_OF_STARTS)) { startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit(); } else { @@ -134,20 +129,20 @@ class AppVersionUpgradeOnInit { return prevAppVersion; } - public void resetFirstTimeRun() { + public void resetFirstTimeRun(SharedPreferences startPrefs) { if(startPrefs != null) { startPrefs.edit().remove(FIRST_TIME_APP_RUN).commit(); } } - public int getNumberOfStarts() { + public int getNumberOfStarts(SharedPreferences startPrefs) { if(startPrefs == null) { return 0; } return startPrefs.getInt(NUMBER_OF_STARTS, 1); } - public long getFirstInstalledDays() { + public long getFirstInstalledDays(SharedPreferences startPrefs) { if(startPrefs == null) { return 0; } @@ -159,14 +154,4 @@ class AppVersionUpgradeOnInit { public boolean isFirstTime() { return firstTime; } - - private String getLocalClassName(String cls) { - final String pkg = app.getPackageName(); - int packageLen = pkg.length(); - if (!cls.startsWith(pkg) || cls.length() <= packageLen - || cls.charAt(packageLen) != '.') { - return cls; - } - return cls.substring(packageLen + 1); - } }