forked from organicmaps/organicmaps
[android] Unbound bookmark payment state from specific fragment link, now it works with the subscription ui interface
This commit is contained in:
parent
923dbbefee
commit
ca4784669e
3 changed files with 158 additions and 81 deletions
|
@ -2,17 +2,17 @@ package com.mapswithme.maps.purchase;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
|
@ -22,6 +22,9 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
|||
import com.mapswithme.maps.dialog.AlertDialog;
|
||||
import com.mapswithme.maps.dialog.AlertDialogCallback;
|
||||
import com.mapswithme.maps.dialog.ResolveFragmentManagerStrategy;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.NetworkPolicy;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
@ -31,9 +34,10 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
||||
implements AlertDialogCallback, PurchaseStateActivator<BookmarkSubscriptionPaymentState>
|
||||
implements AlertDialogCallback, PurchaseStateActivator<BookmarkSubscriptionPaymentState>,
|
||||
SubscriptionUiChangeListener
|
||||
{
|
||||
public static final String EXTRA_FROM = "extra_from";
|
||||
static final String EXTRA_FROM = "extra_from";
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING);
|
||||
private static final String TAG = BookmarkSubscriptionFragment.class.getSimpleName();
|
||||
|
@ -152,7 +156,7 @@ public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
|||
activateState(BookmarkSubscriptionPaymentState.CHECK_NETWORK_CONNECTION);
|
||||
}
|
||||
|
||||
void queryProductDetails()
|
||||
private void queryProductDetails()
|
||||
{
|
||||
mPurchaseController.queryProductDetails();
|
||||
}
|
||||
|
@ -194,7 +198,7 @@ public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
|||
}
|
||||
}
|
||||
|
||||
void updatePaymentButtons()
|
||||
private void updatePaymentButtons()
|
||||
{
|
||||
updateYearlyButton();
|
||||
updateMonthlyButton();
|
||||
|
@ -269,7 +273,7 @@ public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
|||
mPingingResult = result;
|
||||
}
|
||||
|
||||
void finishValidation()
|
||||
private void finishValidation()
|
||||
{
|
||||
if (mValidationResult)
|
||||
requireActivity().setResult(Activity.RESULT_OK);
|
||||
|
@ -277,7 +281,7 @@ public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
|||
requireActivity().finish();
|
||||
}
|
||||
|
||||
public void finishPinging()
|
||||
private void finishPinging()
|
||||
{
|
||||
if (!mPingingResult)
|
||||
{
|
||||
|
@ -343,7 +347,7 @@ public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
|||
LOGGER.w(TAG, "Social authentication error = " + error + ", auth type = " + type);
|
||||
}
|
||||
|
||||
public void onNetworkCheckPassed()
|
||||
private void onNetworkCheckPassed()
|
||||
{
|
||||
activateState(BookmarkSubscriptionPaymentState.PRODUCT_DETAILS_LOADING);
|
||||
}
|
||||
|
@ -361,6 +365,111 @@ public class BookmarkSubscriptionFragment extends BaseAuthFragment
|
|||
manager.executePendingTransactions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReset()
|
||||
{
|
||||
hideAllUi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProductDetailsLoading()
|
||||
{
|
||||
showRootScreenProgress();
|
||||
queryProductDetails();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProductDetailsFailure()
|
||||
{
|
||||
PurchaseUtils.showProductDetailsFailureDialog(this, getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaymentFailure()
|
||||
{
|
||||
PurchaseUtils.showPaymentFailureDialog(this, getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPriceSelection()
|
||||
{
|
||||
hideRootScreenProgress();
|
||||
updatePaymentButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValidating()
|
||||
{
|
||||
showButtonProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValidationFinish()
|
||||
{
|
||||
hideButtonProgress();
|
||||
finishValidation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPinging()
|
||||
{
|
||||
showButtonProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPingFinish()
|
||||
{
|
||||
hideButtonProgress();
|
||||
finishPinging();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckNetworkConnection()
|
||||
{
|
||||
if (ConnectionState.isConnected())
|
||||
NetworkPolicy.checkNetworkPolicy(requireFragmentManager(),
|
||||
this::onNetworkPolicyResult, true);
|
||||
else
|
||||
PurchaseUtils.showNoConnectionDialog(this);
|
||||
}
|
||||
|
||||
private void onNetworkPolicyResult(@NonNull NetworkPolicy policy)
|
||||
{
|
||||
if (policy.canUseNetwork())
|
||||
onNetworkCheckPassed();
|
||||
else
|
||||
requireActivity().finish();
|
||||
}
|
||||
|
||||
private void showButtonProgress()
|
||||
{
|
||||
UiUtils.hide(getViewOrThrow(), R.id.continue_btn);
|
||||
UiUtils.show(getViewOrThrow(), R.id.progress);
|
||||
}
|
||||
|
||||
private void hideButtonProgress()
|
||||
{
|
||||
UiUtils.hide(getViewOrThrow(), R.id.progress);
|
||||
UiUtils.show(getViewOrThrow(), R.id.continue_btn);
|
||||
}
|
||||
|
||||
private void showRootScreenProgress()
|
||||
{
|
||||
UiUtils.show(getViewOrThrow(), R.id.root_screen_progress);
|
||||
UiUtils.hide(getViewOrThrow(), R.id.content_view);
|
||||
}
|
||||
|
||||
private void hideRootScreenProgress()
|
||||
{
|
||||
UiUtils.hide(getViewOrThrow(), R.id.root_screen_progress);
|
||||
UiUtils.show(getViewOrThrow(), R.id.content_view);
|
||||
}
|
||||
|
||||
private void hideAllUi()
|
||||
{
|
||||
UiUtils.hide(getViewOrThrow(), R.id.root_screen_progress, R.id.content_view);
|
||||
}
|
||||
|
||||
private class AnnualCardClickListener implements View.OnClickListener
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -2,137 +2,90 @@ package com.mapswithme.maps.purchase;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.NetworkPolicy;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public enum BookmarkSubscriptionPaymentState
|
||||
{
|
||||
NONE
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
UiUtils.hide(fragment.getViewOrThrow(), R.id.root_screen_progress, R.id.content_view);
|
||||
listener.onReset();
|
||||
}
|
||||
},
|
||||
PRODUCT_DETAILS_LOADING
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
showProgress(fragment);
|
||||
fragment.queryProductDetails();
|
||||
listener.onProductDetailsLoading();
|
||||
}
|
||||
},
|
||||
PRODUCT_DETAILS_FAILURE
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
PurchaseUtils.showProductDetailsFailureDialog(fragment, name());
|
||||
listener.onProductDetailsFailure();
|
||||
}
|
||||
},
|
||||
PAYMENT_FAILURE
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
PurchaseUtils.showPaymentFailureDialog(fragment, name());
|
||||
listener.onPaymentFailure();
|
||||
}
|
||||
},
|
||||
PRICE_SELECTION
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
hideProgress(fragment);
|
||||
fragment.updatePaymentButtons();
|
||||
listener.onPriceSelection();
|
||||
}
|
||||
},
|
||||
VALIDATION
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
showButtonProgress(fragment);
|
||||
listener.onValidating();
|
||||
}
|
||||
},
|
||||
VALIDATION_FINISH
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
hideButtonProgress(fragment);
|
||||
fragment.finishValidation();
|
||||
listener.onValidationFinish();
|
||||
}
|
||||
},
|
||||
PINGING
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
showButtonProgress(fragment);
|
||||
listener.onPinging();
|
||||
}
|
||||
},
|
||||
PINGING_FINISH
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
BookmarkSubscriptionPaymentState.hideButtonProgress(fragment);
|
||||
fragment.finishPinging();
|
||||
listener.onPingFinish();
|
||||
}
|
||||
},
|
||||
|
||||
CHECK_NETWORK_CONNECTION
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
void activate(@NonNull SubscriptionUiChangeListener listener)
|
||||
{
|
||||
if (ConnectionState.isConnected())
|
||||
NetworkPolicy.checkNetworkPolicy(fragment.requireFragmentManager(),
|
||||
policy -> onNetworkPolicyResult(policy, fragment), true);
|
||||
else
|
||||
PurchaseUtils.showNoConnectionDialog(fragment);
|
||||
listener.onCheckNetworkConnection();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private void onNetworkPolicyResult(@NonNull NetworkPolicy policy,
|
||||
@NonNull BookmarkSubscriptionFragment fragment)
|
||||
{
|
||||
if (policy.canUseNetwork())
|
||||
fragment.onNetworkCheckPassed();
|
||||
else
|
||||
fragment.requireActivity().finish();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
private static void showProgress(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
{
|
||||
UiUtils.show(fragment.getViewOrThrow(), R.id.root_screen_progress);
|
||||
UiUtils.hide(fragment.getViewOrThrow(), R.id.content_view);
|
||||
}
|
||||
|
||||
private static void hideProgress(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
{
|
||||
UiUtils.hide(fragment.getViewOrThrow(), R.id.root_screen_progress);
|
||||
UiUtils.show(fragment.getViewOrThrow(), R.id.content_view);
|
||||
}
|
||||
|
||||
private static void showButtonProgress(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
{
|
||||
UiUtils.hide(fragment.getViewOrThrow(), R.id.continue_btn);
|
||||
UiUtils.show(fragment.getViewOrThrow(), R.id.progress);
|
||||
}
|
||||
|
||||
private static void hideButtonProgress(@NonNull BookmarkSubscriptionFragment fragment)
|
||||
{
|
||||
UiUtils.hide(fragment.getViewOrThrow(), R.id.progress);
|
||||
UiUtils.show(fragment.getViewOrThrow(), R.id.continue_btn);
|
||||
}
|
||||
|
||||
abstract void activate(@NonNull BookmarkSubscriptionFragment fragment);
|
||||
abstract void activate(@NonNull SubscriptionUiChangeListener listener);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.mapswithme.maps.purchase;
|
||||
|
||||
public interface SubscriptionUiChangeListener
|
||||
{
|
||||
void onReset();
|
||||
void onProductDetailsLoading();
|
||||
void onProductDetailsFailure();
|
||||
void onPaymentFailure();
|
||||
void onPriceSelection();
|
||||
void onValidating();
|
||||
void onValidationFinish();
|
||||
void onPinging();
|
||||
void onPingFinish();
|
||||
void onCheckNetworkConnection();
|
||||
}
|
Loading…
Add table
Reference in a new issue