From beb6a1805ff580e7a33a06c047f4a3ee6cfd3533 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 14 May 2020 19:06:37 +0300 Subject: [PATCH 1/9] Fix #8926 Default color of Favorites changed to black --- .../main/java/net/osmand/GPXUtilities.java | 4 ++-- OsmAnd/build.gradle | 4 ++-- .../src/net/osmand/data/FavouritePoint.java | 15 ++++++++----- .../src/net/osmand/plus/AppInitializer.java | 14 +++++++++++- .../net/osmand/plus/FavouritesDbHelper.java | 22 +++++++++++++++++++ .../activities/FavoritesTreeFragment.java | 3 ++- .../plus/base/FavoriteImageDrawable.java | 7 ++++-- .../net/osmand/plus/helpers/ImportHelper.java | 3 ++- .../FavoritePointEditorFragmentNew.java | 4 +++- .../editors/PointEditorFragmentNew.java | 2 +- .../editors/WptPtEditorFragmentNew.java | 6 +++-- 11 files changed, 65 insertions(+), 19 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 2fe8a6e033..58c3840b01 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -46,7 +46,7 @@ public class GPXUtilities { private static final String ICON_NAME_EXTENSION = "icon"; private static final String DEFAULT_ICON_NAME = "special_star"; private static final String BACKGROUND_TYPE_EXTENSION = "background"; - private static final String DEFAULT_BACKGROUND_TYPE = "circle"; + private static final String DEFAULT_BACKGROUND_TYPE_NAME = "circle"; private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$ @@ -294,7 +294,7 @@ public class GPXUtilities { public String getBackgroundType() { String backgroundType = getExtensionsToRead().get(BACKGROUND_TYPE_EXTENSION); if (backgroundType == null) { - backgroundType = DEFAULT_BACKGROUND_TYPE; + backgroundType = DEFAULT_BACKGROUND_TYPE_NAME; } return backgroundType; } diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index 6bebf5f67b..438f9e564b 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -45,10 +45,10 @@ android { defaultConfig { minSdkVersion System.getenv("MIN_SDK_VERSION") ? System.getenv("MIN_SDK_VERSION").toInteger() : 15 targetSdkVersion 28 - versionCode 370 + versionCode 371 versionCode System.getenv("APK_NUMBER_VERSION") ? System.getenv("APK_NUMBER_VERSION").toInteger() : versionCode multiDexEnabled true - versionName "3.7.0" + versionName "3.7.1" 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 plugin’s automatic rasterization of vectors diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 95236d4815..814e1103bd 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -5,6 +5,7 @@ import android.content.Context; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.StringRes; +import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.FavouritesDbHelper; @@ -19,6 +20,8 @@ public class FavouritePoint implements Serializable, LocationPoint { private static final String HIDDEN = "hidden"; private static final String ADDRESS_EXTENSION = "address"; + public static final BackgroundType DEFAULT_BACKGROUND_TYPE = BackgroundType.CIRCLE; + public static final int DEFAULT_UI_ICON_ID = R.drawable.mx_special_star; protected String name = ""; protected String description; @@ -93,7 +96,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } public int getIconId() { - return iconId == 0 ? R.drawable.mx_special_star : iconId; + return iconId == 0 ? DEFAULT_UI_ICON_ID : iconId; } public String getIconEntryName(Context ctx) { @@ -198,7 +201,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } public BackgroundType getBackgroundType() { - return backgroundType == null ? BackgroundType.CIRCLE : backgroundType; + return backgroundType == null ? DEFAULT_BACKGROUND_TYPE : backgroundType; } public void setBackgroundType(BackgroundType backgroundType) { @@ -351,7 +354,7 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconName != null) { fp.setIconIdFromName(ctx, iconName); } - BackgroundType backgroundType = BackgroundType.getByTypeName(pt.getBackgroundType(), BackgroundType.CIRCLE); + BackgroundType backgroundType = BackgroundType.getByTypeName(pt.getBackgroundType(), DEFAULT_BACKGROUND_TYPE); fp.setBackgroundType(backgroundType); return fp; } @@ -366,13 +369,13 @@ public class FavouritePoint implements Serializable, LocationPoint { if (isAddressSpecified()) { pt.getExtensionsToWrite().put(ADDRESS_EXTENSION, getAddress()); } - if (iconId != 0) { + if (iconId != 0 && iconId != DEFAULT_UI_ICON_ID) { pt.setIconName(getIconEntryName(ctx).substring(3)); } - if(backgroundType != null) { + if (backgroundType != null && backgroundType != DEFAULT_BACKGROUND_TYPE) { pt.setBackgroundType(backgroundType.typeName); } - if (getColor() != 0) { + if (getColor() != 0 && getColor() != ContextCompat.getColor(ctx, R.color.color_favorite)) { pt.setColor(getColor()); } pt.name = getName(); diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 663e0dad42..3321c2864f 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -228,8 +228,20 @@ public class AppInitializer implements IProgress { app.getSettings().migratePreferences(); startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_6).commit(); } - if (prevAppVersion < VERSION_3_7) { + 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(); diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 3decf9e607..e94240e86b 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -183,6 +183,28 @@ public class FavouritesDbHelper { }); } + void fixBlackBackground() { + flatGroups.clear(); + favoriteGroups.clear(); + for (FavouritePoint fp : cachedFavoritePoints) { + if (fp.getColor() == 0xFF000000) { + fp.setColor(0); + } + FavoriteGroup group = getOrCreateGroup(fp, 0); + group.points.add(fp); + } + sortAll(); + saveCurrentPointsIntoFile(); + context.runInUIThread(new Runnable() { + @Override + public void run() { + for (FavoritesListener listener : listeners) { + listener.onFavoritesLoaded(); + } + } + }); + } + public FavouritePoint getSpecialPoint(FavouritePoint.SpecialPointType pointType) { for (FavouritePoint fp : cachedFavoritePoints) { if (fp.getSpecialPointType() == pointType) { diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index d44c8d4bf3..35c75c40f7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -68,6 +68,7 @@ import java.util.Map; import java.util.Set; import static android.view.Gravity.CENTER; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; @@ -964,7 +965,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen ? app.getFavorites().getColorWithCategory(model, getResources().getColor(R.color.color_favorite)) : ContextCompat.getColor(app, disabledIconColor); int iconSize = (int) getResources().getDimension(R.dimen.favorites_icon_size); - if(model.getBackgroundType().equals(FavouritePoint.BackgroundType.CIRCLE)){ + if (model.getBackgroundType().equals(DEFAULT_BACKGROUND_TYPE)) { icon.setImageDrawable(UiUtilities.createTintedDrawable(getActivity(), model.getIconId(), color)); iconSize = (int) getResources().getDimension(R.dimen.standard_icon_size); }else { diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 5999468241..53f4c0ee1b 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -23,6 +23,9 @@ import net.osmand.plus.UiUtilities; import java.util.TreeMap; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; +import static net.osmand.data.FavouritePoint.DEFAULT_UI_ICON_ID; + public class FavoriteImageDrawable extends Drawable { private boolean withShadow; @@ -55,7 +58,7 @@ public class FavoriteImageDrawable extends Drawable { uiIconId = overlayIconId; } else { favIcon = res.getDrawable(R.drawable.mm_special_star); - uiIconId = R.drawable.mx_special_star; + uiIconId = DEFAULT_UI_ICON_ID; } int col = color == 0 ? res.getColor(R.color.color_favorite) : color; uiListIcon = uiUtilities.getIcon(uiIconId, R.color.color_white); @@ -217,7 +220,7 @@ public class FavoriteImageDrawable extends Drawable { if (pt != null) { point = new FavouritePoint(pt.getLatitude(), pt.getLongitude(), pt.name, pt.category); point.setIconIdFromName(a, pt.getIconName()); - point.setBackgroundType(BackgroundType.getByTypeName(pt.getBackgroundType(), BackgroundType.CIRCLE)); + point.setBackgroundType(BackgroundType.getByTypeName(pt.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); } return point; } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 8ceb40eb42..f06adb6361 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -86,6 +86,7 @@ import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT; import static net.osmand.IndexConstants.RENDERER_INDEX_EXT; import static net.osmand.IndexConstants.ROUTING_FILE_EXT; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; import static net.osmand.plus.AppInitializer.loadRoutingFiles; import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; @@ -1190,7 +1191,7 @@ public class ImportHelper { } fp.setColor(p.getColor(0)); fp.setIconIdFromName(app, p.getIconName()); - fp.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), BackgroundType.CIRCLE)); + fp.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); favourites.add(fp); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 0986437dc0..9534f06f1d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -34,6 +34,8 @@ import net.osmand.util.Algorithms; import java.util.LinkedHashSet; import java.util.Set; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; + public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Nullable @@ -45,7 +47,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { private int color; private int iconId; @NonNull - private BackgroundType backgroundType = BackgroundType.CIRCLE; + private BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE; @Nullable private FavouritesDbHelper helper; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 59de7e4f9b..59dbf8e3cb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -78,7 +78,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { private int selectedIcon; @ColorInt private int selectedColor; - private BackgroundType selectedShape = BackgroundType.CIRCLE; + private BackgroundType selectedShape = DEFAULT_BACKGROUND_TYPE; private ImageView nameIcon; private GroupAdapter groupListAdapter; private int scrollViewY; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index 3b15fcb72d..433ca99dfc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -37,6 +37,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; + public class WptPtEditorFragmentNew extends PointEditorFragmentNew { @Nullable @@ -54,7 +56,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { protected boolean skipDialog; private String iconName; @NonNull - private String backgroundTypeName = BackgroundType.CIRCLE.getTypeName(); + private String backgroundTypeName = DEFAULT_BACKGROUND_TYPE.getTypeName(); private Map categoriesMap; private OsmandApplication app; @@ -432,7 +434,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { @Override public BackgroundType getBackgroundType() { - return BackgroundType.getByTypeName(backgroundTypeName, BackgroundType.CIRCLE); + return BackgroundType.getByTypeName(backgroundTypeName, DEFAULT_BACKGROUND_TYPE); } @Override From 48fb775f51ad48f6759a22219b6504a24c18890f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 15 May 2020 11:49:54 +0300 Subject: [PATCH 2/9] Refactoring AppInitializer --- OsmAnd/build.gradle | 4 +- .../src/net/osmand/plus/AppInitializer.java | 83 +++---------------- .../net/osmand/plus/FavouritesDbHelper.java | 13 ++- .../net/osmand/plus/OsmandApplication.java | 2 +- 4 files changed, 18 insertions(+), 84 deletions(-) diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index 438f9e564b..6bebf5f67b 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -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 plugin’s automatic rasterization of vectors diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 3321c2864f..0587dce343 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index e94240e86b..42e8a01554 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -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() { diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 895c3a1d36..cf6c191124 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -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(); From 07d0b438070f3f3bab8610aa4eb3ecc9e8443404 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 15 May 2020 11:50:59 +0300 Subject: [PATCH 3/9] Refactoring AppInitializer --- .../osmand/plus/AppVersionUpgradeOnInit.java | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java diff --git a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java new file mode 100644 index 0000000000..4a7d3d3fd8 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java @@ -0,0 +1,107 @@ +package net.osmand.plus; + +import android.annotation.SuppressLint; +import android.content.SharedPreferences; + +class AppVersionUpgradeOnInit { + // 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; + // 3701 - 3.7.0.1 + public static final int VERSION_3_7_0_1 = 3701; // from 3.7.0.1 - 4 digit version + + 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; + + 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(); + } + + startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); + appVersionChanged = true; + } + } + + private boolean needsUpgrade(SharedPreferences startPrefs, int maxVersion) { + return !(Version.getFullVersion(app)).equals(startPrefs.getString(VERSION_INSTALLED, "")) || prevAppVersion < maxVersion; + } + + boolean isAppVersionChanged() { + return appVersionChanged; + } + + int getPrevAppVersion() { + return prevAppVersion; + } +} From 082a24a21a0174d261e944ce53730b36cc24c851 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 15 May 2020 15:51:54 +0200 Subject: [PATCH 4/9] Fix upgrade process --- .../main/java/net/osmand/osm/PoiFilter.java | 2 +- .../src/net/osmand/plus/AppInitializer.java | 51 +----- .../osmand/plus/AppVersionUpgradeOnInit.java | 172 +++++++++++------- .../src/net/osmand/plus/OsmandSettings.java | 3 - .../explore/ExploreTabFragment.java | 11 +- 5 files changed, 128 insertions(+), 111 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java b/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java index a4d2a79396..8063c0c5ab 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java @@ -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 { diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 0587dce343..61603b1dc9 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -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(); } diff --git a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java index 4a7d3d3fd8..e4f720fa14 100644 --- a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java +++ b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java @@ -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; + } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b70668e34d..fcf5f09908 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -3792,9 +3792,6 @@ public class OsmandSettings { public final OsmandPreference SELECTED_TRAVEL_BOOK = new StringPreference("selected_travel_book", "").makeGlobal(); - public final OsmandPreference SHOW_TRAVEL_UPDATE_CARD = new BooleanPreference("show_travel_update_card", true).makeGlobal(); - public final OsmandPreference 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(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index 72a235c956..bedaa96810 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -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 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(); } } From d3ab1445aae5c085114fbe9d11fa9c8fdfef2a01 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 15 May 2020 20:21:23 +0300 Subject: [PATCH 5/9] Fix #8901 --- OsmAnd/AndroidManifest.xml | 14 ++++++ .../src/net/osmand/AndroidNetworkUtils.java | 47 +++++++++++++++++++ .../osmand/plus/activities/MapActivity.java | 46 ++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index bb1715f495..95599f2c0e 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -133,6 +133,20 @@ + + + + + + + + + + + + + +