forked from organicmaps/organicmaps
[android] Refactored sharing bookmarks so that it uses core instead of custom JNI logic
This commit is contained in:
parent
40b43aa600
commit
bee0b71274
6 changed files with 80 additions and 73 deletions
|
@ -200,22 +200,6 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteTrack(
|
|||
frm()->GetBookmarkManager().GetEditSession().DeleteTrack(static_cast<df::LineID>(trkId));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeSaveToKmzFile(
|
||||
JNIEnv * env, jobject thiz, jlong catId, jstring tmpPath)
|
||||
{
|
||||
auto const categoryId = static_cast<df::MarkGroupID>(catId);
|
||||
if (frm()->GetBookmarkManager().HasBmCategory(categoryId))
|
||||
{
|
||||
auto const name = frm()->GetBookmarkManager().GetCategoryName(categoryId);
|
||||
auto const fileName = frm()->GetBookmarkManager().GetCategoryFileName(categoryId);
|
||||
if (CreateZipFromPathDeflatedAndDefaultCompression(fileName, ToNativeString(env, tmpPath) + name + ".kmz"))
|
||||
return ToJavaString(env, name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAddBookmarkToLastEditedCategory(
|
||||
JNIEnv * env, jobject thiz, jstring name, double lat, double lon)
|
||||
|
|
|
@ -1315,7 +1315,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
super.onStart();
|
||||
Framework.nativeSetMapObjectListener(this);
|
||||
BookmarkManager.INSTANCE.addListener(this);
|
||||
BookmarkManager.INSTANCE.addLoadingListener(this);
|
||||
RoutingController.get().attach(this);
|
||||
if (MapFragment.nativeIsEngineCreated())
|
||||
LocationHelper.INSTANCE.attach(this);
|
||||
|
@ -1331,7 +1331,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
super.onStop();
|
||||
Framework.nativeRemoveMapObjectListener();
|
||||
BookmarkManager.INSTANCE.removeListener(this);
|
||||
BookmarkManager.INSTANCE.removeLoadingListener(this);
|
||||
LocationHelper.INSTANCE.detach(!isFinishing());
|
||||
RoutingController.get().detach();
|
||||
TrafficManager.INSTANCE.detachAll();
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.mapswithme.maps.auth.Authorizer;
|
|||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkBackupController;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
import com.mapswithme.maps.widget.PlaceholderView;
|
||||
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
|
||||
|
@ -32,6 +33,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
RecyclerClickListener,
|
||||
RecyclerLongClickListener,
|
||||
BookmarkManager.BookmarksLoadingListener,
|
||||
BookmarkManager.BookmarksSharingListener,
|
||||
BookmarkCategoriesAdapter.CategoryListInterface
|
||||
{
|
||||
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
|
||||
|
@ -121,7 +123,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
BookmarkManager.INSTANCE.addListener(this);
|
||||
BookmarkManager.INSTANCE.addLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.addSharingListener(this);
|
||||
if (mBackupController != null)
|
||||
mBackupController.onStart();
|
||||
}
|
||||
|
@ -130,7 +133,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
BookmarkManager.INSTANCE.removeListener(this);
|
||||
BookmarkManager.INSTANCE.removeLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.removeSharingListener(this);
|
||||
if (mBackupController != null)
|
||||
mBackupController.onStop();
|
||||
}
|
||||
|
@ -195,7 +199,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
break;
|
||||
|
||||
case R.id.set_share:
|
||||
SharingHelper.shareBookmarksCategory(getActivity(), mSelectedCatId);
|
||||
BookmarkManager.INSTANCE.prepareCategoryForSharing(mSelectedCatId);
|
||||
break;
|
||||
|
||||
case R.id.set_delete:
|
||||
|
@ -285,6 +289,12 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
// Do nothing here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreparedFileForSharing(@NonNull BookmarkSharingResult result)
|
||||
{
|
||||
SharingHelper.shareBookmarksCategory(getActivity(), result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddCategory()
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.base.BaseMwmListFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.maps.bookmarks.data.Track;
|
||||
import com.mapswithme.maps.widget.placepage.EditBookmarkFragment;
|
||||
import com.mapswithme.maps.widget.placepage.Sponsored;
|
||||
|
@ -30,7 +31,8 @@ import com.mapswithme.util.sharing.SharingHelper;
|
|||
|
||||
public class BookmarksListFragment extends BaseMwmListFragment
|
||||
implements AdapterView.OnItemLongClickListener,
|
||||
MenuItem.OnMenuItemClickListener
|
||||
MenuItem.OnMenuItemClickListener,
|
||||
BookmarkManager.BookmarksSharingListener
|
||||
{
|
||||
public static final String TAG = BookmarksListFragment.class.getSimpleName();
|
||||
|
||||
|
@ -67,6 +69,13 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
bar.setTitle(BookmarkManager.INSTANCE.getCategoryName(mCategoryId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
BookmarkManager.INSTANCE.addSharingListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
|
@ -87,6 +96,13 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
mAdapter.stopLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
BookmarkManager.INSTANCE.removeSharingListener(this);
|
||||
}
|
||||
|
||||
private void initList()
|
||||
{
|
||||
mAdapter = new BookmarkListAdapter(getActivity(), mCategoryId);
|
||||
|
@ -171,6 +187,12 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreparedFileForSharing(@NonNull BookmarkSharingResult result)
|
||||
{
|
||||
SharingHelper.shareBookmarksCategory(getActivity(), result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem)
|
||||
{
|
||||
|
@ -224,7 +246,7 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
{
|
||||
if (item.getItemId() == R.id.set_share)
|
||||
{
|
||||
SharingHelper.shareBookmarksCategory(getActivity(), mCategoryId);
|
||||
BookmarkManager.INSTANCE.prepareCategoryForSharing(mCategoryId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,14 @@ package com.mapswithme.maps.bookmarks.data;
|
|||
|
||||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
@MainThread
|
||||
public enum BookmarkManager
|
||||
{
|
||||
|
@ -64,32 +63,32 @@ public enum BookmarkManager
|
|||
return bookmark;
|
||||
}
|
||||
|
||||
public void addListener(@NonNull BookmarksLoadingListener listener)
|
||||
public void addLoadingListener(@NonNull BookmarksLoadingListener listener)
|
||||
{
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(@NonNull BookmarksLoadingListener listener)
|
||||
public void removeLoadingListener(@NonNull BookmarksLoadingListener listener)
|
||||
{
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void addListener(@NonNull KmlConversionListener listener)
|
||||
public void addKmlConversionListener(@NonNull KmlConversionListener listener)
|
||||
{
|
||||
mConversionListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(@NonNull KmlConversionListener listener)
|
||||
public void removeKmlConversionListener(@NonNull KmlConversionListener listener)
|
||||
{
|
||||
mConversionListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void addListener(@NonNull BookmarksSharingListener listener)
|
||||
public void addSharingListener(@NonNull BookmarksSharingListener listener)
|
||||
{
|
||||
mSharingListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(@NonNull BookmarksSharingListener listener)
|
||||
public void removeSharingListener(@NonNull BookmarksSharingListener listener)
|
||||
{
|
||||
mSharingListeners.remove(listener);
|
||||
}
|
||||
|
@ -234,15 +233,6 @@ public enum BookmarkManager
|
|||
|
||||
public void showBookmarkOnMap(long bmkId) { nativeShowBookmarkOnMap(bmkId); }
|
||||
|
||||
/**
|
||||
* @return null, if wrong category is passed.
|
||||
*/
|
||||
@Nullable
|
||||
public String saveToKmzFile(long catId, @NonNull String tmpPath)
|
||||
{
|
||||
return nativeSaveToKmzFile(catId, tmpPath);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Bookmark addBookmarkToLastEditedCategory(@NonNull String name, double lat, double lon)
|
||||
{
|
||||
|
@ -322,6 +312,11 @@ public enum BookmarkManager
|
|||
return nativeIsCategoryEmpty(catId);
|
||||
}
|
||||
|
||||
public void prepareCategoryForSharing(long catId)
|
||||
{
|
||||
nativePrepareFileForSharing(catId);
|
||||
}
|
||||
|
||||
private native int nativeGetCategoriesCount();
|
||||
|
||||
private native int nativeGetCategoryPositionById(long catId);
|
||||
|
@ -366,12 +361,6 @@ public enum BookmarkManager
|
|||
|
||||
private native void nativeShowBookmarkOnMap(long bmkId);
|
||||
|
||||
/**
|
||||
* @return null, if wrong category is passed.
|
||||
*/
|
||||
@Nullable
|
||||
private native String nativeSaveToKmzFile(long catId, @NonNull String tmpPath);
|
||||
|
||||
@NonNull
|
||||
private native Bookmark nativeAddBookmarkToLastEditedCategory(String name, double lat, double lon);
|
||||
|
||||
|
@ -423,6 +412,6 @@ public enum BookmarkManager
|
|||
|
||||
public interface BookmarksSharingListener
|
||||
{
|
||||
void onPreparedFileForSharing(BookmarkSharingResult result);
|
||||
void onPreparedFileForSharing(@NonNull BookmarkSharingResult result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,22 @@ import android.content.pm.ActivityInfo;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.cocosw.bottomsheet.BottomSheet;
|
||||
import com.google.gson.Gson;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -21,19 +34,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cocosw.bottomsheet.BottomSheet;
|
||||
import com.google.gson.Gson;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.StorageUtils;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
public final class SharingHelper
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
private static final String TAG = SharingHelper.class.getSimpleName();
|
||||
private static final String PREFS_STORAGE = "sharing";
|
||||
private static final String PREFS_KEY_ITEMS = "items";
|
||||
|
||||
|
@ -163,7 +167,6 @@ public final class SharingHelper
|
|||
|
||||
private static void shareInternal(final BaseShareable data, int titleRes, final List<SharingTarget> items)
|
||||
{
|
||||
boolean showing = BottomSheetHelper.isShowing();
|
||||
final BottomSheet.Builder builder = BottomSheetHelper.createGrid(data.getActivity(), titleRes)
|
||||
.limit(R.integer.sharing_initial_rows);
|
||||
|
||||
|
@ -186,12 +189,6 @@ public final class SharingHelper
|
|||
}
|
||||
});
|
||||
|
||||
if (!showing)
|
||||
{
|
||||
builder.show();
|
||||
return;
|
||||
}
|
||||
|
||||
UiThread.runLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
|
@ -215,14 +212,19 @@ public final class SharingHelper
|
|||
save();
|
||||
}
|
||||
|
||||
public static void shareBookmarksCategory(Activity context, long id)
|
||||
public static void shareBookmarksCategory(@NonNull Activity context,
|
||||
@NonNull BookmarkSharingResult result)
|
||||
{
|
||||
final String path = StorageUtils.getTempPath() + "/";
|
||||
String name = BookmarkManager.INSTANCE.saveToKmzFile(id, path);
|
||||
if (name == null)
|
||||
//TODO: show error dialog in this case.
|
||||
String name = BookmarkManager.INSTANCE.getCategoryName(result.getCategoryId());
|
||||
if (result.getCode() != BookmarkSharingResult.SUCCESS)
|
||||
{
|
||||
LOGGER.e(TAG, "Failed to share bookmark category '" + name + "', error code: "
|
||||
+ result.getCode());
|
||||
return;
|
||||
}
|
||||
|
||||
shareOutside(new LocalFileShareable(context, path + name + ".kmz", "application/vnd.google-earth.kmz")
|
||||
shareOutside(new LocalFileShareable(context, result.getSharingPath(), "application/vnd.google-earth.kmz")
|
||||
// TODO fix translation for some languages, that doesn't contain holder for filename
|
||||
.setText(context.getString(R.string.share_bookmarks_email_body, name))
|
||||
.setSubject(R.string.share_bookmarks_email_subject));
|
||||
|
@ -235,4 +237,4 @@ public final class SharingHelper
|
|||
.setSubject(subject));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue