Refactoring AppInitializer

This commit is contained in:
Dima-1 2020-05-15 11:49:54 +03:00
parent 0e5078dd4b
commit 48fb775f51
4 changed files with 18 additions and 84 deletions

View file

@ -45,10 +45,10 @@ android {
defaultConfig {
minSdkVersion System.getenv("MIN_SDK_VERSION") ? System.getenv("MIN_SDK_VERSION").toInteger() : 15
targetSdkVersion 28
versionCode 371
versionCode 370
versionCode System.getenv("APK_NUMBER_VERSION") ? System.getenv("APK_NUMBER_VERSION").toInteger() : versionCode
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_SUFFIX")? versionName + System.getenv("APK_VERSION_SUFFIX").toString(): versionName
// Stops the Gradle plugins automatic rasterization of vectors

View file

@ -83,6 +83,9 @@ import java.util.Random;
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.preferenceLastCheck;
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 {
// 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 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 FIRST_INSTALLED = "FIRST_INSTALLED"; //$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$
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 String APP_EXIT_KEY = "APP_EXIT_KEY";
private OsmandApplication app;
private AppVersionUpgradeOnInit appVersionUpgrade;
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(AppInitializer.class);
private boolean initSettings = false;
private boolean firstTime;
private boolean activityChangesShowed = false;
private boolean appVersionChanged;
private int prevAppVersion;
private long startTime;
private long startBgTime;
private boolean appInitializing = true;
@ -158,6 +146,7 @@ public class AppInitializer implements IProgress {
public AppInitializer(OsmandApplication 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().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
} else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) {
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
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;
} else {
appVersionUpgrade.upgradeVersion(startPrefs, VERSION_3_7_0_1);
}
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
@ -280,16 +217,16 @@ public class AppInitializer implements IProgress {
}
public boolean isAppVersionChanged() {
return appVersionChanged;
return appVersionUpgrade.isAppVersionChanged();
}
public int getPrevAppVersion() {
return prevAppVersion;
return appVersionUpgrade.getPrevAppVersion();
}
public boolean checkAppVersionChanged() {
initVariables();
boolean showRecentChangesDialog = !firstTime && appVersionChanged;
boolean showRecentChangesDialog = !firstTime && isAppVersionChanged();
// showRecentChangesDialog = true;
if (showRecentChangesDialog && !activityChangesShowed) {
activityChangesShowed = true;

View file

@ -173,14 +173,7 @@ public class FavouritesDbHelper {
saveCurrentPointsIntoFile();
}
favoritesLoaded = true;
context.runInUIThread(new Runnable() {
@Override
public void run() {
for (FavoritesListener listener : listeners) {
listener.onFavoritesLoaded();
}
}
});
notifyListeners();
}
void fixBlackBackground() {
@ -195,6 +188,10 @@ public class FavouritesDbHelper {
}
sortAll();
saveCurrentPointsIntoFile();
notifyListeners();
}
private void notifyListeners() {
context.runInUIThread(new Runnable() {
@Override
public void run() {

View file

@ -179,7 +179,7 @@ public class OsmandApplication extends MultiDexApplication {
appCustomization.setup(this);
osmandSettings = appCustomization.getOsmandSettings();
appInitializer.initVariables();
if (appInitializer.isAppVersionChanged() && appInitializer.getPrevAppVersion() < AppInitializer.VERSION_2_3) {
if (appInitializer.isAppVersionChanged() && appInitializer.getPrevAppVersion() < AppVersionUpgradeOnInit.VERSION_2_3) {
osmandSettings.freezeExternalStorageDirectory();
} else if (appInitializer.isFirstTime()) {
osmandSettings.initExternalStorageDirectory();