forked from organicmaps/organicmaps
[android] Added kml import
This commit is contained in:
parent
090177f9a4
commit
38e6374490
5 changed files with 138 additions and 17 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -340,7 +340,7 @@ public enum BookmarkManager
|
|||
return nativeFormatNewBookmarkName();
|
||||
}
|
||||
|
||||
public static boolean isAsyncBookmarksLoadingInProgress()
|
||||
public boolean isAsyncBookmarksLoadingInProgress()
|
||||
{
|
||||
return nativeIsAsyncBookmarksLoadingInProgress();
|
||||
}
|
||||
|
|
|
@ -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, msgId, posBtn, negBtn).show();
|
||||
buildAlertDialog(activity, titleId, msg, posBtn, posClickListener, negBtn).show();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ProgressDialog showModalProgressDialog(@NonNull Activity activity, @StringRes int msg)
|
||||
{
|
||||
ProgressDialog progress = new ProgressDialog(activity);
|
||||
progress.setMessage(activity.getString(msg));
|
||||
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
progress.setIndeterminate(true);
|
||||
progress.setCancelable(false);
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue