Refactoring AppInitializer
This commit is contained in:
parent
0e5078dd4b
commit
48fb775f51
4 changed files with 18 additions and 84 deletions
|
@ -45,10 +45,10 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion System.getenv("MIN_SDK_VERSION") ? System.getenv("MIN_SDK_VERSION").toInteger() : 15
|
minSdkVersion System.getenv("MIN_SDK_VERSION") ? System.getenv("MIN_SDK_VERSION").toInteger() : 15
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 371
|
versionCode 370
|
||||||
versionCode System.getenv("APK_NUMBER_VERSION") ? System.getenv("APK_NUMBER_VERSION").toInteger() : versionCode
|
versionCode System.getenv("APK_NUMBER_VERSION") ? System.getenv("APK_NUMBER_VERSION").toInteger() : versionCode
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionName "3.7.1"
|
versionName "3.7.0"
|
||||||
versionName System.getenv("APK_VERSION")? System.getenv("APK_VERSION").toString(): versionName
|
versionName System.getenv("APK_VERSION")? System.getenv("APK_VERSION").toString(): versionName
|
||||||
versionName System.getenv("APK_VERSION_SUFFIX")? versionName + System.getenv("APK_VERSION_SUFFIX").toString(): versionName
|
versionName System.getenv("APK_VERSION_SUFFIX")? versionName + System.getenv("APK_VERSION_SUFFIX").toString(): versionName
|
||||||
// Stops the Gradle plugin’s automatic rasterization of vectors
|
// Stops the Gradle plugin’s automatic rasterization of vectors
|
||||||
|
|
|
@ -83,6 +83,9 @@ import java.util.Random;
|
||||||
|
|
||||||
import btools.routingapp.BRouterServiceConnection;
|
import btools.routingapp.BRouterServiceConnection;
|
||||||
|
|
||||||
|
import static net.osmand.plus.AppVersionUpgradeOnInit.VERSION_3_5;
|
||||||
|
import static net.osmand.plus.AppVersionUpgradeOnInit.VERSION_3_7_0_1;
|
||||||
|
import static net.osmand.plus.AppVersionUpgradeOnInit.VERSION_INSTALLED;
|
||||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
||||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
|
||||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
|
||||||
|
@ -94,19 +97,6 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIn
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class AppInitializer implements IProgress {
|
public class AppInitializer implements IProgress {
|
||||||
// 22 - 2.2
|
|
||||||
public static final int VERSION_2_2 = 22;
|
|
||||||
// 23 - 2.3
|
|
||||||
public static final int VERSION_2_3 = 23;
|
|
||||||
// 32 - 3.2
|
|
||||||
public static final int VERSION_3_2 = 32;
|
|
||||||
// 35 - 3.5
|
|
||||||
public static final int VERSION_3_5 = 35;
|
|
||||||
// 36 - 3.6
|
|
||||||
public static final int VERSION_3_6 = 36;
|
|
||||||
// 37 - 3.7
|
|
||||||
public static final int VERSION_3_7 = 37;
|
|
||||||
|
|
||||||
|
|
||||||
public static final boolean TIPS_AND_TRICKS = false;
|
public static final boolean TIPS_AND_TRICKS = false;
|
||||||
public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
|
public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
|
||||||
|
@ -114,7 +104,6 @@ public class AppInitializer implements IProgress {
|
||||||
public static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$
|
public static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$
|
||||||
public static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$
|
public static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$
|
||||||
private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$
|
private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$
|
||||||
private static final String VERSION_INSTALLED = "VERSION_INSTALLED"; //$NON-NLS-1$
|
|
||||||
private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$
|
private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final String LATEST_CHANGES_URL = "https://osmand.net/blog/osmand-3-7-released";
|
public static final String LATEST_CHANGES_URL = "https://osmand.net/blog/osmand-3-7-released";
|
||||||
|
@ -122,13 +111,12 @@ public class AppInitializer implements IProgress {
|
||||||
public static final int APP_EXIT_CODE = 4;
|
public static final int APP_EXIT_CODE = 4;
|
||||||
public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
|
public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
private AppVersionUpgradeOnInit appVersionUpgrade;
|
||||||
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(AppInitializer.class);
|
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(AppInitializer.class);
|
||||||
|
|
||||||
private boolean initSettings = false;
|
private boolean initSettings = false;
|
||||||
private boolean firstTime;
|
private boolean firstTime;
|
||||||
private boolean activityChangesShowed = false;
|
private boolean activityChangesShowed = false;
|
||||||
private boolean appVersionChanged;
|
|
||||||
private int prevAppVersion;
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private long startBgTime;
|
private long startBgTime;
|
||||||
private boolean appInitializing = true;
|
private boolean appInitializing = true;
|
||||||
|
@ -158,6 +146,7 @@ public class AppInitializer implements IProgress {
|
||||||
|
|
||||||
public AppInitializer(OsmandApplication app) {
|
public AppInitializer(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
appVersionUpgrade = new AppVersionUpgradeOnInit(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -192,60 +181,8 @@ public class AppInitializer implements IProgress {
|
||||||
startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
|
startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
|
||||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
||||||
} else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) {
|
} else {
|
||||||
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
|
appVersionUpgrade.upgradeVersion(startPrefs, VERSION_3_7_0_1);
|
||||||
if(prevAppVersion < VERSION_2_2) {
|
|
||||||
app.getSettings().SHOW_DASHBOARD_ON_START.set(true);
|
|
||||||
app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
|
|
||||||
app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
|
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit();
|
|
||||||
}
|
|
||||||
if(prevAppVersion < VERSION_2_3) {
|
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
|
|
||||||
}
|
|
||||||
if (prevAppVersion < VERSION_3_2) {
|
|
||||||
app.getSettings().BILLING_PURCHASE_TOKENS_SENT.set("");
|
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
|
|
||||||
}
|
|
||||||
if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")
|
|
||||||
|| Version.getAppVersion(app).equals("3.5.4")) {
|
|
||||||
app.getSettings().migratePreferences();
|
|
||||||
addListener(new AppInitializeListener() {
|
|
||||||
@Override
|
|
||||||
public void onProgress(AppInitializer init, InitEvents event) {
|
|
||||||
if (event.equals(InitEvents.FAVORITES_INITIALIZED)) {
|
|
||||||
app.getSettings().migrateHomeWorkParkingToFavorites();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFinish(AppInitializer init) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
|
||||||
}
|
|
||||||
if (prevAppVersion < VERSION_3_6) {
|
|
||||||
app.getSettings().migratePreferences();
|
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_6).commit();
|
|
||||||
}
|
|
||||||
if (prevAppVersion < VERSION_3_7 || Version.getAppVersion(app).equals("3.7.1")) {
|
|
||||||
app.getSettings().migrateEnumPreferences();
|
|
||||||
addListener(new AppInitializeListener() {
|
|
||||||
@Override
|
|
||||||
public void onProgress(AppInitializer init, InitEvents event) {
|
|
||||||
if (event.equals(InitEvents.FAVORITES_INITIALIZED)) {
|
|
||||||
app.getFavorites().fixBlackBackground();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFinish(AppInitializer init) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7).commit();
|
|
||||||
}
|
|
||||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
|
||||||
appVersionChanged = true;
|
|
||||||
}
|
}
|
||||||
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
|
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
|
||||||
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
|
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
|
||||||
|
@ -280,16 +217,16 @@ public class AppInitializer implements IProgress {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAppVersionChanged() {
|
public boolean isAppVersionChanged() {
|
||||||
return appVersionChanged;
|
return appVersionUpgrade.isAppVersionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPrevAppVersion() {
|
public int getPrevAppVersion() {
|
||||||
return prevAppVersion;
|
return appVersionUpgrade.getPrevAppVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkAppVersionChanged() {
|
public boolean checkAppVersionChanged() {
|
||||||
initVariables();
|
initVariables();
|
||||||
boolean showRecentChangesDialog = !firstTime && appVersionChanged;
|
boolean showRecentChangesDialog = !firstTime && isAppVersionChanged();
|
||||||
// showRecentChangesDialog = true;
|
// showRecentChangesDialog = true;
|
||||||
if (showRecentChangesDialog && !activityChangesShowed) {
|
if (showRecentChangesDialog && !activityChangesShowed) {
|
||||||
activityChangesShowed = true;
|
activityChangesShowed = true;
|
||||||
|
|
|
@ -173,14 +173,7 @@ public class FavouritesDbHelper {
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
}
|
}
|
||||||
favoritesLoaded = true;
|
favoritesLoaded = true;
|
||||||
context.runInUIThread(new Runnable() {
|
notifyListeners();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (FavoritesListener listener : listeners) {
|
|
||||||
listener.onFavoritesLoaded();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fixBlackBackground() {
|
void fixBlackBackground() {
|
||||||
|
@ -195,6 +188,10 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
sortAll();
|
sortAll();
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyListeners() {
|
||||||
context.runInUIThread(new Runnable() {
|
context.runInUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -179,7 +179,7 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
appCustomization.setup(this);
|
appCustomization.setup(this);
|
||||||
osmandSettings = appCustomization.getOsmandSettings();
|
osmandSettings = appCustomization.getOsmandSettings();
|
||||||
appInitializer.initVariables();
|
appInitializer.initVariables();
|
||||||
if (appInitializer.isAppVersionChanged() && appInitializer.getPrevAppVersion() < AppInitializer.VERSION_2_3) {
|
if (appInitializer.isAppVersionChanged() && appInitializer.getPrevAppVersion() < AppVersionUpgradeOnInit.VERSION_2_3) {
|
||||||
osmandSettings.freezeExternalStorageDirectory();
|
osmandSettings.freezeExternalStorageDirectory();
|
||||||
} else if (appInitializer.isFirstTime()) {
|
} else if (appInitializer.isFirstTime()) {
|
||||||
osmandSettings.initExternalStorageDirectory();
|
osmandSettings.initExternalStorageDirectory();
|
||||||
|
|
Loading…
Reference in a new issue