Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorАлександр Зацепин <az@mapswithme.com>2018-04-09 18:39:19 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2018-04-10 13:17:36 +0300
commit38e63744904e14ed36202da8ef2d9b5a4371a44b (patch)
treead6a5d544e1423e8f794ea761e9805b0c59ef4b0 /android/src
parent090177f9a429ce4ce00e4b0b34505149212659f2 (diff)
[android] Added kml import
Diffstat (limited to 'android/src')
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java31
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/KmlImportController.java85
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java2
-rw-r--r--android/src/com/mapswithme/util/DialogUtils.java31
-rw-r--r--android/src/com/mapswithme/util/sharing/SharingHelper.java6
5 files changed, 138 insertions, 17 deletions
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java
index b77d09cb49..d0c12a8769 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java
@@ -33,7 +33,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
RecyclerLongClickListener,
BookmarkManager.BookmarksLoadingListener,
BookmarkManager.BookmarksSharingListener,
- BookmarkCategoriesAdapter.CategoryListInterface
+ BookmarkCategoriesAdapter.CategoryListInterface,
+ KmlImportController.ImportKmlCallback
{
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
private long mSelectedCatId;
@@ -44,6 +45,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
@Nullable
private BookmarkBackupController mBackupController;
+ @Nullable
+ private KmlImportController mKmlImportController;
@Override
protected @LayoutRes int getLayoutRes()
@@ -74,6 +77,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
mLoadingPlaceholder = view.findViewById(R.id.placeholder_loading);
mBackupController = new BookmarkBackupController(view.findViewById(R.id.backup),
new Authorizer(this));
+ mKmlImportController = new KmlImportController(getActivity(), this);
if (getAdapter() != null)
{
getAdapter().setOnClickListener(this);
@@ -89,13 +93,17 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
});
}
- getRecyclerView().setNestedScrollingEnabled(false);
- getRecyclerView().addItemDecoration(ItemDecoratorFactory.createVerticalDefaultDecorator(getContext()));
+ RecyclerView rw = getRecyclerView();
+ if (rw == null)
+ return;
+
+ rw.setNestedScrollingEnabled(false);
+ rw.addItemDecoration(ItemDecoratorFactory.createVerticalDefaultDecorator(getContext()));
}
private void updateResultsPlaceholder()
{
- boolean showLoadingPlaceholder = BookmarkManager.isAsyncBookmarksLoadingInProgress();
+ boolean showLoadingPlaceholder = BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress();
boolean showPlaceHolder = !showLoadingPlaceholder &&
(getAdapter() == null || getAdapter().getItemCount() == 0);
if (getAdapter() != null)
@@ -110,7 +118,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
{
if (mLoadingPlaceholder != null)
{
- boolean showLoadingPlaceholder = BookmarkManager.isAsyncBookmarksLoadingInProgress();
+ boolean showLoadingPlaceholder = BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress();
if (getAdapter() != null && getAdapter().getItemCount() != 0)
showLoadingPlaceholder = false;
@@ -126,6 +134,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
BookmarkManager.INSTANCE.addSharingListener(this);
if (mBackupController != null)
mBackupController.onStart();
+ if (mKmlImportController != null)
+ mKmlImportController.onStart();
}
@Override
@@ -136,6 +146,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
BookmarkManager.INSTANCE.removeSharingListener(this);
if (mBackupController != null)
mBackupController.onStop();
+ if (mKmlImportController != null)
+ mKmlImportController.onStop();
}
@Override
@@ -145,6 +157,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
updateLoadingPlaceholder();
if (getAdapter() != null)
getAdapter().notifyDataSetChanged();
+ if (mKmlImportController != null)
+ mKmlImportController.importKml();
}
@Override
@@ -306,6 +320,13 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
mBackupController.onActivityResult(requestCode, resultCode, data);
}
+ @Override
+ public void onFinishKmlImport()
+ {
+ if (getAdapter() != null)
+ getAdapter().notifyDataSetChanged();
+ }
+
interface CategoryEditor
{
void commit(@Nullable String newName);
diff --git a/android/src/com/mapswithme/maps/bookmarks/KmlImportController.java b/android/src/com/mapswithme/maps/bookmarks/KmlImportController.java
new file mode 100644
index 0000000000..9150cc00f6
--- /dev/null
+++ b/android/src/com/mapswithme/maps/bookmarks/KmlImportController.java
@@ -0,0 +1,85 @@
+package com.mapswithme.maps.bookmarks;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+import com.mapswithme.maps.R;
+import com.mapswithme.maps.bookmarks.data.BookmarkManager;
+import com.mapswithme.util.DialogUtils;
+
+public class KmlImportController implements BookmarkManager.KmlConversionListener
+{
+ @NonNull
+ private final Activity mContext;
+ @Nullable
+ private ProgressDialog mProgressDialog;
+ @Nullable
+ private final ImportKmlCallback mCallback;
+ private boolean mWasShown = false;
+
+ KmlImportController(@NonNull Activity context, @Nullable ImportKmlCallback callback)
+ {
+ mContext = context;
+ mCallback = callback;
+ }
+
+ void onStart()
+ {
+ BookmarkManager.INSTANCE.addKmlConversionListener(this);
+ }
+
+ void onStop()
+ {
+ BookmarkManager.INSTANCE.removeKmlConversionListener(this);
+ }
+
+ void importKml()
+ {
+ if (mWasShown)
+ return;
+
+ if (BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress())
+ return;
+
+ int count = BookmarkManager.INSTANCE.getKmlFilesCountForConversion();
+ if (count == 0)
+ return;
+
+ DialogInterface.OnClickListener clickListener = (dialog, which) -> {
+ BookmarkManager.INSTANCE.convertAllKmlFiles();
+ dialog.dismiss();
+ mProgressDialog = DialogUtils.showModalProgressDialog(mContext, R.string.converting);
+ mProgressDialog.show();
+ };
+
+ String msg = mContext.getString(R.string.bookmarks_detect_message, count);
+ DialogUtils.showAlertDialog(mContext, R.string.bookmarks_detect_title, msg,
+ R.string.button_convert, clickListener, R.string.cancel);
+ mWasShown = true;
+ }
+
+ @Override
+ public void onFinishKmlConversion(boolean success)
+ {
+ if (mProgressDialog != null && mProgressDialog.isShowing())
+ mProgressDialog.dismiss();
+
+ if (success)
+ {
+ if (mCallback != null)
+ mCallback.onFinishKmlImport();
+ return;
+ }
+
+ DialogUtils.showAlertDialog(mContext, R.string.bookmarks_convert_error_title,
+ R.string.bookmarks_convert_error_message);
+ }
+
+ interface ImportKmlCallback
+ {
+ void onFinishKmlImport();
+ }
+}
diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java
index 326fc8e065..db57af3123 100644
--- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java
+++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java
@@ -340,7 +340,7 @@ public enum BookmarkManager
return nativeFormatNewBookmarkName();
}
- public static boolean isAsyncBookmarksLoadingInProgress()
+ public boolean isAsyncBookmarksLoadingInProgress()
{
return nativeIsAsyncBookmarksLoadingInProgress();
}
diff --git a/android/src/com/mapswithme/util/DialogUtils.java b/android/src/com/mapswithme/util/DialogUtils.java
index d5a68ae55a..0e9451eaad 100644
--- a/android/src/com/mapswithme/util/DialogUtils.java
+++ b/android/src/com/mapswithme/util/DialogUtils.java
@@ -1,6 +1,8 @@
package com.mapswithme.util;
import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
@@ -28,11 +30,15 @@ public class DialogUtils
.setMessage(msgId);
}
- private static AlertDialog.Builder buildAlertDialog(Activity activity, int titleId, @StringRes int msgId,
- @StringRes int posBtn, @StringRes int negBtn)
+ private static AlertDialog.Builder buildAlertDialog(Activity activity, int titleId,
+ @NonNull CharSequence msg,
+ @StringRes int posBtn,
+ @NonNull DialogInterface.OnClickListener posClickListener,
+ @StringRes int negBtn)
{
- return buildAlertDialog(activity, titleId, msgId)
- .setPositiveButton(posBtn, (dlg, which) -> dlg.dismiss())
+ return buildAlertDialog(activity, titleId)
+ .setMessage(msg)
+ .setPositiveButton(posBtn, posClickListener)
.setNegativeButton(negBtn, null);
}
@@ -48,8 +54,21 @@ public class DialogUtils
}
public static void showAlertDialog(@NonNull Activity activity, @StringRes int titleId,
- @StringRes int msgId, @StringRes int posBtn, @StringRes int negBtn)
+ @NonNull CharSequence msg, @StringRes int posBtn,
+ @NonNull DialogInterface.OnClickListener posClickListener,
+ @StringRes int negBtn)
+ {
+ buildAlertDialog(activity, titleId, msg, posBtn, posClickListener, negBtn).show();
+ }
+
+ @NonNull
+ public static ProgressDialog showModalProgressDialog(@NonNull Activity activity, @StringRes int msg)
{
- buildAlertDialog(activity, titleId, msgId, posBtn, negBtn).show();
+ ProgressDialog progress = new ProgressDialog(activity);
+ progress.setMessage(activity.getString(msg));
+ progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ progress.setIndeterminate(true);
+ progress.setCancelable(false);
+ return progress;
}
}
diff --git a/android/src/com/mapswithme/util/sharing/SharingHelper.java b/android/src/com/mapswithme/util/sharing/SharingHelper.java
index 832c3e25bf..abca84f3d4 100644
--- a/android/src/com/mapswithme/util/sharing/SharingHelper.java
+++ b/android/src/com/mapswithme/util/sharing/SharingHelper.java
@@ -192,11 +192,7 @@ public enum SharingHelper
public void prepareBookmarkCategoryForSharing(@NonNull Activity context, long catId)
{
- mProgressDialog = new ProgressDialog(context);
- mProgressDialog.setMessage(context.getString(R.string.please_wait));
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- mProgressDialog.setIndeterminate(true);
- mProgressDialog.setCancelable(false);
+ mProgressDialog = DialogUtils.showModalProgressDialog(context, R.string.please_wait);
mProgressDialog.show();
BookmarkManager.INSTANCE.prepareCategoryForSharing(catId);
}