[android][ios][core] different links for sharing bookmarks

This commit is contained in:
Arsentiy Milchakov 2019-09-11 15:08:55 +03:00 committed by Aleksandr Zatsepin
parent 7171d56dfa
commit a57b39e2c7
11 changed files with 61 additions and 15 deletions

View file

@ -987,6 +987,14 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetCatalogDeeplink
return ToJavaString(env, bm.GetCategoryCatalogDeeplink(static_cast<kml::MarkGroupId>(catId)));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetCatalogPublicLink(
JNIEnv * env, jobject, jlong catId)
{
auto & bm = frm()->GetBookmarkManager();
return ToJavaString(env, bm.GetCategoryCatalogPublicLink(static_cast<kml::MarkGroupId>(catId)));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetCatalogDownloadUrl(
JNIEnv * env, jobject, jstring serverId)

View file

@ -99,12 +99,7 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
@Override
protected void onShareActionSelected(@NonNull BookmarkCategory category)
{
String deepLink = BookmarkManager.INSTANCE.getCatalogDeeplink(category.getId());
Intent intent = new Intent(Intent.ACTION_SEND)
.setType(TargetUtils.TYPE_TEXT_PLAIN)
.putExtra(Intent.EXTRA_SUBJECT, deepLink)
.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_bookmarks_email_body));
startActivity(Intent.createChooser(intent, getString(R.string.share)));
throw new AssertionError("Sharing is not supported for downloaded guides");
}
@Override

View file

@ -693,6 +693,12 @@ public enum BookmarkManager
return nativeGetCatalogDeeplink(catId);
}
@NonNull
public String getCatalogPublicLink(long catId)
{
return nativeGetCatalogPublicLink(catId);
}
@NonNull
public String getCatalogDownloadUrl(@NonNull String serverId)
{
@ -911,6 +917,9 @@ public enum BookmarkManager
@NonNull
private static native String nativeGetCatalogDeeplink(long catId);
@NonNull
private static native String nativeGetCatalogPublicLink(long catId);
@NonNull
private static native String nativeGetCatalogDownloadUrl(@NonNull String serverId);

View file

@ -256,22 +256,21 @@ public class UgcSharingOptionsFragment extends BaseToolbarAuthFragment implement
private void onPublishedCategoryShared()
{
shareCategory();
shareCategory(BookmarkManager.INSTANCE.getCatalogPublicLink(mCategory.getId()));
}
private void shareCategory()
private void shareCategory(@NonNull String link)
{
String deepLink = BookmarkManager.INSTANCE.getCatalogDeeplink(mCategory.getId());
Intent intent = new Intent(Intent.ACTION_SEND)
.setType(TargetUtils.TYPE_TEXT_PLAIN)
.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_bookmarks_email_body_link, deepLink));
.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_bookmarks_email_body_link, link));
startActivity(Intent.createChooser(intent, getString(R.string.share)));
Statistics.INSTANCE.trackSharingOptionsClick(Statistics.ParamValue.COPY_LINK);
}
private void onDirectLinkShared()
{
shareCategory();
shareCategory(BookmarkManager.INSTANCE.getCatalogDeeplink(mCategory.getId()));
}
private void showNoNetworkConnectionDialog()

View file

