From 7bf0e66bbb8ec2e9d000ff7734b96d494dbbd5ab 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: Mon, 8 Jul 2019 20:11:18 +0300 Subject: [PATCH] [android] Implemented bookmark subscription success dialog, reloading of catalog and refactored request codes across bookmarks code --- android/res/layout/fragment_confirmation.xml | 10 ++-- android/res/values/dimens.xml | 1 + .../bookmarks/BookmarksCatalogFragment.java | 52 +++++++++++++++---- .../BookmarksDownloadFragmentDelegate.java | 26 +++++----- ...nvalidSubscriptionAlertDialogCallback.java | 8 ++- .../mapswithme/maps/dialog/AlertDialog.java | 14 +++-- .../maps/purchase/PurchaseUtils.java | 8 +++ 7 files changed, 83 insertions(+), 36 deletions(-) diff --git a/android/res/layout/fragment_confirmation.xml b/android/res/layout/fragment_confirmation.xml index 1326faf614..5d16163bfa 100644 --- a/android/res/layout/fragment_confirmation.xml +++ b/android/res/layout/fragment_confirmation.xml @@ -3,25 +3,27 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" - android:layout_width="wrap_content" + android:layout_width="match_parent" + android:minWidth="@dimen/dialog_min_width" android:layout_height="wrap_content" android:gravity="center_horizontal" android:padding="@dimen/margin_base"> 72dp 36dp 64dp + 288dp 320dp 56dp diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java index 13b0931285..ab609fd32c 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java @@ -66,8 +66,6 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment private static final String FAILED_PURCHASE_DIALOG_TAG = "failed_purchase_dialog_tag"; private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING); private static final String TAG = BookmarksCatalogFragment.class.getSimpleName(); - static final int REQ_CODE_PAY_SUBSCRIPTION = 1; - static final int REQ_CODE_PAY_BOOKMARK = 2; @SuppressWarnings("NullableProblems") @NonNull private WebViewBookmarksCatalogClient mWebViewClient; @@ -97,7 +95,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment private BookmarksDownloadFragmentDelegate mDelegate; @SuppressWarnings("NullableProblems") @NonNull - private AlertDialogCallback mDialogClickDelegate; + private AlertDialogCallback mInvalidSubsDialogDelegate; @Override public void onCreate(@Nullable Bundle savedInstanceState) @@ -105,7 +103,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment super.onCreate(savedInstanceState); mDelegate = new BookmarksDownloadFragmentDelegate(this); mDelegate.onCreate(savedInstanceState); - mDialogClickDelegate = new InvalidSubscriptionAlertDialogCallback(this); + mInvalidSubsDialogDelegate = new InvalidSubscriptionAlertDialogCallback(this); } @Override @@ -217,10 +215,25 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment if (resultCode != Activity.RESULT_OK) return; - if (requestCode != REQ_CODE_PAY_SUBSCRIPTION) + if (requestCode != PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION) return; - onRetryClick(); + showSubscriptionSuccessDialog(); + } + + private void showSubscriptionSuccessDialog() + { + AlertDialog dialog = new AlertDialog.Builder() + .setTitleId(R.string.subscription_success_dialog_title) + .setMessageId(R.string.subscription_success_dialog_message) + .setPositiveBtnId(R.string.subscription_error_button) + .setReqCode(PurchaseUtils.REQ_CODE_BMK_SUBS_SUCCESS_DIALOG) + .setFragManagerStrategyType(AlertDialog.FragManagerStrategyType.ACTIVITY_FRAGMENT_MANAGER) + .setDialogViewStrategyType(AlertDialog.DialogViewStrategyType.CONFIRMATION_DIALOG) + .setDialogFactory(new ConfirmationDialogFactory()) + .build(); + dialog.setTargetFragment(this, PurchaseUtils.REQ_CODE_BMK_SUBS_SUCCESS_DIALOG); + dialog.show(this, PurchaseUtils.DIALOG_TAG_BMK_SUBSCRIPTION_SUCCESS); } @Override @@ -268,19 +281,38 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment @Override public void onAlertDialogPositiveClick(int requestCode, int which) { - mDialogClickDelegate.onAlertDialogPositiveClick(requestCode, which); + switch (requestCode) + { + case PurchaseUtils.REQ_CODE_CHECK_INVALID_SUBS_DIALOG: + mInvalidSubsDialogDelegate.onAlertDialogPositiveClick(requestCode, which); + break; + case PurchaseUtils.REQ_CODE_BMK_SUBS_SUCCESS_DIALOG: + onRetryClick(); + break; + } } @Override public void onAlertDialogNegativeClick(int requestCode, int which) { - mDialogClickDelegate.onAlertDialogPositiveClick(requestCode,which); + if (requestCode == PurchaseUtils.REQ_CODE_CHECK_INVALID_SUBS_DIALOG) + { + mInvalidSubsDialogDelegate.onAlertDialogNegativeClick(requestCode, which); + } } @Override public void onAlertDialogCancel(int requestCode) { - mDialogClickDelegate.onAlertDialogCancel(requestCode); + switch (requestCode) + { + case PurchaseUtils.REQ_CODE_CHECK_INVALID_SUBS_DIALOG: + mInvalidSubsDialogDelegate.onAlertDialogCancel(requestCode); + break; + case PurchaseUtils.REQ_CODE_BMK_SUBS_SUCCESS_DIALOG: + onRetryClick(); + break; + } } private static class WebViewBookmarksCatalogClient extends WebViewClient @@ -328,7 +360,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment if (frag == null || frag.getActivity() == null) return; - BookmarkSubscriptionActivity.startForResult(frag, REQ_CODE_PAY_SUBSCRIPTION); + BookmarkSubscriptionActivity.startForResult(frag, PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION); } @Override diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarksDownloadFragmentDelegate.java b/android/src/com/mapswithme/maps/bookmarks/BookmarksDownloadFragmentDelegate.java index ba20ff12d1..190b4d11b9 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarksDownloadFragmentDelegate.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarksDownloadFragmentDelegate.java @@ -21,13 +21,11 @@ import com.mapswithme.maps.dialog.AlertDialog; import com.mapswithme.maps.dialog.ConfirmationDialogFactory; import com.mapswithme.maps.dialog.ProgressDialogFragment; import com.mapswithme.maps.purchase.BookmarkPaymentActivity; +import com.mapswithme.maps.purchase.PurchaseUtils; class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, BookmarkDownloadCallback, TargetFragmentCallback { - private final static int REQ_CODE_PAY_BOOKMARK = 1; - private static final int REQ_CODE_CHECK_INVALID_SUBS_DIALOG = 300; - private static final String CHECK_INVALID_SUBS_DIALOG_TAG = "check_invalid_subs_dialog_tag"; @SuppressWarnings("NullableProblems") @NonNull @@ -94,15 +92,15 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (resultCode == Activity.RESULT_OK && requestCode == BookmarksCatalogFragment.REQ_CODE_PAY_SUBSCRIPTION) + if (resultCode == Activity.RESULT_OK && requestCode == PurchaseUtils.REQ_CODE_PAY_CONTINUE_SUBSCRIPTION) BookmarkManager.INSTANCE.resetInvalidCategories(); - if (requestCode != BookmarksCatalogFragment.REQ_CODE_PAY_BOOKMARK) + if (requestCode != PurchaseUtils.REQ_CODE_PAY_BOOKMARK) return; - if (resultCode == Activity.RESULT_OK && requestCode == REQ_CODE_PAY_BOOKMARK) + if (resultCode == Activity.RESULT_OK) mDownloadController.retryDownloadBookmark(); - else if (requestCode == REQ_CODE_PAY_BOOKMARK) + else mFragment.requireActivity().finish(); } @@ -167,7 +165,7 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark @Override public void onPaymentRequired(@NonNull PaymentData data) { - BookmarkPaymentActivity.startForResult(mFragment, data, BookmarksCatalogFragment.REQ_CODE_PAY_BOOKMARK); + BookmarkPaymentActivity.startForResult(mFragment, data, PurchaseUtils.REQ_CODE_PAY_BOOKMARK); } @Override @@ -224,10 +222,10 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark if (!hasInvalidCategories) return; - showDialog(); + showInvalidBookmarksDialog(); } - private void showDialog() + private void showInvalidBookmarksDialog() { if (mFrag == null) return; @@ -237,7 +235,7 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark .setMessageId(R.string.renewal_screen_message) .setPositiveBtnId(R.string.renewal_screen_button_restore) .setNegativeBtnId(R.string.renewal_screen_button_cancel) - .setReqCode(REQ_CODE_CHECK_INVALID_SUBS_DIALOG) + .setReqCode(PurchaseUtils.REQ_CODE_CHECK_INVALID_SUBS_DIALOG) .setImageResId(R.drawable.ic_error_red) .setFragManagerStrategyType(AlertDialog.FragManagerStrategyType.ACTIVITY_FRAGMENT_MANAGER) .setDialogViewStrategyType(AlertDialog.DialogViewStrategyType.CONFIRMATION_DIALOG) @@ -246,8 +244,8 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark .build(); dialog.setCancelable(false); - dialog.setTargetFragment(mFrag, REQ_CODE_CHECK_INVALID_SUBS_DIALOG); - dialog.show(mFrag, CHECK_INVALID_SUBS_DIALOG_TAG); + dialog.setTargetFragment(mFrag, PurchaseUtils.REQ_CODE_CHECK_INVALID_SUBS_DIALOG); + dialog.show(mFrag, PurchaseUtils.DIALOG_TAG_CHECK_INVALID_SUBS); } @Override @@ -256,7 +254,7 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark mFrag = object; if (Boolean.TRUE.equals(mPendingInvalidCategoriesResult)) { - showDialog(); + showInvalidBookmarksDialog(); mPendingInvalidCategoriesResult = null; } } diff --git a/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java b/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java index 9af894414d..c61c709f6f 100644 --- a/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java +++ b/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java @@ -1,19 +1,19 @@ package com.mapswithme.maps.bookmarks; -import android.content.Intent; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.dialog.AlertDialogCallback; import com.mapswithme.maps.purchase.BookmarkSubscriptionActivity; +import com.mapswithme.maps.purchase.PurchaseUtils; class InvalidSubscriptionAlertDialogCallback implements AlertDialogCallback { @NonNull private final Fragment mFragment; - public InvalidSubscriptionAlertDialogCallback(@NonNull Fragment fragment) + InvalidSubscriptionAlertDialogCallback(@NonNull Fragment fragment) { mFragment = fragment; } @@ -21,9 +21,7 @@ class InvalidSubscriptionAlertDialogCallback implements AlertDialogCallback @Override public void onAlertDialogPositiveClick(int requestCode, int which) { - Intent intent = new Intent(mFragment.requireActivity(), - BookmarkSubscriptionActivity.class); - mFragment.startActivityForResult(intent, BookmarksDownloadFragmentDelegate.REQ_CODE_SUBSCRIPTION_ACTIVITY); + BookmarkSubscriptionActivity.startForResult(mFragment, PurchaseUtils.REQ_CODE_PAY_CONTINUE_SUBSCRIPTION); } @Override diff --git a/android/src/com/mapswithme/maps/dialog/AlertDialog.java b/android/src/com/mapswithme/maps/dialog/AlertDialog.java index 3c0ffbc135..4c4a8c54d7 100644 --- a/android/src/com/mapswithme/maps/dialog/AlertDialog.java +++ b/android/src/com/mapswithme/maps/dialog/AlertDialog.java @@ -420,9 +420,17 @@ public class AlertDialog extends BaseMwmDialogFragment View root = inflater.inflate(fragment.getLayoutId(), null, false); TextView declineBtn = root.findViewById(R.id.decline_btn); - declineBtn.setText(args.getInt(ARG_NEGATIVE_BUTTON_ID)); - declineBtn.setOnClickListener( - v -> fragment.onNegativeClicked(DialogInterface.BUTTON_NEGATIVE)); + int declineBtnTextId = args.getInt(ARG_NEGATIVE_BUTTON_ID); + if (declineBtnTextId != INVALID_ID) + { + declineBtn.setText(args.getInt(ARG_NEGATIVE_BUTTON_ID)); + declineBtn.setOnClickListener( + v -> fragment.onNegativeClicked(DialogInterface.BUTTON_NEGATIVE)); + } + else + { + UiUtils.hide(declineBtn); + } TextView acceptBtn = root.findViewById(R.id.accept_btn); acceptBtn.setText(args.getInt(ARG_POSITIVE_BUTTON_ID)); diff --git a/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java b/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java index 1d117c2b57..1a882a5beb 100644 --- a/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java +++ b/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java @@ -25,6 +25,14 @@ public class PurchaseUtils final static int REQ_CODE_VALIDATION_SERVER_ERROR = 3; final static int REQ_CODE_START_TRANSACTION_FAILURE = 4; final static int REQ_CODE_PING_FAILURE = 5; + public static final int REQ_CODE_CHECK_INVALID_SUBS_DIALOG = 6; + public static final int REQ_CODE_BMK_SUBS_SUCCESS_DIALOG = 7; + public final static int REQ_CODE_PAY_CONTINUE_SUBSCRIPTION = 8; + public final static int REQ_CODE_PAY_BOOKMARK = 9; + public final static int REQ_CODE_PAY_SUBSCRIPTION = 10; + public static final String DIALOG_TAG_CHECK_INVALID_SUBS = "check_invalid_subs"; + public static final String DIALOG_TAG_BMK_SUBSCRIPTION_SUCCESS = "bmk_subscription_success"; + final static int WEEKS_IN_YEAR = 52; final static int MONTHS_IN_YEAR = 12; private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING);