[android] Notify user to update maps without search index.

This commit is contained in:
vng 2012-07-16 15:56:14 -07:00 committed by Alex Zolotarev
parent 841b34fcff
commit be3f69b625
7 changed files with 147 additions and 46 deletions

View file

@ -203,22 +203,6 @@ extern "C"
g_framework->RemoveLocalMaps();
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeGetMapsWithoutSearch(JNIEnv * env, jobject thiz)
{
vector<string> v;
g_framework->GetMapsWithoutSearch(v);
jclass klass = env->FindClass("java/lang/String");
ASSERT ( klass, () );
int const count = static_cast<int>(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)
{

View file

@ -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<string> v;
g_framework->GetMapsWithoutSearch(v);
jclass klass = env->FindClass("java/lang/String");
ASSERT ( klass, () );
int const count = static_cast<int>(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;
}
}

View file

@ -149,4 +149,5 @@
<string name="downloaded_touch_to_update">Загружено (%s), нажмите для обновления или удаления</string>
<string name="update_mb_or_kb">Обновить %s</string>
<string name="search_update_maps">Для функции поиска необходимо обновить устаревшие карты</string>
<string name="advise_update_maps">Доступно обновление для следующих карт</string>
</resources>

View file

@ -153,4 +153,5 @@
<string name="downloaded_touch_to_update">Downloaded (%s), touch to update or delete</string>
<string name="update_mb_or_kb">Update %s</string>
<string name="search_update_maps">You need updated maps for search function</string>
<string name="advise_update_maps">Update available for this maps</string>
</resources>

View file

@ -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();
}

View file

@ -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;
}
}

View file

@ -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 = Доступно обновление для следующих карт