forked from organicmaps/organicmaps
[android] Implemented bookmark subscription success dialog, reloading of catalog and refactored request codes across bookmarks code
This commit is contained in:
parent
635d8a8407
commit
7bf0e66bbb
7 changed files with 83 additions and 36 deletions
|
@ -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">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:gravity="center|start"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:gravity="start"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:textStyle="bold"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:text="Woohoo!"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_marginEnd="@dimen/margin_base"/>
|
||||
<ImageView
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
<dimen name="height_item_edit_bookmark">72dp</dimen>
|
||||
<dimen name="primary_button_min_height">36dp</dimen>
|
||||
<dimen name="primary_button_min_width">64dp</dimen>
|
||||
<dimen name="dialog_min_width">288dp</dimen>
|
||||
|
||||
<dimen name="dialog_max_height">320dp</dimen>
|
||||
<dimen name="search_item_height">56dp</dimen>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue