forked from organicmaps/organicmaps
[android] Added blocking of back button pressing while bookmark validation in progress
This commit is contained in:
parent
34481b2831
commit
7ab237c8e7
3 changed files with 24 additions and 9 deletions
|
@ -67,10 +67,16 @@ class BookmarksDownloadFragmentDelegate implements Authorizer.Callback, Bookmark
|
|||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == REQ_CODE_PAY_BOOKMARK)
|
||||
if (requestCode != REQ_CODE_PAY_BOOKMARK)
|
||||
return;
|
||||
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
mDownloadController.retryDownloadBookmark();
|
||||
return;
|
||||
}
|
||||
|
||||
mFragment.requireActivity().finish();
|
||||
}
|
||||
|
||||
private void showAuthorizationProgress()
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
|
@ -79,10 +80,10 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
mPurchaseController = PurchaseFactory.createBookmarkPurchaseController(getContext(),
|
||||
mPurchaseController = PurchaseFactory.createBookmarkPurchaseController(requireContext(),
|
||||
mPaymentData.getProductId(),
|
||||
mPaymentData.getServerId());
|
||||
mPurchaseController.initialize(getActivity());
|
||||
mPurchaseController.initialize(requireActivity());
|
||||
View root = inflater.inflate(R.layout.fragment_bookmark_payment, container, false);
|
||||
TextView buyButton = root.findViewById(R.id.buy_btn);
|
||||
buyButton.setOnClickListener(v -> onBuyClicked());
|
||||
|
@ -104,12 +105,18 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
{
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_CANCEL,
|
||||
mPaymentData.getServerId());
|
||||
getActivity().finish();
|
||||
requireActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed()
|
||||
{
|
||||
if (mState == BookmarkPaymentState.VALIDATION)
|
||||
{
|
||||
Toast.makeText(requireContext(), R.string.please_wait, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_CANCEL,
|
||||
mPaymentData.getServerId());
|
||||
return super.onBackPressed();
|
||||
|
@ -166,7 +173,7 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
PurchaseOperationObservable observable = PurchaseOperationObservable.from(getContext());
|
||||
PurchaseOperationObservable observable = PurchaseOperationObservable.from(requireContext());
|
||||
observable.addTransactionObserver(mPurchaseCallback);
|
||||
mPurchaseController.addCallback(mPurchaseCallback);
|
||||
mPurchaseCallback.attach(this);
|
||||
|
@ -176,7 +183,7 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
PurchaseOperationObservable observable = PurchaseOperationObservable.from(getContext());
|
||||
PurchaseOperationObservable observable = PurchaseOperationObservable.from(requireContext());
|
||||
observable.removeTransactionObserver(mPurchaseCallback);
|
||||
mPurchaseController.removeCallback();
|
||||
mPurchaseCallback.detach();
|
||||
|
@ -259,7 +266,7 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
switch (requestCode)
|
||||
{
|
||||
case REQ_CODE_PRODUCT_DETAILS_FAILURE:
|
||||
getActivity().finish();
|
||||
requireActivity().finish();
|
||||
break;
|
||||
case REQ_CODE_START_TRANSACTION_FAILURE:
|
||||
case REQ_CODE_PAYMENT_FAILURE:
|
||||
|
@ -283,8 +290,9 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
public void finishValidation()
|
||||
{
|
||||
if (mValidationResult)
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
getActivity().finish();
|
||||
requireActivity().setResult(Activity.RESULT_OK);
|
||||
|
||||
requireActivity().finish();
|
||||
}
|
||||
|
||||
private static class BookmarkPurchaseCallback
|
||||
|
|
|
@ -93,6 +93,7 @@ enum BookmarkPaymentState
|
|||
void activate(@NonNull BookmarkPaymentFragment fragment)
|
||||
{
|
||||
showProgress(fragment);
|
||||
UiUtils.hide(fragment.getViewOrThrow(), R.id.cancel_btn);
|
||||
}
|
||||
},
|
||||
VALIDATION_FINISH
|
||||
|
|
Loading…
Add table
Reference in a new issue