@ -455,7 +455,17 @@ extension BookmarksSharingViewController: UITextViewDelegate {
extension BookmarksSharingViewController: UploadActionCellDelegate {
func cellDidPressShareButton(_ cell: UploadActionCell, senderView: UIView) {
guard let url = manager.sharingUrl(forCategoryId: category.categoryId) else {
if cell == uploadAndPublishCell {
share(manager.publicLink(forCategoryId: category.categoryId), senderView: senderView)
} else if cell == getDirectLinkCell {
share(manager.deeplink(forCategoryId: category.categoryId), senderView: senderView)
} else {
assert(false, "unsupported cell")
}
}
func share(_ url: URL?, senderView: UIView) {
guard let url = url else {
assert(false, "must provide guide url")
return
}

View file

@ -70,7 +70,8 @@ typedef void (^PingCompletionBlock)(BOOL success);
- (NSURL * _Nullable)catalogFrontendUrl:(MWMUTM)utm;
- (NSURL * _Nullable)catalogFrontendUrlPlusPath:(NSString *)path
utm:(MWMUTM)utm;
- (NSURL * _Nullable)sharingUrlForCategoryId:(MWMMarkGroupID)groupId;
- (NSURL *_Nullable)deeplinkForCategoryId:(MWMMarkGroupID)groupId;
- (NSURL *_Nullable)publicLinkForCategoryId:(MWMMarkGroupID)groupId;
- (NSURL * _Nullable)webEditorUrlForCategoryId:(MWMMarkGroupID)groupId;
- (void)downloadItemWithId:(NSString *)itemId
name:(NSString *)name

View file

@ -598,12 +598,16 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
return urlString ? [NSURL URLWithString:[urlString stringByAppendingPathComponent:path]] : nil;
}
- (NSURL *)sharingUrlForCategoryId:(MWMMarkGroupID)groupId
{
- (NSURL *)deeplinkForCategoryId:(MWMMarkGroupID)groupId {
NSString * urlString = @(self.bm.GetCategoryCatalogDeeplink(groupId).c_str());
return urlString ? [NSURL URLWithString:urlString] : nil;
}
- (NSURL *)publicLinkForCategoryId:(MWMMarkGroupID)groupId {
NSString *urlString = @(self.bm.GetCategoryCatalogPublicLink(groupId).c_str());
return urlString ? [NSURL URLWithString:urlString] : nil;
}
- (NSURL *)webEditorUrlForCategoryId:(MWMMarkGroupID)groupId {
auto serverId = self.bm.GetCategoryServerId(groupId);
auto language = [[AppInfo sharedInfo] twoLetterLanguageId].UTF8String;

View file

@ -300,6 +300,16 @@ bool BookmarkCategory::IsCategoryFromCatalog() const
}
std::string BookmarkCategory::GetCatalogDeeplink() const
{
if (kDeepLinkUrl.empty())
return {};
std::ostringstream ss;
ss << kDeepLinkUrl << "catalogue?id=" << m_serverId << "&name=" << UrlEncode(GetName());
return ss.str();
}
std::string BookmarkCategory::GetCatalogPublicLink() const
{
if (kDeepLinkUrl.empty())
return {};

View file

@ -95,6 +95,7 @@ public:
bool IsCategoryFromCatalog() const;
std::string GetCatalogDeeplink() const;
std::string GetCatalogPublicLink() const;
void SetAuthor(std::string const & name, std::string const & id);
void SetAccessRules(kml::AccessRules accessRules);

View file

@ -3232,6 +3232,14 @@ std::string BookmarkManager::GetCategoryCatalogDeeplink(kml::MarkGroupId categor
return cat->GetCatalogDeeplink();
}
std::string BookmarkManager::GetCategoryCatalogPublicLink(kml::MarkGroupId categoryId) const
{
auto cat = GetBmCategory(categoryId);
if (cat == nullptr)
return {};
return cat->GetCatalogPublicLink();
}
BookmarkCatalog const & BookmarkManager::GetCatalog() const
{
CHECK_THREAD_CHECKER(m_threadChecker, ());

View file

@ -396,6 +396,7 @@ public:
bool IsCategoryFromCatalog(kml::MarkGroupId categoryId) const;
std::string GetCategoryServerId(kml::MarkGroupId categoryId) const;
std::string GetCategoryCatalogDeeplink(kml::MarkGroupId categoryId) const;
std::string GetCategoryCatalogPublicLink(kml::MarkGroupId categoryId) const;
BookmarkCatalog const & GetCatalog() const;
bool IsMyCategory(kml::MarkGroupId categoryId) const;