Fix upgrade process

This commit is contained in:
Victor Shcherb 2020-05-15 15:51:54 +02:00
parent 07d0b43807
commit 082a24a21a
5 changed files with 128 additions and 111 deletions

View file

@ -26,7 +26,7 @@ public class PoiFilter extends AbstractPoiType {
} }
public void addPoiType(PoiType type) { public void addPoiType(PoiType type) {
if(!map.containsKey(type.getKeyName())) { if (!map.containsKey(type.getKeyName())) {
poiTypes.add(type); poiTypes.add(type);
map.put(type.getKeyName(), type); map.put(type.getKeyName(), type);
} else { } else {

View file

@ -83,9 +83,7 @@ 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.LAST_APP_VERSION;
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;
@ -99,10 +97,7 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIn
public class AppInitializer implements IProgress { public class AppInitializer implements IProgress {
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 VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$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$
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 EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$ private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$
@ -115,7 +110,6 @@ public class AppInitializer implements IProgress {
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 activityChangesShowed = false; private boolean activityChangesShowed = false;
private long startTime; private long startTime;
private long startBgTime; private long startBgTime;
@ -168,52 +162,25 @@ public class AppInitializer implements IProgress {
startPrefs = app.getSharedPreferences( startPrefs = app.getSharedPreferences(
getLocalClassName(app.getAppCustomization().getMapActivity().getName()), getLocalClassName(app.getAppCustomization().getMapActivity().getName()),
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
if(!startPrefs.contains(NUMBER_OF_STARTS)) { appVersionUpgrade.upgradeVersion(startPrefs, LAST_APP_VERSION);
startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit();
} else {
startPrefs.edit().putInt(NUMBER_OF_STARTS, startPrefs.getInt(NUMBER_OF_STARTS, 0) + 1).commit();
}
if (!startPrefs.contains(FIRST_INSTALLED)) {
startPrefs.edit().putLong(FIRST_INSTALLED, System.currentTimeMillis()).commit();
}
if (!startPrefs.contains(FIRST_TIME_APP_RUN)) {
firstTime = true;
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 {
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);
initSettings = true; initSettings = true;
} }
public int getNumberOfStarts() { public int getNumberOfStarts() {
if(startPrefs == null) { return appVersionUpgrade.getNumberOfStarts(startPrefs);
return 0;
}
return startPrefs.getInt(NUMBER_OF_STARTS, 1);
} }
public long getFirstInstalledDays() { public long getFirstInstalledDays() {
if(startPrefs == null) { return appVersionUpgrade.getFirstInstalledDays(startPrefs);
return 0;
}
long nd = startPrefs.getLong(FIRST_INSTALLED, 0);
return (System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l);
} }
public void resetFirstTimeRun() { public void resetFirstTimeRun() {
if(startPrefs != null) { appVersionUpgrade.resetFirstTimeRun(startPrefs);
startPrefs.edit().remove(FIRST_TIME_APP_RUN).commit();
}
} }
public boolean isFirstTime() { public boolean isFirstTime() {
initVariables(); initVariables();
return firstTime; return appVersionUpgrade.isFirstTime();
} }
public boolean isAppVersionChanged() { public boolean isAppVersionChanged() {
@ -226,7 +193,7 @@ public class AppInitializer implements IProgress {
public boolean checkAppVersionChanged() { public boolean checkAppVersionChanged() {
initVariables(); initVariables();
boolean showRecentChangesDialog = !firstTime && isAppVersionChanged(); boolean showRecentChangesDialog = !isFirstTime() && isAppVersionChanged();
// showRecentChangesDialog = true; // showRecentChangesDialog = true;
if (showRecentChangesDialog && !activityChangesShowed) { if (showRecentChangesDialog && !activityChangesShowed) {
activityChangesShowed = true; activityChangesShowed = true;
@ -252,7 +219,7 @@ public class AppInitializer implements IProgress {
long size = activity.getPreferences(Context.MODE_PRIVATE).getLong(EXCEPTION_FILE_SIZE, 0); long size = activity.getPreferences(Context.MODE_PRIVATE).getLong(EXCEPTION_FILE_SIZE, 0);
final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH); final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH);
if (file.exists() && file.length() > 0) { if (file.exists() && file.length() > 0) {
if (size != file.length() && !firstTime) { if (size != file.length() && !isFirstTime()) {
if (writeFileSize) { if (writeFileSize) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit(); activity.getPreferences(Context.MODE_PRIVATE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
} }

View file

@ -4,6 +4,11 @@ import android.annotation.SuppressLint;
import android.content.SharedPreferences; import android.content.SharedPreferences;
class AppVersionUpgradeOnInit { class AppVersionUpgradeOnInit {
public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
public static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$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$
// 22 - 2.2 // 22 - 2.2
public static final int VERSION_2_2 = 22; public static final int VERSION_2_2 = 22;
// 23 - 2.3 // 23 - 2.3
@ -16,80 +21,99 @@ class AppVersionUpgradeOnInit {
public static final int VERSION_3_6 = 36; public static final int VERSION_3_6 = 36;
// 37 - 3.7 // 37 - 3.7
public static final int VERSION_3_7 = 37; public static final int VERSION_3_7 = 37;
// 3701 - 3.7.0.1 // 3701 - 3.7-01 (4 digits version)
public static final int VERSION_3_7_0_1 = 3701; // from 3.7.0.1 - 4 digit version // Each upgrade should have independent version!
// So, we could have multiple upgrades per 1 release i.e. 3701, 3702, 3703, ... - will be for 3.7
public static final int VERSION_3_7_01 = 3701;
public static final int LAST_APP_VERSION = VERSION_3_7_01;
private static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER";
static final String VERSION_INSTALLED = "VERSION_INSTALLED"; static final String VERSION_INSTALLED = "VERSION_INSTALLED";
private OsmandApplication app; private OsmandApplication app;
private int prevAppVersion; private int prevAppVersion;
private boolean appVersionChanged; private boolean appVersionChanged;
private boolean firstTime;
AppVersionUpgradeOnInit(OsmandApplication app) { AppVersionUpgradeOnInit(OsmandApplication app) {
this.app = app; this.app = app;
} }
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
void upgradeVersion(SharedPreferences startPrefs, int versionToUpgrade) { void upgradeVersion(SharedPreferences startPrefs, int lastVersion) {
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0); if(!startPrefs.contains(NUMBER_OF_STARTS)) {
if (needsUpgrade(startPrefs, versionToUpgrade)) { startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit();
if (prevAppVersion < VERSION_2_2) { } else {
app.getSettings().SHOW_DASHBOARD_ON_START.set(true); startPrefs.edit().putInt(NUMBER_OF_STARTS, startPrefs.getInt(NUMBER_OF_STARTS, 0) + 1).commit();
app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true); }
app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true); if (!startPrefs.contains(FIRST_INSTALLED)) {
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit(); startPrefs.edit().putLong(FIRST_INSTALLED, System.currentTimeMillis()).commit();
} }
if (prevAppVersion < VERSION_2_3) { if (!startPrefs.contains(FIRST_TIME_APP_RUN)) {
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit(); firstTime = true;
} startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).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();
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
if (event.equals(AppInitializer.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) {
app.getSettings().migrateEnumPreferences();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7).commit();
}
if (prevAppVersion < VERSION_3_7_0_1) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
if (event.equals(AppInitializer.InitEvents.FAVORITES_INITIALIZED)) {
app.getFavorites().fixBlackBackground();
}
}
@Override
public void onFinish(AppInitializer init) {
}
});
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7_0_1).commit();
}
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true; startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
} else {
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
if (needsUpgrade(startPrefs, lastVersion)) {
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();
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
if (event.equals(AppInitializer.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) {
app.getSettings().migrateEnumPreferences();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7).commit();
}
if (prevAppVersion < VERSION_3_7_01) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
if (event.equals(AppInitializer.InitEvents.FAVORITES_INITIALIZED)) {
app.getFavorites().fixBlackBackground();
}
}
@Override
public void onFinish(AppInitializer init) {
}
});
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7_01).commit();
}
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true;
}
} }
} }
@ -104,4 +128,30 @@ class AppVersionUpgradeOnInit {
int getPrevAppVersion() { int getPrevAppVersion() {
return prevAppVersion; return prevAppVersion;
} }
public void resetFirstTimeRun(SharedPreferences startPrefs) {
if(startPrefs != null) {
startPrefs.edit().remove(FIRST_TIME_APP_RUN).commit();
}
}
public int getNumberOfStarts(SharedPreferences startPrefs) {
if(startPrefs == null) {
return 0;
}
return startPrefs.getInt(NUMBER_OF_STARTS, 1);
}
public long getFirstInstalledDays(SharedPreferences startPrefs) {
if(startPrefs == null) {
return 0;
}
long nd = startPrefs.getLong(FIRST_INSTALLED, 0);
return (System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l);
}
public boolean isFirstTime() {
return firstTime;
}
} }

View file

@ -3792,9 +3792,6 @@ public class OsmandSettings {
public final OsmandPreference<String> SELECTED_TRAVEL_BOOK = new StringPreference("selected_travel_book", "").makeGlobal(); public final OsmandPreference<String> SELECTED_TRAVEL_BOOK = new StringPreference("selected_travel_book", "").makeGlobal();
public final OsmandPreference<Boolean> SHOW_TRAVEL_UPDATE_CARD = new BooleanPreference("show_travel_update_card", true).makeGlobal();
public final OsmandPreference<Boolean> SHOW_TRAVEL_NEEDED_MAPS_CARD = new BooleanPreference("show_travel_needed_maps_card", true).makeGlobal();
public final ListStringPreference DISPLAYED_TRANSPORT_SETTINGS = (ListStringPreference) public final ListStringPreference DISPLAYED_TRANSPORT_SETTINGS = (ListStringPreference)
new ListStringPreference("displayed_transport_settings", null, ",").makeProfile(); new ListStringPreference("displayed_transport_settings", null, ",").makeProfile();

View file

@ -48,6 +48,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite"; private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite";
private static boolean SHOW_TRAVEL_UPDATE_CARD = true;
private static boolean SHOW_TRAVEL_NEEDED_MAPS_CARD = true;
@Nullable @Nullable
private ExploreRvAdapter adapter = new ExploreRvAdapter(); private ExploreRvAdapter adapter = new ExploreRvAdapter();
private boolean nightMode; private boolean nightMode;
@ -237,7 +240,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
boolean needsDownloading = mainIndexItem != null && !mainIndexItem.isDownloaded(); boolean needsDownloading = mainIndexItem != null && !mainIndexItem.isDownloaded();
File selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook(); File selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
if (selectedTravelBook == null || needsDownloading || (outdated && app.getSettings().SHOW_TRAVEL_UPDATE_CARD.get())) { if (selectedTravelBook == null || needsDownloading || (outdated && SHOW_TRAVEL_UPDATE_CARD)) {
boolean showOtherMaps = false; boolean showOtherMaps = false;
if (needsDownloading) { if (needsDownloading) {
List<IndexItem> items = downloadThread.getIndexes().getWikivoyageItems(); List<IndexItem> items = downloadThread.getIndexes().getWikivoyageItems();
@ -261,7 +264,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
downloadThread.cancelDownload(mainIndexItem); downloadThread.cancelDownload(mainIndexItem);
adapter.updateDownloadUpdateCard(false); adapter.updateDownloadUpdateCard(false);
} else if (!downloadUpdateCard.isDownload()) { } else if (!downloadUpdateCard.isDownload()) {
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(false); SHOW_TRAVEL_UPDATE_CARD = false;
removeDownloadUpdateCard(); removeDownloadUpdateCard();
} else if (downloadUpdateCard.isShowOtherMapsBtn()) { } else if (downloadUpdateCard.isShowOtherMapsBtn()) {
Activity activity = getActivity(); Activity activity = getActivity();
@ -282,7 +285,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
private void addNeededMapsCard() { private void addNeededMapsCard() {
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
if (app != null && !neededIndexItems.isEmpty() && adapter != null && app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.get()) { if (app != null && !neededIndexItems.isEmpty() && adapter != null && SHOW_TRAVEL_NEEDED_MAPS_CARD) {
neededMapsCard = new TravelNeededMapsCard(app, nightMode, neededIndexItems); neededMapsCard = new TravelNeededMapsCard(app, nightMode, neededIndexItems);
neededMapsCard.setListener(new TravelNeededMapsCard.CardListener() { neededMapsCard.setListener(new TravelNeededMapsCard.CardListener() {
@Override @Override
@ -301,7 +304,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
adapter.updateNeededMapsCard(false); adapter.updateNeededMapsCard(false);
} }
} else { } else {
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(false); SHOW_TRAVEL_NEEDED_MAPS_CARD = false;
removeNeededMapsCard(); removeNeededMapsCard();
} }
} }