diff --git a/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp b/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp index 508bc9ae20..fef24a8e6e 100644 --- a/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp +++ b/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp @@ -188,20 +188,23 @@ void OnPreparedFileForSharing(JNIEnv * env, BookmarkManager::SharingResult const static jclass const classBookmarkSharingResult = jni::GetGlobalClassRef(env, "app/organicmaps/bookmarks/data/BookmarkSharingResult"); - // Java signature : BookmarkSharingResult(long categoryId, @Code int code, + // Java signature : BookmarkSharingResult(long[] categoriesIds, @Code int code, // @NonNull String sharingPath, // @NonNull String errorString) static jmethodID const ctorBookmarkSharingResult = jni::GetConstructorID(env, - classBookmarkSharingResult, "(JILjava/lang/String;Ljava/lang/String;)V"); + classBookmarkSharingResult, "([JILjava/lang/String;Ljava/lang/String;)V"); + jsize const size = static_cast(result.m_categoriesIds.size()); + jni::ScopedLocalRef categoriesIds(env, env->NewLongArray(size)); + std::vector tmp(result.m_categoriesIds.cbegin(), result.m_categoriesIds.cend()); + env->SetLongArrayRegion(categoriesIds.get(), 0, size, tmp.data()); jni::TScopedLocalRef const sharingPath(env, jni::ToJavaString(env, result.m_sharingPath)); jni::TScopedLocalRef const errorString(env, jni::ToJavaString(env, result.m_errorString)); jni::TScopedLocalRef const sharingResult(env, env->NewObject(classBookmarkSharingResult, - ctorBookmarkSharingResult, static_cast(result.m_categoryId), + ctorBookmarkSharingResult, categoriesIds.get(), static_cast(result.m_code), sharingPath.get(), errorString.get())); - env->CallVoidMethod(bookmarkManagerInstance, g_onPreparedFileForSharingMethod, - sharingResult.get()); + env->CallVoidMethod(bookmarkManagerInstance, g_onPreparedFileForSharingMethod, sharingResult.get()); jni::HandleJavaException(env); } @@ -592,10 +595,13 @@ Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeSetAllCategoriesVisibi } JNIEXPORT void JNICALL -Java_app_organicmaps_bookmarks_data_BookmarkManager_nativePrepareFileForSharing( - JNIEnv * env, jclass, jlong catId) +Java_app_organicmaps_bookmarks_data_BookmarkManager_nativePrepareFileForSharing(JNIEnv * env, jclass, jlongArray catIds) { - frm()->GetBookmarkManager().PrepareFileForSharing(static_cast(catId), + auto const size = env->GetArrayLength(catIds); + std::vector tmp(size); + env->GetLongArrayRegion(catIds, 0, size, &tmp[0]); + kml::GroupIdCollection catIdsVector(tmp.cbegin(), tmp.cend()); + frm()->GetBookmarkManager().PrepareFileForSharing(catIdsVector, [env](BookmarkManager::SharingResult const & result) { OnPreparedFileForSharing(env, result); diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksSharingHelper.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksSharingHelper.java index 7a60c49b62..f2f90f8727 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksSharingHelper.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksSharingHelper.java @@ -14,6 +14,11 @@ import app.organicmaps.util.SharingUtils; import app.organicmaps.util.log.Logger; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + public enum BookmarksSharingHelper { INSTANCE; @@ -24,6 +29,12 @@ public enum BookmarksSharingHelper private ProgressDialog mProgressDialog; public void prepareBookmarkCategoryForSharing(@NonNull Activity context, long catId) + { + showProgressDialog(context); + BookmarkManager.INSTANCE.prepareCategoriesForSharing(new long[]{catId}); + } + + private void showProgressDialog(@NonNull Activity context) { mProgressDialog = new ProgressDialog(context, R.style.MwmTheme_ProgressDialog); mProgressDialog.setMessage(context.getString(R.string.please_wait)); @@ -31,7 +42,6 @@ public enum BookmarksSharingHelper mProgressDialog.setIndeterminate(true); mProgressDialog.setCancelable(false); mProgressDialog.show(); - BookmarkManager.INSTANCE.prepareCategoryForSharing(catId); } public void onPreparedFileForSharing(@NonNull FragmentActivity context, @@ -57,8 +67,10 @@ public enum BookmarksSharingHelper .setMessage(R.string.bookmarks_error_message_share_general) .setPositiveButton(R.string.ok, null) .show(); - String catName = BookmarkManager.INSTANCE.getCategoryById(result.getCategoryId()).getName(); - Logger.e(TAG, "Failed to share bookmark category '" + catName + "', error code: " + result.getCode()); + List names = new ArrayList<>(); + for (long categoryId : result.getCategoriesIds()) + names.add(BookmarkManager.INSTANCE.getCategoryById(categoryId).getName()); + Logger.e(TAG, "Failed to share bookmark categories " + names + ", error code: " + result.getCode()); } default -> throw new AssertionError("Unsupported bookmark sharing code: " + result.getCode()); } diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java index 8e97301b25..3966e1f36d 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java @@ -559,9 +559,9 @@ public enum BookmarkManager nativeSetChildCategoriesVisibility(catId, visible); } - public void prepareCategoryForSharing(long catId) + public void prepareCategoriesForSharing(long[] catIds) { - nativePrepareFileForSharing(catId); + nativePrepareFileForSharing(catIds); } public void setNotificationsEnabled(boolean enabled) @@ -799,7 +799,7 @@ public enum BookmarkManager private static native void nativeSetAllCategoriesVisibility(boolean visible); - private static native void nativePrepareFileForSharing(long catId); + private static native void nativePrepareFileForSharing(long[] catIds); private static native boolean nativeIsCategoryEmpty(long catId); diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkSharingResult.java b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkSharingResult.java index 9ed617f27b..dc80a977f2 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkSharingResult.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkSharingResult.java @@ -21,7 +21,7 @@ public class BookmarkSharingResult public static final int ARCHIVE_ERROR = 2; public static final int FILE_ERROR = 3; - private final long mCategoryId; + private final long[] mCategoriesIds; @Code private final int mCode; @NonNull @@ -30,19 +30,19 @@ public class BookmarkSharingResult @SuppressWarnings("unused") private final String mErrorString; - private BookmarkSharingResult(long categoryId, @Code int code, + public BookmarkSharingResult(long[] categoriesIds, @Code int code, @NonNull String sharingPath, @NonNull String errorString) { - mCategoryId = categoryId; + mCategoriesIds = categoriesIds; mCode = code; mSharingPath = sharingPath; mErrorString = errorString; } - public long getCategoryId() + public long[] getCategoriesIds() { - return mCategoryId; + return mCategoriesIds; } public int getCode() diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm index e10dd71c17..7fdfc90d3e 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm @@ -570,7 +570,7 @@ static BookmarkManager::SortingType convertSortingTypeToCore(MWMBookmarksSorting - (void)shareCategory:(MWMMarkGroupID)groupId { - self.bm.PrepareFileForSharing(groupId, [self](auto sharingResult) + self.bm.PrepareFileForSharing({groupId}, [self](auto sharingResult) { MWMBookmarksShareStatus status; switch (sharingResult.m_code) diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 1ec2ed2f47..b62a75d5ba 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -87,13 +87,13 @@ BookmarkManager::SharingResult GetFileForSharing(BookmarkManager::KMLDataCollect auto const categoryId = kmlToShare.second->m_categoryData.m_id; if (!SaveKmlFileSafe(*kmlToShare.second, filePath, KmlFileType::Text)) - return {categoryId, BookmarkManager::SharingResult::Code::FileError, "Bookmarks file does not exist."}; + return {{categoryId}, BookmarkManager::SharingResult::Code::FileError, "Bookmarks file does not exist."}; auto const tmpFilePath = base::JoinPath(GetPlatform().TmpDir(), fileName + std::string{kKmzExtension}); if (!CreateZipFromPathDeflatedAndDefaultCompression(filePath, tmpFilePath)) - return {categoryId, BookmarkManager::SharingResult::Code::ArchiveError, "Could not create archive."}; + return {{categoryId}, BookmarkManager::SharingResult::Code::ArchiveError, "Could not create archive."}; - return {categoryId, tmpFilePath}; + return {{categoryId}, tmpFilePath}; } std::string ToString(BookmarkManager::SortingType type) @@ -2596,20 +2596,20 @@ void BookmarkManager::SaveBookmarks(kml::GroupIdCollection const & groupIdCollec }); } -void BookmarkManager::PrepareFileForSharing(kml::MarkGroupId categoryId, SharingHandler && handler) +void BookmarkManager::PrepareFileForSharing(kml::GroupIdCollection const & categoriesIds, SharingHandler && handler) { CHECK_THREAD_CHECKER(m_threadChecker, ()); ASSERT(handler, ()); - if (IsCategoryEmpty(categoryId)) + if (categoriesIds.size() == 1 && IsCategoryEmpty(categoriesIds.front())) { - handler(SharingResult(categoryId, SharingResult::Code::EmptyCategory)); + handler(SharingResult(categoriesIds, SharingResult::Code::EmptyCategory)); return; } - auto collection = PrepareToSaveBookmarks({categoryId}); + auto collection = PrepareToSaveBookmarks(categoriesIds); if (!collection || collection->empty()) { - handler(SharingResult(categoryId, SharingResult::Code::FileError)); + handler(SharingResult(categoriesIds, SharingResult::Code::FileError)); return; } diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index ebfb309b03..0d8ee6161c 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -316,31 +316,31 @@ public: FileError }; - SharingResult(kml::MarkGroupId categoryId, std::string const & sharingPath) - : m_categoryId(categoryId) + SharingResult(kml::GroupIdCollection const & categoriesIds, std::string const & sharingPath) + : m_categoriesIds(categoriesIds) , m_code(Code::Success) , m_sharingPath(sharingPath) {} - SharingResult(kml::MarkGroupId categoryId, Code code) - : m_categoryId(categoryId) + SharingResult(kml::GroupIdCollection const & categoriesIds, Code code) + : m_categoriesIds(categoriesIds) , m_code(code) {} - SharingResult(kml::MarkGroupId categoryId, Code code, std::string const & errorString) - : m_categoryId(categoryId) + SharingResult(kml::GroupIdCollection const & categoriesIds, Code code, std::string const & errorString) + : m_categoriesIds(categoriesIds) , m_code(code) , m_errorString(errorString) {} - kml::MarkGroupId m_categoryId; + kml::MarkIdCollection m_categoriesIds; Code m_code; std::string m_sharingPath; std::string m_errorString; }; using SharingHandler = platform::SafeCallback; - void PrepareFileForSharing(kml::MarkGroupId categoryId, SharingHandler && handler); + void PrepareFileForSharing(kml::GroupIdCollection const & categoriesIds, SharingHandler && handler); bool IsCategoryEmpty(kml::MarkGroupId categoryId) const; diff --git a/qt/bookmark_dialog.cpp b/qt/bookmark_dialog.cpp index 5f650316be..fd10f5d722 100644 --- a/qt/bookmark_dialog.cpp +++ b/qt/bookmark_dialog.cpp @@ -170,7 +170,7 @@ void BookmarkDialog::OnExportClick() if (name.isEmpty()) return; - m_framework.GetBookmarkManager().PrepareFileForSharing(categoryIt->second, + m_framework.GetBookmarkManager().PrepareFileForSharing({categoryIt->second}, [this, name](BookmarkManager::SharingResult const & result) { if (result.m_code == BookmarkManager::SharingResult::Code::Success)