From 323ea46de6222c295346b631313920280447d282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Thu, 14 Nov 2019 17:56:03 +0300 Subject: [PATCH] [android] Added parsing 'groups' parameter in buy_kml request to recognize which one subscription screen should be shown --- .../DefaultBookmarkDownloadController.java | 2 ++ .../maps/bookmarks/PaymentDataParser.java | 11 ------ .../SystemDownloadCompletedService.java | 12 ++++--- .../maps/bookmarks/data/PaymentData.java | 14 +++++++- .../BookmarkPaymentDataParser.java | 31 +++++++++------- .../purchase/BookmarkPaymentFragment.java | 23 +++++++++--- .../BookmarksAllSubscriptionActivity.java | 9 +++++ .../BookmarksSightsSubscriptionActivity.java | 9 +++++ .../maps/purchase/PaymentDataParser.java | 13 +++++++ .../maps/purchase/PurchaseUtils.java | 35 +++++++++++++++++-- 10 files changed, 123 insertions(+), 36 deletions(-) delete mode 100644 android/src/com/mapswithme/maps/bookmarks/PaymentDataParser.java rename android/src/com/mapswithme/maps/{bookmarks => purchase}/BookmarkPaymentDataParser.java (59%) create mode 100644 android/src/com/mapswithme/maps/purchase/PaymentDataParser.java diff --git a/android/src/com/mapswithme/maps/bookmarks/DefaultBookmarkDownloadController.java b/android/src/com/mapswithme/maps/bookmarks/DefaultBookmarkDownloadController.java index 9ec11b31d2..bfa05bc663 100644 --- a/android/src/com/mapswithme/maps/bookmarks/DefaultBookmarkDownloadController.java +++ b/android/src/com/mapswithme/maps/bookmarks/DefaultBookmarkDownloadController.java @@ -9,6 +9,8 @@ import android.text.TextUtils; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.PaymentData; +import com.mapswithme.maps.purchase.BookmarkPaymentDataParser; +import com.mapswithme.maps.purchase.PaymentDataParser; import com.mapswithme.util.log.Logger; import com.mapswithme.util.log.LoggerFactory; diff --git a/android/src/com/mapswithme/maps/bookmarks/PaymentDataParser.java b/android/src/com/mapswithme/maps/bookmarks/PaymentDataParser.java deleted file mode 100644 index 34b2bc1c27..0000000000 --- a/android/src/com/mapswithme/maps/bookmarks/PaymentDataParser.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mapswithme.maps.bookmarks; - -import androidx.annotation.NonNull; - -import com.mapswithme.maps.bookmarks.data.PaymentData; - -interface PaymentDataParser -{ - @NonNull - PaymentData parse(@NonNull String url); -} diff --git a/android/src/com/mapswithme/maps/bookmarks/SystemDownloadCompletedService.java b/android/src/com/mapswithme/maps/bookmarks/SystemDownloadCompletedService.java index c77049ad69..756289a305 100644 --- a/android/src/com/mapswithme/maps/bookmarks/SystemDownloadCompletedService.java +++ b/android/src/com/mapswithme/maps/bookmarks/SystemDownloadCompletedService.java @@ -6,15 +6,17 @@ import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; +import android.text.TextUtils; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.JobIntentService; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import android.text.TextUtils; - import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.bookmarks.data.Error; import com.mapswithme.maps.bookmarks.data.Result; +import com.mapswithme.maps.purchase.BookmarkPaymentDataParser; +import com.mapswithme.maps.purchase.PaymentDataParser; import com.mapswithme.util.Utils; import com.mapswithme.util.concurrency.UiThread; import com.mapswithme.util.log.Logger; @@ -152,9 +154,9 @@ public class SystemDownloadCompletedService extends JobIntentService decodedUrl = ""; } - BookmarkPaymentDataParser p = new BookmarkPaymentDataParser(); - String productId = p.getParameter(decodedUrl, BookmarkPaymentDataParser.PRODUCT_ID); - String name = p.getParameter(decodedUrl, BookmarkPaymentDataParser.NAME); + PaymentDataParser p = new BookmarkPaymentDataParser(); + String productId = p.getParameterByName(decodedUrl, BookmarkPaymentDataParser.PRODUCT_ID); + String name = p.getParameterByName(decodedUrl, BookmarkPaymentDataParser.NAME); MwmApplication app = (MwmApplication) application; if (TextUtils.isEmpty(productId)) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/PaymentData.java b/android/src/com/mapswithme/maps/bookmarks/data/PaymentData.java index 5ea913fb94..804ebc5aed 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/PaymentData.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/PaymentData.java @@ -2,6 +2,7 @@ package com.mapswithme.maps.bookmarks.data; import android.os.Parcel; import android.os.Parcelable; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -17,15 +18,18 @@ public class PaymentData implements Parcelable private final String mImgUrl; @NonNull private final String mAuthorName; + @NonNull + private final String mGroup; public PaymentData(@NonNull String serverId, @NonNull String productId, @NonNull String name, - @Nullable String imgUrl, @NonNull String authorName) + @Nullable String imgUrl, @NonNull String authorName, @NonNull String group) { mServerId = serverId; mProductId = productId; mName = name; mImgUrl = imgUrl; mAuthorName = authorName; + mGroup = group; } private PaymentData(Parcel in) @@ -35,6 +39,7 @@ public class PaymentData implements Parcelable mName = in.readString(); mImgUrl = in.readString(); mAuthorName = in.readString(); + mGroup = in.readString(); } public static final Creator CREATOR = new Creator() @@ -82,6 +87,12 @@ public class PaymentData implements Parcelable return mAuthorName; } + @NonNull + public String getGroup() + { + return mGroup; + } + @Override public int describeContents() { @@ -96,5 +107,6 @@ public class PaymentData implements Parcelable dest.writeString(mName); dest.writeString(mImgUrl); dest.writeString(mAuthorName); + dest.writeString(mGroup); } } diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkPaymentDataParser.java b/android/src/com/mapswithme/maps/purchase/BookmarkPaymentDataParser.java similarity index 59% rename from android/src/com/mapswithme/maps/bookmarks/BookmarkPaymentDataParser.java rename to android/src/com/mapswithme/maps/purchase/BookmarkPaymentDataParser.java index b6a519c43c..7a5db2b71e 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkPaymentDataParser.java +++ b/android/src/com/mapswithme/maps/purchase/BookmarkPaymentDataParser.java @@ -1,22 +1,26 @@ -package com.mapswithme.maps.bookmarks; +package com.mapswithme.maps.purchase; import android.net.Uri; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.mapswithme.maps.bookmarks.data.PaymentData; import com.mapswithme.util.CrashlyticsUtils; +import com.mapswithme.util.log.Logger; +import com.mapswithme.util.log.LoggerFactory; -class BookmarkPaymentDataParser implements PaymentDataParser +public class BookmarkPaymentDataParser implements PaymentDataParser { + private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING); private static final String TAG = BookmarkPaymentDataParser.class.getSimpleName(); - final static String SERVER_ID = "id"; - final static String PRODUCT_ID = "tier"; - final static String NAME = "name"; - final static String IMG_URL = "img"; - final static String AUTHOR_NAME = "author_name"; + public final static String SERVER_ID = "id"; + public final static String PRODUCT_ID = "tier"; + public final static String NAME = "name"; + public final static String IMG_URL = "img"; + public final static String AUTHOR_NAME = "author_name"; + public final static String GROUPS = "groups"; @NonNull @Override @@ -27,15 +31,18 @@ class BookmarkPaymentDataParser implements PaymentDataParser String productId = getQueryRequiredParameter(uri, PRODUCT_ID); String name = getQueryRequiredParameter(uri, NAME); String authorName = getQueryRequiredParameter(uri, AUTHOR_NAME); + String group = PurchaseUtils.getTargetBookmarkGroupFromUri(uri); + LOGGER.i(TAG, "Found target group: " + group); String imgUrl = uri.getQueryParameter(IMG_URL); - return new PaymentData(serverId, productId, name, imgUrl, authorName); + return new PaymentData(serverId, productId, name, imgUrl, authorName, group); } @Nullable - String getParameter(@NonNull String url, @NonNull String parameterName) + @Override + public String getParameterByName(@NonNull String url, @NonNull String name) { Uri uri = Uri.parse(url); - return uri.getQueryParameter(parameterName); + return uri.getQueryParameter(name); } @NonNull diff --git a/android/src/com/mapswithme/maps/purchase/BookmarkPaymentFragment.java b/android/src/com/mapswithme/maps/purchase/BookmarkPaymentFragment.java index d9c9290bf5..1198fd5a5c 100644 --- a/android/src/com/mapswithme/maps/purchase/BookmarkPaymentFragment.java +++ b/android/src/com/mapswithme/maps/purchase/BookmarkPaymentFragment.java @@ -3,8 +3,6 @@ package com.mapswithme.maps.purchase; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -13,6 +11,8 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.billingclient.api.SkuDetails; import com.bumptech.glide.Glide; import com.mapswithme.maps.Framework; @@ -110,8 +110,20 @@ public class BookmarkPaymentFragment extends BaseMwmFragment private void onBuySubscriptionClicked() { - BookmarkSubscriptionActivity.startForResult(this, PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION, - Statistics.ParamValue.CARD); + String bookmarksGroup = mPaymentData.getGroup(); + + if (bookmarksGroup.equals(SubscriptionType.BOOKMARKS_SIGHTS.getServerId())) + { + BookmarksSightsSubscriptionActivity.startForResult + (this, PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION, Statistics.ParamValue.CARD); + return; + } + + if (bookmarksGroup.equals(SubscriptionType.BOOKMARKS_ALL.getServerId())) + { + BookmarksAllSubscriptionActivity.startForResult + (this, PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION, Statistics.ParamValue.CARD); + } } @Override @@ -135,7 +147,8 @@ public class BookmarkPaymentFragment extends BaseMwmFragment Statistics.INSTANCE.trackPurchasePreviewSelect(mPaymentData.getServerId(), mPaymentData.getProductId()); Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_PAY, - mPaymentData.getServerId(), Statistics.STATISTICS_CHANNEL_REALTIME); + mPaymentData.getServerId(), + Statistics.STATISTICS_CHANNEL_REALTIME); startPurchaseTransaction(); } diff --git a/android/src/com/mapswithme/maps/purchase/BookmarksAllSubscriptionActivity.java b/android/src/com/mapswithme/maps/purchase/BookmarksAllSubscriptionActivity.java index 0680864908..0c8ac28135 100644 --- a/android/src/com/mapswithme/maps/purchase/BookmarksAllSubscriptionActivity.java +++ b/android/src/com/mapswithme/maps/purchase/BookmarksAllSubscriptionActivity.java @@ -27,4 +27,13 @@ public class BookmarksAllSubscriptionActivity extends BaseMwmFragmentActivity { return R.style.MwmTheme; } + + public static void startForResult(@NonNull Fragment fragment, int requestCode, + @NonNull String from) + { + Intent intent = new Intent(fragment.getActivity(), BookmarksAllSubscriptionActivity.class); + intent.putExtra(AbstractBookmarkSubscriptionFragment.EXTRA_FROM, from) + .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + fragment.startActivityForResult(intent, requestCode); + } } diff --git a/android/src/com/mapswithme/maps/purchase/BookmarksSightsSubscriptionActivity.java b/android/src/com/mapswithme/maps/purchase/BookmarksSightsSubscriptionActivity.java index 3d9c6d7352..74e9557081 100644 --- a/android/src/com/mapswithme/maps/purchase/BookmarksSightsSubscriptionActivity.java +++ b/android/src/com/mapswithme/maps/purchase/BookmarksSightsSubscriptionActivity.java @@ -27,4 +27,13 @@ public class BookmarksSightsSubscriptionActivity extends BaseMwmFragmentActivity { return R.style.MwmTheme; } + + public static void startForResult(@NonNull Fragment fragment, int requestCode, + @NonNull String from) + { + Intent intent = new Intent(fragment.getActivity(), BookmarksSightsSubscriptionActivity.class); + intent.putExtra(AbstractBookmarkSubscriptionFragment.EXTRA_FROM, from) + .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + fragment.startActivityForResult(intent, requestCode); + } } diff --git a/android/src/com/mapswithme/maps/purchase/PaymentDataParser.java b/android/src/com/mapswithme/maps/purchase/PaymentDataParser.java new file mode 100644 index 0000000000..a836a97ce2 --- /dev/null +++ b/android/src/com/mapswithme/maps/purchase/PaymentDataParser.java @@ -0,0 +1,13 @@ +package com.mapswithme.maps.purchase; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.mapswithme.maps.bookmarks.data.PaymentData; + +public interface PaymentDataParser +{ + @NonNull + PaymentData parse(@NonNull String url); + @Nullable + String getParameterByName(@NonNull String url, @NonNull String name); +} diff --git a/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java b/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java index bc608dface..2d5470b6d0 100644 --- a/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java +++ b/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java @@ -1,10 +1,11 @@ package com.mapswithme.maps.purchase; +import android.net.Uri; +import android.text.TextUtils; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import android.text.TextUtils; - import com.android.billingclient.api.Purchase; import com.android.billingclient.api.SkuDetails; import com.mapswithme.maps.R; @@ -16,6 +17,7 @@ import com.mapswithme.util.log.LoggerFactory; import org.json.JSONException; import org.json.JSONObject; +import java.util.Arrays; import java.util.List; public class PurchaseUtils @@ -178,6 +180,35 @@ public class PurchaseUtils dialog.show(fragment, NO_NETWORK_CONNECTION_DIALOG_TAG); } + @NonNull + static String getTargetBookmarkGroupFromUri(@NonNull Uri uri) + { + List uriGroups = uri.getQueryParameters(BookmarkPaymentDataParser.GROUPS); + if (uriGroups == null || uriGroups.isEmpty()) + { + CrashlyticsUtils.logException( + new IllegalArgumentException("'" + BookmarkPaymentDataParser.GROUPS + + "' parameter is required! URI: " + uri)); + return SubscriptionType.BOOKMARKS_ALL.getServerId(); + } + + + List priorityGroups = Arrays.asList(SubscriptionType.BOOKMARKS_ALL.getServerId(), + SubscriptionType.BOOKMARKS_SIGHTS.getServerId()); + for (String priorityGroup : priorityGroups) + { + for (String uriGroup : uriGroups) + { + if (priorityGroup.equals(uriGroup)) + { + return priorityGroup; + } + } + } + + return SubscriptionType.BOOKMARKS_ALL.getServerId(); + } + enum Period { // Order is important.