diff --git a/android/jni/com/mapswithme/maps/MWMActivity.cpp b/android/jni/com/mapswithme/maps/MWMActivity.cpp index 311acaa392..5965595b8f 100644 --- a/android/jni/com/mapswithme/maps/MWMActivity.cpp +++ b/android/jni/com/mapswithme/maps/MWMActivity.cpp @@ -203,22 +203,6 @@ extern "C" g_framework->RemoveLocalMaps(); } - JNIEXPORT jobjectArray JNICALL - Java_com_mapswithme_maps_MWMActivity_nativeGetMapsWithoutSearch(JNIEnv * env, jobject thiz) - { - vector v; - g_framework->GetMapsWithoutSearch(v); - - jclass klass = env->FindClass("java/lang/String"); - ASSERT ( klass, () ); - - int const count = static_cast(v.size()); - jobjectArray ret = env->NewObjectArray(count, klass, 0); - for (int i = 0; i < count; ++i) - env->SetObjectArrayElement(ret, i, env->NewStringUTF(v[i].c_str())); - return ret; - } - JNIEXPORT void JNICALL Java_com_mapswithme_maps_MWMActivity_nativeScale(JNIEnv * env, jobject thiz, jdouble k) { diff --git a/android/jni/com/mapswithme/maps/MapStorage.cpp b/android/jni/com/mapswithme/maps/MapStorage.cpp index 160f131414..f0eeaecb26 100644 --- a/android/jni/com/mapswithme/maps/MapStorage.cpp +++ b/android/jni/com/mapswithme/maps/MapStorage.cpp @@ -171,4 +171,20 @@ extern "C" g_framework->Storage().Unsubscribe(slotID); } + + JNIEXPORT jobjectArray JNICALL + Java_com_mapswithme_maps_MapStorage_nativeGetMapsWithoutSearch(JNIEnv * env, jobject thiz) + { + vector v; + g_framework->GetMapsWithoutSearch(v); + + jclass klass = env->FindClass("java/lang/String"); + ASSERT ( klass, () ); + + int const count = static_cast(v.size()); + jobjectArray ret = env->NewObjectArray(count, klass, 0); + for (int i = 0; i < count; ++i) + env->SetObjectArrayElement(ret, i, env->NewStringUTF(v[i].c_str())); + return ret; + } } diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml index 863d56b286..f47a60d4c1 100644 --- a/android/res/values-ru/strings.xml +++ b/android/res/values-ru/strings.xml @@ -149,4 +149,5 @@ Загружено (%s), нажмите для обновления или удаления Обновить %s Для функции поиска необходимо обновить устаревшие карты + Доступно обновление для следующих карт diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index d0a8979d8f..51f251a985 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -153,4 +153,5 @@ Downloaded (%s), touch to update or delete Update %s You need updated maps for search function + Update available for this maps diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 1b74b88172..917b377ec1 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -71,6 +71,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService checkShouldStartLocationService(); checkMeasurementSystem(); checkProVersionAvailable(); + checkUpdateMaps(); } }); } @@ -202,6 +203,31 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService nativeCheckForProVersion(mApplication.getProVersionCheckURL()); } + private boolean m_needCheckUpdate = true; + + private void checkUpdateMaps() + { + // do it only once + if (m_needCheckUpdate) + { + m_needCheckUpdate = false; + + final MapStorage s = MapStorage.getInstance(); + s.updateMaps(R.string.advise_update_maps, this, new MapStorage.UpdateFunctor() + { + @Override + public void doUpdate() + { + runDownloadActivity(); + } + @Override + public void doCancel() + { + } + }); + } + } + /// Invoked from native code - asynchronous server check. public void onProVersionAvailable() { @@ -249,38 +275,23 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService } else { - final String[] maps = nativeGetMapsWithoutSearch(); - if (maps.length != 0) + final MapStorage s = MapStorage.getInstance(); + if (!s.updateMaps(R.string.search_update_maps, this, new MapStorage.UpdateFunctor() { - String msg = this.getString(R.string.search_update_maps) + ": "; - for (int i = 0; i < maps.length; ++i) - msg = msg + "\n" + maps[i]; - - new AlertDialog.Builder(getActivity()) - .setMessage(msg) - .setPositiveButton(getString(R.string.download), new DialogInterface.OnClickListener() + @Override + public void doUpdate() { - @Override - public void onClick(DialogInterface dlg, int which) - { - dlg.dismiss(); - runDownloadActivity(); - } - }) - .setNegativeButton(getString(R.string.later), new DialogInterface.OnClickListener() + runDownloadActivity(); + } + @Override + public void doCancel() { - @Override - public void onClick(DialogInterface dlg, int which) - { - dlg.dismiss(); - runSearchActivity(); - } - }) - .create() - .show(); - } - else + runSearchActivity(); + } + })) + { runSearchActivity(); + } } } @@ -571,6 +582,4 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService private native String nativeGetProVersionURL(); private native void nativeCheckForProVersion(String serverURL); - - private native String[] nativeGetMapsWithoutSearch(); } diff --git a/android/src/com/mapswithme/maps/MapStorage.java b/android/src/com/mapswithme/maps/MapStorage.java index 5a1d43be17..a874469c9d 100644 --- a/android/src/com/mapswithme/maps/MapStorage.java +++ b/android/src/com/mapswithme/maps/MapStorage.java @@ -1,5 +1,9 @@ package com.mapswithme.maps; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; + public class MapStorage { public static final int GROUP = -2; @@ -121,6 +125,8 @@ public class MapStorage public native int subscribe(Listener l); public native void unsubscribe(int slotId); + private native String[] nativeGetMapsWithoutSearch(); + private MapStorage() { @@ -135,4 +141,85 @@ public class MapStorage return mInstance; } + + private void runDownloadCountries(Index[] indexes) + { + for (int i = 0; i < indexes.length; ++i) + { + if (indexes[i] != null) + downloadCountry(indexes[i]); + } + } + + public interface UpdateFunctor + { + public void doUpdate(); + public void doCancel(); + } + + public boolean updateMaps(int msgID, Context context, final UpdateFunctor fn) + { + // get map names without search index + final String[] maps = nativeGetMapsWithoutSearch(); + + if (maps.length == 0) + return false; + + // get indexes and filter out maps that already downloading + int count = 0; + final Index[] indexes = new Index[maps.length]; + for (int i = 0; i < maps.length; ++i) + { + final Index idx = findIndexByName(maps[i]); + final int st = countryStatus(idx); + + if (st == DOWNLOADING || st == IN_QUEUE) + indexes[i] = null; + else + { + indexes[i] = idx; + ++count; + } + } + + // all maps are already downloading + if (count == 0) + return false; + + String msg = context.getString(msgID) + ":"; + for (int i = 0; i < maps.length; ++i) + { + if (indexes[i] != null) + msg = msg + "\n" + maps[i]; + } + + new AlertDialog.Builder(context) + .setMessage(msg) + .setPositiveButton(context.getString(R.string.download), new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dlg, int which) + { + dlg.dismiss(); + + runDownloadCountries(indexes); + + fn.doUpdate(); + } + }) + .setNegativeButton(context.getString(R.string.later), new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dlg, int which) + { + dlg.dismiss(); + + fn.doCancel(); + } + }) + .create() + .show(); + + return true; + } } diff --git a/strings.txt b/strings.txt index 5256d2c635..061e67543e 100644 --- a/strings.txt +++ b/strings.txt @@ -672,3 +672,6 @@ en = You need updated maps for search function ru = Для функции поиска необходимо обновить устаревшие карты cs = Pro funkci vyhledávání musíš aktualizovat mapy + [advise_update_maps] + en = Update available for this maps + ru = Доступно обновление для следующих карт