[new downloader][android] add: Show confirmation when trying to delete map with unsaved editor changes.

This commit is contained in:
Alexander Marchuk 2016-03-09 18:01:50 +03:00 committed by Sergey Yershov
parent bf6e7d9695
commit 1d2d507975
3 changed files with 52 additions and 2 deletions

View file

@ -491,4 +491,19 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeUnsubscribeOnCountryChanged
g_countryChangedListener = nullptr;
}
// static boolean nativeHasUnsavedEditorChanges(String root);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeHasUnsavedEditorChanges(JNIEnv * env, jclass clazz, jstring root)
{
return g_framework->NativeFramework()->HasUnsavedEdits(jni::ToNativeString(env, root));
}
// static void nativeDeleteUnsavedEditorChanges(String root);
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeDeleteUnsavedEditorChanges(JNIEnv * env, jclass clazz, jstring root)
{
// TODO (trashkalmar): Invoke proper method.
//g_framework->NativeFramework()->DeleteUnsavedEdits(jni::ToNativeString(env, root));
}
} // extern "C"

View file

@ -1,10 +1,12 @@
package com.mapswithme.maps.downloader;
import android.app.Activity;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
@ -60,8 +62,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
{
DELETE(R.drawable.ic_delete, R.string.delete)
{
@Override
void invoke(CountryItem item, DownloaderAdapter adapter)
private void deleteNode(CountryItem item)
{
MapManager.nativeCancel(item.id);
MapManager.nativeDelete(item.id);
@ -72,6 +73,30 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
.add("scenario", (item.isExpandable() ? "delete_group"
: "delete")));
}
@Override
void invoke(final CountryItem item, DownloaderAdapter adapter)
{
if (!MapManager.nativeHasUnsavedEditorChanges(item.id))
{
deleteNode(item);
return;
}
new AlertDialog.Builder(adapter.mActivity)
.setTitle(R.string.downloader_delete_map)
.setMessage(R.string.downloader_delete_editor_changes)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
MapManager.nativeDeleteUnsavedEditorChanges(item.id);
deleteNode(item);
}
}).show();
}
},
CANCEL(R.drawable.ic_cancel, R.string.cancel)

View file

@ -242,4 +242,14 @@ public final class MapManager
* Removes callback about current country change.
*/
public static native void nativeUnsubscribeOnCountryChanged();
/**
* Determines if there are unsaved editor changes present for given {@code root}.
*/
public static native boolean nativeHasUnsavedEditorChanges(String root);
/**
* Erases local changes made for the given {@code root} map.
*/
public static native void nativeDeleteUnsavedEditorChanges(String root);
}