From 80907c77a9e4dd5497166393bc7f85907c237da6 Mon Sep 17 00:00:00 2001 From: Alexander Marchuk Date: Tue, 9 Feb 2016 17:13:19 +0300 Subject: [PATCH] [new downloader][android] refactor: Routing error dialog adapted. fix: Shorthand for creating CountryItem`s. --- android/jni/com/mapswithme/maps/Framework.hpp | 3 +- .../jni/com/mapswithme/maps/MapManager.cpp | 8 +- .../maps/DownloadResourcesActivity.java | 24 +-- .../src/com/mapswithme/maps/Framework.java | 14 +- .../src/com/mapswithme/maps/MapFragment.java | 3 +- .../src/com/mapswithme/maps/MwmActivity.java | 25 ++-- .../mapswithme/maps/background/Notifier.java | 24 +-- .../maps/background/WorkerService.java | 31 ++-- .../maps/downloader/CountryItem.java | 7 + .../downloader/CountrySuggestFragment.java | 12 +- .../maps/downloader/MapManager.java | 4 +- .../maps/routing/ResultCodesHelper.java | 43 +++--- .../maps/routing/RoutingController.java | 20 +-- .../routing/RoutingErrorDialogFragment.java | 138 ++++++------------ .../maps/search/SearchFragment.java | 6 +- .../util/statistics/Statistics.java | 4 +- routing/router.hpp | 3 +- 17 files changed, 152 insertions(+), 217 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index f238070b79..814d8fbdf3 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -29,8 +29,7 @@ // TODO (trashkalmar): remove old downloader's stuff namespace android { - class Framework //: public storage::CountryTree::CountryTreeListener, - // public storage::ActiveMapsLayout::ActiveMapsListener + class Framework { private: drape_ptr m_contextFactory; diff --git a/android/jni/com/mapswithme/maps/MapManager.cpp b/android/jni/com/mapswithme/maps/MapManager.cpp index d7dec78755..baf7a7716a 100644 --- a/android/jni/com/mapswithme/maps/MapManager.cpp +++ b/android/jni/com/mapswithme/maps/MapManager.cpp @@ -90,11 +90,11 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeSetAutodownload(JNIEnv * en g_framework->SetAutodownloadMaps(enable); } -// static boolean nativeHasDownloadedMaps(); -JNIEXPORT jboolean JNICALL -Java_com_mapswithme_maps_downloader_MapManager_nativeHasDownloadedMaps(JNIEnv * env, jclass clazz) +// static int nativeGetDownloadedCount(); +JNIEXPORT jint JNICALL +Java_com_mapswithme_maps_downloader_MapManager_nativeGetDownloadedCount(JNIEnv * env, jclass clazz) { - return (GetStorage().GetDownloadedFilesCount() != 0); + return GetStorage().GetDownloadedFilesCount(); } // static String nativeGetRootNode(); diff --git a/android/src/com/mapswithme/maps/DownloadResourcesActivity.java b/android/src/com/mapswithme/maps/DownloadResourcesActivity.java index 21215eeef7..a96a66edbf 100644 --- a/android/src/com/mapswithme/maps/DownloadResourcesActivity.java +++ b/android/src/com/mapswithme/maps/DownloadResourcesActivity.java @@ -24,7 +24,6 @@ import java.io.OutputStream; import com.mapswithme.maps.MwmActivity.MapTask; import com.mapswithme.maps.MwmActivity.OpenUrlTask; -import com.mapswithme.maps.downloader.country.OldMapStorage.Index; import com.mapswithme.maps.api.Const; import com.mapswithme.maps.api.ParsedMwmRequest; import com.mapswithme.maps.base.BaseMwmFragmentActivity; @@ -47,8 +46,8 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity { private static final String TAG = DownloadResourcesActivity.class.getName(); - static final String EXTRA_COUNTRY_INDEX = ".extra.index"; - static final String EXTRA_AUTODOWNLOAD_COUNTRY = ".extra.autodownload"; + static final String EXTRA_COUNTRY = "country"; + static final String EXTRA_AUTODOWNLOAD = "autodownload"; // Error codes, should match the same codes in JNI private static final int ERR_DOWNLOAD_SUCCESS = 0; @@ -117,8 +116,7 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity return; } - CountryItem item = new CountryItem(mCurrentCountry); - MapManager.nativeGetAttributes(item); + CountryItem item = CountryItem.fill(mCurrentCountry); UiUtils.show(mTvLocation); @@ -434,8 +432,7 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity Framework.nativeRegisterMaps(); if (mCurrentCountry != null && mChbDownloadCountry.isChecked()) { - CountryItem item = new CountryItem(mCurrentCountry); - MapManager.nativeGetAttributes(item); + CountryItem item = CountryItem.fill(mCurrentCountry); UiUtils.hide(mChbDownloadCountry, mTvLocation); mTvMessage.setText(getString(R.string.downloading_country_can_proceed, item.name)); @@ -600,18 +597,21 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity @Override public boolean isSupported(Intent intent) { - return intent.hasExtra(EXTRA_COUNTRY_INDEX); + return intent.hasExtra(EXTRA_COUNTRY); } @Override public boolean process(Intent intent) { - final Index index = (Index) intent.getSerializableExtra(EXTRA_COUNTRY_INDEX); - final boolean autoDownload = intent.getBooleanExtra(EXTRA_AUTODOWNLOAD_COUNTRY, false); + String countryId = intent.getStringExtra(EXTRA_COUNTRY); + final boolean autoDownload = intent.getBooleanExtra(EXTRA_AUTODOWNLOAD, false); if (autoDownload) Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOAD_COUNTRY_NOTIFICATION_CLICKED); - mMapTaskToForward = new MwmActivity.ShowCountryTask(index, autoDownload); - org.alohalytics.Statistics.logEvent("OpenCountryTaskProcessor::process", new String[]{"autoDownload", String.valueOf(autoDownload)}, LocationHelper.INSTANCE.getLastLocation()); + + mMapTaskToForward = new MwmActivity.ShowCountryTask(countryId, autoDownload); + org.alohalytics.Statistics.logEvent("OpenCountryTaskProcessor::process", + new String[] { "autoDownload", String.valueOf(autoDownload) }, + LocationHelper.INSTANCE.getLastLocation()); return true; } } diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index f9a054c0c9..353790a33c 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -3,7 +3,6 @@ package com.mapswithme.maps; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.mapswithme.maps.downloader.country.OldMapStorage.Index; import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.routing.RoutingInfo; @@ -33,7 +32,7 @@ public class Framework @SuppressWarnings("unused") public interface RoutingListener { - void onRoutingEvent(int resultCode, Index[] missingCountries, Index[] missingRoutes); + void onRoutingEvent(int resultCode, String[] missingMaps); } @SuppressWarnings("unused") @@ -137,16 +136,7 @@ public class Framework public static native void nativeSetRouteProgressListener(RoutingProgressListener listener); - public static native String nativeGetCountryNameIfAbsent(double lat, double lon); - - public static native Index nativeGetCountryIndex(double lat, double lon); - - public static native String nativeGetViewportCountryNameIfAbsent(); - - public static native void nativeShowCountry(Index idx, boolean zoomToDownloadButton); - - // TODO consider removal of that methods - public static native void nativeDownloadCountry(Index idx); + public static native void nativeShowCountry(String countryId, boolean zoomToDownloadButton); public static native double[] nativePredictLocation(double lat, double lon, double accuracy, double bearing, double speed, double elapsedSeconds); diff --git a/android/src/com/mapswithme/maps/MapFragment.java b/android/src/com/mapswithme/maps/MapFragment.java index 20596b55bd..3dfec702bc 100644 --- a/android/src/com/mapswithme/maps/MapFragment.java +++ b/android/src/com/mapswithme/maps/MapFragment.java @@ -295,8 +295,7 @@ public class MapFragment extends BaseMwmFragment return; } - CountryItem item = new CountryItem(countryId); - MapManager.nativeGetAttributes(item); + CountryItem item = CountryItem.fill(countryId); DownloadHelper.downloadWithCellularCheck(getActivity(), item.size, item.name, new DownloadHelper.OnDownloadListener() { @Override diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index c898ee0223..9731bf4d34 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -28,7 +28,6 @@ import java.io.Serializable; import java.util.Stack; import com.mapswithme.maps.Framework.MapObjectListener; -import com.mapswithme.maps.downloader.country.OldMapStorage.Index; import com.mapswithme.maps.activity.CustomNavigateUpListener; import com.mapswithme.maps.ads.LikesManager; import com.mapswithme.maps.api.ParsedMwmRequest; @@ -41,8 +40,6 @@ import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.downloader.DownloaderActivity; import com.mapswithme.maps.downloader.DownloaderFragment; import com.mapswithme.maps.downloader.MapManager; -import com.mapswithme.maps.downloader.country.OldActiveCountryTree; -import com.mapswithme.maps.downloader.country.OldDownloadFragment; import com.mapswithme.maps.editor.EditorActivity; import com.mapswithme.maps.editor.EditorHostFragment; import com.mapswithme.maps.location.LocationHelper; @@ -99,7 +96,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private static final String EXTRA_UPDATE_COUNTRIES = ".extra.update.countries"; private static final String[] DOCKED_FRAGMENTS = { SearchFragment.class.getName(), - OldDownloadFragment.class.getName(), + DownloaderFragment.class.getName(), RoutingPlanFragment.class.getName(), EditorHostFragment.class.getName() }; // Instance state @@ -160,11 +157,11 @@ public class MwmActivity extends BaseMwmFragmentActivity } } - public static Intent createShowMapIntent(Context context, Index index, boolean doAutoDownload) + public static Intent createShowMapIntent(Context context, String countryId, boolean doAutoDownload) { return new Intent(context, DownloadResourcesActivity.class) - .putExtra(DownloadResourcesActivity.EXTRA_COUNTRY_INDEX, index) - .putExtra(DownloadResourcesActivity.EXTRA_AUTODOWNLOAD_COUNTRY, doAutoDownload); + .putExtra(DownloadResourcesActivity.EXTRA_COUNTRY, countryId) + .putExtra(DownloadResourcesActivity.EXTRA_AUTODOWNLOAD, doAutoDownload); } public static Intent createUpdateMapsIntent() @@ -663,7 +660,8 @@ public class MwmActivity extends BaseMwmFragmentActivity addTask(intent); else if (intent.hasExtra(EXTRA_UPDATE_COUNTRIES)) { - OldActiveCountryTree.updateAll(); + // TODO (trashkalmar): Update all maps in downloader + //OldActiveCountryTree.updateAll(); showDownloader(true); } } @@ -1206,12 +1204,12 @@ public class MwmActivity extends BaseMwmFragmentActivity public static class ShowCountryTask implements MapTask { private static final long serialVersionUID = 1L; - private final Index mIndex; + private final String mCountryId; private final boolean mDoAutoDownload; - public ShowCountryTask(Index index, boolean doAutoDownload) + public ShowCountryTask(String countryId, boolean doAutoDownload) { - mIndex = index; + mCountryId = countryId; mDoAutoDownload = doAutoDownload; } @@ -1219,8 +1217,9 @@ public class MwmActivity extends BaseMwmFragmentActivity public boolean run(MwmActivity target) { if (mDoAutoDownload) - Framework.nativeDownloadCountry(mIndex); - Framework.nativeShowCountry(mIndex, mDoAutoDownload); + MapManager.nativeDownload(mCountryId); + + Framework.nativeShowCountry(mCountryId, mDoAutoDownload); return true; } } diff --git a/android/src/com/mapswithme/maps/background/Notifier.java b/android/src/com/mapswithme/maps/background/Notifier.java index 596815fdb4..5b7d1f75ab 100644 --- a/android/src/com/mapswithme/maps/background/Notifier.java +++ b/android/src/com/mapswithme/maps/background/Notifier.java @@ -7,10 +7,10 @@ import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; -import com.mapswithme.maps.downloader.country.OldMapStorage.Index; import com.mapswithme.maps.MwmActivity; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.downloader.CountryItem; import com.mapswithme.util.StringUtils; import com.mapswithme.util.statistics.Statistics; @@ -34,24 +34,26 @@ public final class Notifier placeNotification(title, countryName, pi, ID_UPDATE_AVAILABLE); } - public static void notifyDownloadFailed(Index idx, String countryName) + public static void notifyDownloadFailed(String countryId) { - final String title = APP.getString(R.string.app_name); - final String content = APP.getString(R.string.download_country_failed, countryName); + CountryItem item = CountryItem.fill(countryId); - final PendingIntent pi = PendingIntent.getActivity(APP, 0, - MwmActivity.createShowMapIntent(APP, idx, false).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), - PendingIntent.FLAG_UPDATE_CURRENT); + String title = APP.getString(R.string.app_name); + String content = APP.getString(R.string.download_country_failed, item.name); + + PendingIntent pi = PendingIntent.getActivity(APP, 0, MwmActivity.createShowMapIntent(APP, countryId, false) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), + PendingIntent.FLAG_UPDATE_CURRENT); placeNotification(title, content, pi, ID_DOWNLOAD_FAILED); Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN); } - public static void notifyDownloadSuggest(String title, String content, Index countryIndex) + public static void notifyDownloadSuggest(String title, String content, String countryId) { - final PendingIntent pi = PendingIntent.getActivity(APP, 0, - MwmActivity.createShowMapIntent(APP, countryIndex, true).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pi = PendingIntent.getActivity(APP, 0, MwmActivity.createShowMapIntent(APP, countryId, true) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), + PendingIntent.FLAG_UPDATE_CURRENT); placeNotification(title, content, pi, ID_DOWNLOAD_NEW_COUNTRY); Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN); diff --git a/android/src/com/mapswithme/maps/background/WorkerService.java b/android/src/com/mapswithme/maps/background/WorkerService.java index e04e166c7b..ec36d65e43 100644 --- a/android/src/com/mapswithme/maps/background/WorkerService.java +++ b/android/src/com/mapswithme/maps/background/WorkerService.java @@ -22,7 +22,6 @@ public class WorkerService extends IntentService private static final String ACTION_DOWNLOAD_COUNTRY = "com.mapswithme.maps.action.download_country"; private static final String ACTION_UPLOAD_OSM_CHANGES = "com.mapswithme.maps.action.upload_osm_changes"; - private static final MwmApplication APP = MwmApplication.get(); private static final SharedPreferences PREFS = MwmApplication.prefs(); /** @@ -151,23 +150,21 @@ public class WorkerService extends IntentService */ private static void placeDownloadNotification(Location l) { - final String country = Framework.nativeGetCountryNameIfAbsent(l.getLatitude(), l.getLongitude()); - if (!TextUtils.isEmpty(country)) + final String country = MapManager.nativeFindCountry(l.getLatitude(), l.getLongitude()); + if (TextUtils.isEmpty(country)) + return; + + final String lastNotification = PREFS.getString(country, null); + if (lastNotification != null) { - - final String lastNotification = PREFS.getString(country, null); - if (lastNotification != null) - { - // Do not place notification if it was displayed less than 180 days ago. - final long timeStamp = Long.valueOf(lastNotification); - final long outdatedMillis = 180L * 24 * 60 * 60 * 1000; - if (System.currentTimeMillis() - timeStamp < outdatedMillis) - return; - } - - Notifier.notifyDownloadSuggest(country, String.format(APP.getString(R.string.download_location_country), country), - Framework.nativeGetCountryIndex(l.getLatitude(), l.getLongitude())); - PREFS.edit().putString(country, String.valueOf(System.currentTimeMillis())).apply(); + // Do not place notification if it was displayed less than 180 days ago. + final long timeStamp = Long.valueOf(lastNotification); + final long outdatedMillis = 180L * 24 * 60 * 60 * 1000; + if (System.currentTimeMillis() - timeStamp < outdatedMillis) + return; } + + Notifier.notifyDownloadSuggest(country, MwmApplication.get().getString(R.string.download_location_country, country), country); + PREFS.edit().putString(country, String.valueOf(System.currentTimeMillis())).apply(); } } diff --git a/android/src/com/mapswithme/maps/downloader/CountryItem.java b/android/src/com/mapswithme/maps/downloader/CountryItem.java index f615f3ba08..a547c0772a 100644 --- a/android/src/com/mapswithme/maps/downloader/CountryItem.java +++ b/android/src/com/mapswithme/maps/downloader/CountryItem.java @@ -84,6 +84,13 @@ public final class CountryItem implements Comparable return name.compareTo(another.name); } + public static CountryItem fill(String countryId) + { + CountryItem res = new CountryItem(countryId); + MapManager.nativeGetAttributes(res); + return res; + } + @Override public String toString() { diff --git a/android/src/com/mapswithme/maps/downloader/CountrySuggestFragment.java b/android/src/com/mapswithme/maps/downloader/CountrySuggestFragment.java index 123c76f508..d66fdb69bc 100644 --- a/android/src/com/mapswithme/maps/downloader/CountrySuggestFragment.java +++ b/android/src/com/mapswithme/maps/downloader/CountrySuggestFragment.java @@ -76,10 +76,7 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl return; if (mDownloadingCountry == null) - { - mDownloadingCountry = new CountryItem(countryId); - MapManager.nativeGetAttributes(mDownloadingCountry); - } + mDownloadingCountry = CountryItem.fill(countryId); refreshViews(); @@ -105,10 +102,7 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl { String id = MapManager.nativeFindCountry(loc.getLatitude(), loc.getLongitude()); if (!TextUtils.isEmpty(id)) - { - mCurrentCountry = new CountryItem(id); - MapManager.nativeGetAttributes(mCurrentCountry); - } + mCurrentCountry = CountryItem.fill(id); } refreshViews(); @@ -161,7 +155,7 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl private void refreshViews() { - if (!isAdded() || MapManager.nativeHasDownloadedMaps()) + if (!isAdded() || MapManager.nativeGetDownloadedCount() > 0) return; boolean downloading = MapManager.nativeIsDownloading(); diff --git a/android/src/com/mapswithme/maps/downloader/MapManager.java b/android/src/com/mapswithme/maps/downloader/MapManager.java index d0041a6129..a6de66172a 100644 --- a/android/src/com/mapswithme/maps/downloader/MapManager.java +++ b/android/src/com/mapswithme/maps/downloader/MapManager.java @@ -47,9 +47,9 @@ public final class MapManager public static native String nativeGetRootNode(); /** - * Determines if any downloaded map is present (excluding fake MWMs). + * Return count of fully downloaded maps (excluding fake MWMs). */ - public static native boolean nativeHasDownloadedMaps(); + public static native int nativeGetDownloadedCount(); /** * Returns info about updatable data or null on error. diff --git a/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java b/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java index f796faaf18..0858afed32 100644 --- a/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java +++ b/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java @@ -3,36 +3,31 @@ package com.mapswithme.maps.routing; import android.content.res.Resources; import android.util.Pair; -import com.mapswithme.maps.LocationState; -import com.mapswithme.maps.MwmApplication; -import com.mapswithme.maps.downloader.country.OldMapStorage; -import com.mapswithme.maps.R; - import java.util.ArrayList; import java.util.List; +import com.mapswithme.maps.LocationState; +import com.mapswithme.maps.MwmApplication; +import com.mapswithme.maps.R; + class ResultCodesHelper { - // Codes correspond to native routing::IRouter::ResultCode - public static final int NO_ERROR = 0; - public static final int CANCELLED = 1; - public static final int NO_POSITION = 2; - public static final int INCONSISTENT_MWM_ROUTE = 3; - public static final int ROUTING_FILE_NOT_EXIST = 4; - public static final int START_POINT_NOT_FOUND = 5; - public static final int END_POINT_NOT_FOUND = 6; - public static final int DIFFERENT_MWM = 7; - public static final int ROUTE_NOT_FOUND = 8; - public static final int NEED_MORE_MAPS = 9; - public static final int INTERNAL_ERROR = 10; - public static final int FILE_TOO_OLD = 11; + // Codes correspond to native routing::IRouter::ResultCode in routing/router.hpp + static final int NO_ERROR = 0; + static final int CANCELLED = 1; + static final int NO_POSITION = 2; + static final int INCONSISTENT_MWM_ROUTE = 3; + static final int ROUTING_FILE_NOT_EXIST = 4; + static final int START_POINT_NOT_FOUND = 5; + static final int END_POINT_NOT_FOUND = 6; + static final int DIFFERENT_MWM = 7; + static final int ROUTE_NOT_FOUND = 8; + static final int NEED_MORE_MAPS = 9; + static final int INTERNAL_ERROR = 10; + static final int FILE_TOO_OLD = 11; - public static Pair getDialogTitleSubtitle(int errorCode, OldMapStorage.Index[] missingCountries) + static Pair getDialogTitleSubtitle(int errorCode, int missingCount) { - int missingCount = 0; - if (missingCountries != null) - missingCount = missingCountries.length; - Resources resources = MwmApplication.get().getResources(); int titleRes = 0; List messages = new ArrayList<>(); @@ -102,7 +97,7 @@ class ResultCodesHelper return new Pair<>(titleRes == 0 ? "" : resources.getString(titleRes), builder.toString()); } - public static boolean isDownloadable(int resultCode) + static boolean isDownloadable(int resultCode) { return resultCode == INCONSISTENT_MWM_ROUTE || resultCode == ROUTING_FILE_NOT_EXIST; } diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 3fa57317e6..dc45757a86 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -16,13 +16,11 @@ import android.widget.TextView; import java.util.Calendar; import java.util.concurrent.TimeUnit; -import com.mapswithme.maps.downloader.country.OldMapStorage; -import com.mapswithme.maps.downloader.country.OldActiveCountryTree; -import com.mapswithme.maps.downloader.country.OldStorageOptions; import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.Config; import com.mapswithme.util.StringUtils; @@ -91,15 +89,14 @@ public class RoutingController private boolean mHasContainerSavedState; private boolean mContainsCachedResult; private int mLastResultCode; - private OldMapStorage.Index[] mLastMissingCountries; - private OldMapStorage.Index[] mLastMissingRoutes; + private String[] mLastMissingMaps; private RoutingInfo mCachedRoutingInfo; @SuppressWarnings("FieldCanBeLocal") private final Framework.RoutingListener mRoutingListener = new Framework.RoutingListener() { @Override - public void onRoutingEvent(final int resultCode, final OldMapStorage.Index[] missingCountries, final OldMapStorage.Index[] missingRoutes) + public void onRoutingEvent(final int resultCode, final String[] missingMaps) { Log.d(TAG, "onRoutingEvent(resultCode: " + resultCode + ")"); @@ -109,8 +106,7 @@ public class RoutingController public void run() { mLastResultCode = resultCode; - mLastMissingCountries = missingCountries; - mLastMissingRoutes = missingRoutes; + mLastMissingMaps = missingMaps; mContainsCachedResult = true; if (mLastResultCode == ResultCodesHelper.NO_ERROR) @@ -163,7 +159,7 @@ public class RoutingController mLastBuildProgress = 0; updateProgress(); - RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(mLastResultCode, mLastMissingCountries, mLastMissingRoutes); + RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(mLastResultCode, mLastMissingMaps); fragment.setListener(new RoutingErrorDialogFragment.Listener() { @Override @@ -171,8 +167,8 @@ public class RoutingController { cancel(); - OldActiveCountryTree.downloadMapsForIndices(mLastMissingCountries, OldStorageOptions.MAP_OPTION_MAP_ONLY); - OldActiveCountryTree.downloadMapsForIndices(mLastMissingRoutes, OldStorageOptions.MAP_OPTION_MAP_ONLY); + for (String map: mLastMissingMaps) + MapManager.nativeDownload(map); if (mContainer != null) mContainer.showDownloader(true); @@ -364,7 +360,7 @@ public class RoutingController MapObject my = LocationHelper.INSTANCE.getMyPosition(); if (my == null) { - mRoutingListener.onRoutingEvent(ResultCodesHelper.NO_POSITION, null, null); + mRoutingListener.onRoutingEvent(ResultCodesHelper.NO_POSITION, null); return; } diff --git a/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java b/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java index 1bcf38e2b4..38be38e314 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java +++ b/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java @@ -22,27 +22,24 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.mapswithme.maps.downloader.country.OldMapStorage; -import com.mapswithme.maps.downloader.country.OldStorageOptions; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; import com.mapswithme.maps.adapter.DisabledChildSimpleExpandableListAdapter; import com.mapswithme.maps.base.BaseMwmDialogFragment; +import com.mapswithme.maps.downloader.CountryItem; import com.mapswithme.util.StringUtils; import com.mapswithme.util.UiUtils; public class RoutingErrorDialogFragment extends BaseMwmDialogFragment { private static final String EXTRA_RESULT_CODE = "ResultCode"; - private static final String EXTRA_MISSING_COUNTRIES = "MissingCountries"; - private static final String EXTRA_MISSING_ROUTES = "MissingRoutes"; + private static final String EXTRA_MISSING_MAPS = "MissingMaps"; private static final String GROUP_NAME = "GroupName"; private static final String GROUP_SIZE = "GroupSize"; private static final String COUNTRY_NAME = "CountryName"; - private OldMapStorage.Index[] mMissingCountries; - private OldMapStorage.Index[] mMissingRoutes; + private final List mMissingMaps = new ArrayList<>(); private int mResultCode; public interface Listener @@ -63,40 +60,38 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment public Dialog onCreateDialog(Bundle savedInstanceState) { parseArguments(); - final Pair titleMessage = ResultCodesHelper.getDialogTitleSubtitle(mResultCode, mMissingCountries); + final Pair titleMessage = ResultCodesHelper.getDialogTitleSubtitle(mResultCode, mMissingMaps.size()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) .setTitle(titleMessage.first) .setCancelable(true); - if (hasIndex(mMissingCountries) || hasIndex(mMissingRoutes)) - { - View view; - if (hasSingleIndex(mMissingCountries) && !hasIndex(mMissingRoutes)) - view = buildSingleMapView(titleMessage.second, mMissingCountries[0], OldStorageOptions.MAP_OPTION_MAP_ONLY); - else - view = buildMultipleMapView(titleMessage.second); - - return builder.setView(view) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.download, new Dialog.OnClickListener() + if (mMissingMaps.isEmpty()) + return builder.setMessage(titleMessage.second) + .setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mListener != null) - mListener.onDownload(); + mListener.onOk(); } }).create(); - } - return builder.setMessage(titleMessage.second) - .setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() + View view; + if (mMissingMaps.size() == 1) + view = buildSingleMapView(titleMessage.second, mMissingMaps.get(0)); + else + view = buildMultipleMapView(titleMessage.second); + + return builder.setView(view) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.download, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mListener != null) - mListener.onOk(); + mListener.onDownload(); } }).create(); } @@ -111,30 +106,24 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment private void parseArguments() { final Bundle args = getArguments(); - mMissingCountries = (OldMapStorage.Index[]) args.getSerializable(EXTRA_MISSING_COUNTRIES); - mMissingRoutes = (OldMapStorage.Index[]) args.getSerializable(EXTRA_MISSING_ROUTES); mResultCode = args.getInt(EXTRA_RESULT_CODE); + String[] maps = args.getStringArray(EXTRA_MISSING_MAPS); + if (maps == null) + return; + + for (String map: maps) + mMissingMaps.add(CountryItem.fill(map)); } - private static boolean hasIndex(OldMapStorage.Index[] indices) - { - return (indices != null && indices.length != 0); - } - - private static boolean hasSingleIndex(OldMapStorage.Index[] indices) - { - return (indices != null && indices.length == 1); - } - - private View buildSingleMapView(String message, OldMapStorage.Index index, int option) + private View buildSingleMapView(String message, CountryItem map) { @SuppressLint("InflateParams") final View countryView = View.inflate(getActivity(), R.layout.dialog_download_single_item, null); - ((TextView) countryView.findViewById(R.id.tv__title)).setText(OldMapStorage.INSTANCE.countryName(index)); + ((TextView) countryView.findViewById(R.id.tv__title)).setText(map.name); ((TextView) countryView.findViewById(R.id.tv__message)).setText(message); final TextView szView = (TextView) countryView.findViewById(R.id.tv__size); - szView.setText(StringUtils.getFileSizeString(OldMapStorage.INSTANCE.countryRemoteSizeInBytes(index, option))); + szView.setText(StringUtils.getFileSizeString(map.totalSize - map.size)); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) szView.getLayoutParams(); lp.rightMargin = 0; szView.setLayoutParams(lp); @@ -172,79 +161,46 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment private ExpandableListAdapter buildAdapter() { - final List> groupData = new ArrayList<>(); - final List>> childData = new ArrayList<>(); - List> countries = null; - if (hasIndex(mMissingCountries)) + List> countries = new ArrayList<>(); + long size = 0; + + for (CountryItem item: mMissingMaps) { - final Map countriesGroup = new HashMap<>(); - countriesGroup.put(GROUP_NAME, getString(R.string.maps) + " (" + mMissingCountries.length + ") "); - countriesGroup.put(GROUP_SIZE, StringUtils.getFileSizeString(getCountrySizesBytes(mMissingCountries, OldStorageOptions.MAP_OPTION_MAP_ONLY))); - groupData.add(countriesGroup); + Map data = new HashMap<>(); + data.put(COUNTRY_NAME, item.name); + countries.add(data); - countries = getCountryNames(mMissingCountries); - childData.add(countries); + size += (item.totalSize - item.size); } - if (hasIndex(mMissingRoutes)) - { - final Map routesGroup = new HashMap<>(); - long size = 0; - int routesCount = mMissingRoutes.length; - final List> routes = getCountryNames(mMissingRoutes); - if (countries != null) - { - routes.addAll(countries); - size += getCountrySizesBytes(mMissingCountries, OldStorageOptions.MAP_OPTION_CAR_ROUTING); - routesCount += mMissingCountries.length; - } - size += getCountrySizesBytes(mMissingRoutes, OldStorageOptions.MAP_OPTION_CAR_ROUTING); - routesGroup.put(GROUP_NAME, getString(R.string.dialog_routing_routes_size) + " (" + routesCount + ") "); - routesGroup.put(GROUP_SIZE, StringUtils.getFileSizeString(size)); - groupData.add(routesGroup); + Map group = new HashMap<>(); + group.put(GROUP_NAME, getString(R.string.maps) + " (" + mMissingMaps.size() + ") "); + group.put(GROUP_SIZE, StringUtils.getFileSizeString(size)); - childData.add(routes); - } + List> groups = new ArrayList<>(); + groups.add(group); + + List>> children = new ArrayList<>(); + children.add(countries); return new DisabledChildSimpleExpandableListAdapter(getActivity(), - groupData, + groups, R.layout.item_country_group_dialog_expanded, R.layout.item_country_dialog, new String[] { GROUP_NAME, GROUP_SIZE }, new int[] { R.id.tv__title, R.id.tv__size }, - childData, + children, R.layout.item_country_dialog, new String[] { COUNTRY_NAME }, new int[] { R.id.tv__title } ); } - private static List> getCountryNames(OldMapStorage.Index[] indices) - { - final List> countries = new ArrayList<>(indices.length); - for (OldMapStorage.Index index : indices) - { - final Map countryData = new HashMap<>(); - countryData.put(COUNTRY_NAME, OldMapStorage.INSTANCE.countryName(index)); - countries.add(countryData); - } - return countries; - } - - private static long getCountrySizesBytes(OldMapStorage.Index[] indices, int option) - { - long total = 0; - for (OldMapStorage.Index index : indices) - total += OldMapStorage.INSTANCE.countryRemoteSizeInBytes(index, option); - return total; - } - - public static RoutingErrorDialogFragment create(int resultCode, OldMapStorage.Index[] missingCountries, OldMapStorage.Index[] missingRoutes) + public static RoutingErrorDialogFragment create(int resultCode, String[] missingMaps) { Bundle args = new Bundle(); args.putInt(EXTRA_RESULT_CODE, resultCode); - args.putSerializable(EXTRA_MISSING_COUNTRIES, missingCountries); - args.putSerializable(EXTRA_MISSING_ROUTES, missingRoutes); + args.putStringArray(EXTRA_MISSING_MAPS, missingMaps); RoutingErrorDialogFragment res = (RoutingErrorDialogFragment)Fragment.instantiate(MwmApplication.get(), RoutingErrorDialogFragment.class.getName()); res.setArguments(args); return res; diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 5046f68b76..e45f64cd13 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -28,8 +28,8 @@ import com.mapswithme.maps.base.BaseMwmFragmentActivity; import com.mapswithme.maps.base.OnBackPressListener; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.downloader.CountrySuggestFragment; +import com.mapswithme.maps.downloader.DownloaderFragment; import com.mapswithme.maps.downloader.MapManager; -import com.mapswithme.maps.downloader.country.OldDownloadFragment; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.maps.widget.SearchToolbarController; @@ -157,7 +157,7 @@ public class SearchFragment extends BaseMwmFragment private static boolean doShowDownloadSuggest() { - return (!MapManager.nativeHasDownloadedMaps() && !MapManager.nativeIsDownloading()); + return (MapManager.nativeGetDownloadedCount() == 0 && !MapManager.nativeIsDownloading()); } private void showDownloadSuggest() @@ -187,7 +187,7 @@ public class SearchFragment extends BaseMwmFragment public void showDownloader() { - ((BaseMwmFragmentActivity)getActivity()).replaceFragment(OldDownloadFragment.class, null, null); + ((BaseMwmFragmentActivity)getActivity()).replaceFragment(DownloaderFragment.class, null, null); UiUtils.hide(mResultsFrame, mResultsPlaceholder, mTabFrame); } diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index acc9cad8d0..55fdfd1ae1 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -13,12 +13,12 @@ import java.util.Map; import com.facebook.appevents.AppEventsLogger; import com.flurry.android.FlurryAgent; -import com.mapswithme.maps.downloader.country.OldActiveCountryTree; import com.mapswithme.maps.BuildConfig; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.PrivateVariables; import com.mapswithme.maps.api.ParsedMwmRequest; import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.util.Config; import com.mapswithme.util.ConnectionState; import ru.mail.android.mytracker.MRMyTracker; @@ -302,7 +302,7 @@ public enum Statistics { if (mEnabled) { - final ParameterBuilder params = params().add(EventParam.COUNT, String.valueOf(OldActiveCountryTree.getTotalDownloadedCount())); + final ParameterBuilder params = params().add(EventParam.COUNT, String.valueOf(MapManager.nativeGetDownloadedCount())); MRMyTracker.trackEvent(event, params.get()); trackEvent(event, params); } diff --git a/routing/router.hpp b/routing/router.hpp index bd46b60400..919fef89cf 100644 --- a/routing/router.hpp +++ b/routing/router.hpp @@ -30,7 +30,8 @@ class IRouter public: /// Routing possible statuses enumeration. /// \warning this enum has JNI mirror! - /// \see android/src/com/mapswithme/maps/data/RoutingResultCodesProcessor.java + /// \see android/src/com/mapswithme/maps/routing/ResultCodesHelper.java + // TODO(gardster): Please check what items become obsolete now enum ResultCode // TODO(mgsergio) enum class { NoError = 0,