Fix upgrade process
This commit is contained in:
parent
07d0b43807
commit
082a24a21a
5 changed files with 128 additions and 111 deletions
|
@ -26,7 +26,7 @@ public class PoiFilter extends AbstractPoiType {
|
|||
}
|
||||
|
||||
public void addPoiType(PoiType type) {
|
||||
if(!map.containsKey(type.getKeyName())) {
|
||||
if (!map.containsKey(type.getKeyName())) {
|
||||
poiTypes.add(type);
|
||||
map.put(type.getKeyName(), type);
|
||||
} else {
|
||||
|
|
|
@ -83,9 +83,7 @@ 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.AppVersionUpgradeOnInit.LAST_APP_VERSION;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
|
||||
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 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 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 boolean initSettings = false;
|
||||
private boolean firstTime;
|
||||
private boolean activityChangesShowed = false;
|
||||
private long startTime;
|
||||
private long startBgTime;
|
||||
|
@ -168,52 +162,25 @@ public class AppInitializer implements IProgress {
|
|||
startPrefs = app.getSharedPreferences(
|
||||
getLocalClassName(app.getAppCustomization().getMapActivity().getName()),
|
||||
Context.MODE_PRIVATE);
|
||||
if(!startPrefs.contains(NUMBER_OF_STARTS)) {
|
||||
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);
|
||||
appVersionUpgrade.upgradeVersion(startPrefs, LAST_APP_VERSION);
|
||||
initSettings = true;
|
||||
}
|
||||
|
||||
public int getNumberOfStarts() {
|
||||
if(startPrefs == null) {
|
||||
return 0;
|
||||
}
|
||||
return startPrefs.getInt(NUMBER_OF_STARTS, 1);
|
||||
return appVersionUpgrade.getNumberOfStarts(startPrefs);
|
||||
}
|
||||
|
||||
public long getFirstInstalledDays() {
|
||||
if(startPrefs == null) {
|
||||
return 0;
|
||||
}
|
||||
long nd = startPrefs.getLong(FIRST_INSTALLED, 0);
|
||||
|
||||
return (System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l);
|
||||
return appVersionUpgrade.getFirstInstalledDays(startPrefs);
|
||||
}
|
||||
|
||||
public void resetFirstTimeRun() {
|
||||
if(startPrefs != null) {
|
||||
startPrefs.edit().remove(FIRST_TIME_APP_RUN).commit();
|
||||
}
|
||||
appVersionUpgrade.resetFirstTimeRun(startPrefs);
|
||||
}
|
||||
|
||||
public boolean isFirstTime() {
|
||||
initVariables();
|
||||
return firstTime;
|
||||
return appVersionUpgrade.isFirstTime();
|
||||
}
|
||||
|
||||
public boolean isAppVersionChanged() {
|
||||
|
@ -226,7 +193,7 @@ public class AppInitializer implements IProgress {
|
|||
|
||||
public boolean checkAppVersionChanged() {
|
||||
initVariables();
|
||||
boolean showRecentChangesDialog = !firstTime && isAppVersionChanged();
|
||||
boolean showRecentChangesDialog = !isFirstTime() && isAppVersionChanged();
|
||||
// showRecentChangesDialog = true;
|
||||
if (showRecentChangesDialog && !activityChangesShowed) {
|
||||
activityChangesShowed = true;
|
||||
|
@ -252,7 +219,7 @@ public class AppInitializer implements IProgress {
|
|||
long size = activity.getPreferences(Context.MODE_PRIVATE).getLong(EXCEPTION_FILE_SIZE, 0);
|
||||
final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
if (size != file.length() && !firstTime) {
|
||||
if (size != file.length() && !isFirstTime()) {
|
||||
if (writeFileSize) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,11 @@ import android.annotation.SuppressLint;
|
|||
import android.content.SharedPreferences;
|
||||
|
||||
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
|
||||
public static final int VERSION_2_2 = 22;
|
||||
// 23 - 2.3
|
||||
|
@ -16,80 +21,99 @@ class AppVersionUpgradeOnInit {
|
|||
public static final int VERSION_3_6 = 36;
|
||||
// 37 - 3.7
|
||||
public static final int VERSION_3_7 = 37;
|
||||
// 3701 - 3.7.0.1
|
||||
public static final int VERSION_3_7_0_1 = 3701; // from 3.7.0.1 - 4 digit version
|
||||
// 3701 - 3.7-01 (4 digits 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";
|
||||
|
||||
private OsmandApplication app;
|
||||
private int prevAppVersion;
|
||||
private boolean appVersionChanged;
|
||||
private boolean firstTime;
|
||||
|
||||
AppVersionUpgradeOnInit(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
void upgradeVersion(SharedPreferences startPrefs, int versionToUpgrade) {
|
||||
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
|
||||
if (needsUpgrade(startPrefs, versionToUpgrade)) {
|
||||
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_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();
|
||||
}
|
||||
|
||||
void upgradeVersion(SharedPreferences startPrefs, int lastVersion) {
|
||||
if(!startPrefs.contains(NUMBER_OF_STARTS)) {
|
||||
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();
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3792,9 +3792,6 @@ public class OsmandSettings {
|
|||
|
||||
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)
|
||||
new ListStringPreference("displayed_transport_settings", null, ",").makeProfile();
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
|
||||
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
|
||||
private ExploreRvAdapter adapter = new ExploreRvAdapter();
|
||||
private boolean nightMode;
|
||||
|
@ -237,7 +240,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
boolean needsDownloading = mainIndexItem != null && !mainIndexItem.isDownloaded();
|
||||
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;
|
||||
if (needsDownloading) {
|
||||
List<IndexItem> items = downloadThread.getIndexes().getWikivoyageItems();
|
||||
|
@ -261,7 +264,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
downloadThread.cancelDownload(mainIndexItem);
|
||||
adapter.updateDownloadUpdateCard(false);
|
||||
} else if (!downloadUpdateCard.isDownload()) {
|
||||
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(false);
|
||||
SHOW_TRAVEL_UPDATE_CARD = false;
|
||||
removeDownloadUpdateCard();
|
||||
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
|
||||
Activity activity = getActivity();
|
||||
|
@ -282,7 +285,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
|
||||
private void addNeededMapsCard() {
|
||||
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.setListener(new TravelNeededMapsCard.CardListener() {
|
||||
@Override
|
||||
|
@ -301,7 +304,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
|||
adapter.updateNeededMapsCard(false);
|
||||
}
|
||||
} else {
|
||||
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(false);
|
||||
SHOW_TRAVEL_NEEDED_MAPS_CARD = false;
|
||||
removeNeededMapsCard();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue