forked from organicmaps/organicmaps
[android] Implementing closing billing connection
This commit is contained in:
parent
cb1ee6ea6b
commit
3abacd3edc
6 changed files with 37 additions and 13 deletions
|
@ -72,6 +72,8 @@ import com.mapswithme.maps.maplayer.subway.SubwayManager;
|
|||
import com.mapswithme.maps.maplayer.traffic.OnTrafficLayerToggleListener;
|
||||
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
|
||||
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton;
|
||||
import com.mapswithme.maps.purchase.BillingFactory;
|
||||
import com.mapswithme.maps.purchase.BillingManager;
|
||||
import com.mapswithme.maps.routing.NavigationController;
|
||||
import com.mapswithme.maps.routing.RoutePointInfo;
|
||||
import com.mapswithme.maps.routing.RoutingBottomMenuListener;
|
||||
|
@ -228,7 +230,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
private Bundle mSavedForTabletState;
|
||||
@Nullable
|
||||
private PlacePageTracker mPlacePageTracker;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BillingManager mBillingManager;
|
||||
@NonNull
|
||||
private final OnClickListener mOnMyPositionClickListener = new CurrentPositionClickListener();
|
||||
|
||||
|
@ -547,6 +551,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
SharingHelper.INSTANCE.initialize();
|
||||
|
||||
mBillingManager = BillingFactory.ADS_REMOVAL.createBillingManager(this, "android.test.purchased");
|
||||
|
||||
//TODO: uncomment after correct visible rect calculation.
|
||||
//mVisibleRectMeasurer = new VisibleRectMeasurer(new VisibleRectListener() {
|
||||
// @Override
|
||||
|
@ -1340,6 +1346,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
mBillingManager.initialize();
|
||||
SearchEngine.INSTANCE.addListener(this);
|
||||
Framework.nativeSetMapObjectListener(this);
|
||||
BookmarkManager.INSTANCE.addLoadingListener(this);
|
||||
|
@ -1357,6 +1364,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
protected void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
mBillingManager.destroy();
|
||||
SearchEngine.INSTANCE.removeListener(this);
|
||||
Framework.nativeRemoveMapObjectListener();
|
||||
BookmarkManager.INSTANCE.removeLoadingListener(this);
|
||||
|
|
|
@ -27,11 +27,11 @@ import com.mapswithme.maps.location.LocationHelper;
|
|||
import com.mapswithme.maps.location.TrackRecorder;
|
||||
import com.mapswithme.maps.maplayer.subway.SubwayManager;
|
||||
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
|
||||
import com.mapswithme.maps.purchase.Factory;
|
||||
import com.mapswithme.maps.purchase.BillingFactory;
|
||||
import com.mapswithme.maps.purchase.PurchaseValidator;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.maps.scheduling.ConnectivityListener;
|
||||
import com.mapswithme.maps.scheduling.ConnectivityJobScheduler;
|
||||
import com.mapswithme.maps.scheduling.ConnectivityListener;
|
||||
import com.mapswithme.maps.sound.TtsPlayer;
|
||||
import com.mapswithme.maps.ugc.UGC;
|
||||
import com.mapswithme.util.Config;
|
||||
|
@ -77,7 +77,7 @@ public class MwmApplication extends Application
|
|||
@NonNull
|
||||
private PushwooshHelper mPushwooshHelper;
|
||||
@NonNull
|
||||
private final PurchaseValidator mPurchaseValidator = Factory.ADS_REMOVAL.createPurchaseManager();
|
||||
private final PurchaseValidator mPurchaseValidator = BillingFactory.ADS_REMOVAL.createPurchaseManager();
|
||||
|
||||
private boolean mFrameworkInitialized;
|
||||
private boolean mPlatformInitialized;
|
||||
|
|
|
@ -8,9 +8,14 @@ import android.support.annotation.NonNull;
|
|||
public interface BillingConnection
|
||||
{
|
||||
/**
|
||||
* Connects to the billing manager.
|
||||
* Opens a connection to the billing manager.
|
||||
*/
|
||||
void connect();
|
||||
void open();
|
||||
|
||||
/**
|
||||
* Closes the connection to the billing manager.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* @return the connection state of the billing manager.
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.android.billingclient.api.SkuDetails;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum Factory
|
||||
public enum BillingFactory
|
||||
{
|
||||
ADS_REMOVAL
|
||||
{
|
|
@ -28,12 +28,21 @@ class PlayStoreBillingConnection implements BillingConnection,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connect()
|
||||
public void open()
|
||||
{
|
||||
LOGGER.d(TAG, "Opening billing connection...");
|
||||
mState = State.CONNECTING;
|
||||
mBillingClient.startConnection(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
LOGGER.d(TAG, "Closing billing connection...");
|
||||
mBillingClient.endConnection();
|
||||
mState = State.CLOSED;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public State getState()
|
||||
|
@ -44,7 +53,7 @@ class PlayStoreBillingConnection implements BillingConnection,
|
|||
@Override
|
||||
public void onBillingSetupFinished(int responseCode)
|
||||
{
|
||||
LOGGER.i(TAG, "Setup finished. Response code: " + responseCode);
|
||||
LOGGER.i(TAG, "Connection established to billing client. Response code: " + responseCode);
|
||||
if (responseCode == BillingClient.BillingResponse.OK)
|
||||
{
|
||||
mState = State.CONNECTED;
|
||||
|
@ -59,6 +68,7 @@ class PlayStoreBillingConnection implements BillingConnection,
|
|||
@Override
|
||||
public void onBillingServiceDisconnected()
|
||||
{
|
||||
LOGGER.i(TAG, "Billing client is disconnected.");
|
||||
mState = State.DISCONNECTED;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,13 +54,14 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
LOGGER.i(TAG, "Creating play store billing client...");
|
||||
mBillingClient = BillingClient.newBuilder(mActivity).setListener(this).build();
|
||||
mConnection = new PlayStoreBillingConnection(mBillingClient, this);
|
||||
mConnection.connect();
|
||||
mConnection.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
// Coming soon.
|
||||
mConnection.close();
|
||||
mPendingRequests.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +81,7 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
task.run();
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
mConnection.connect();
|
||||
mConnection.open();
|
||||
break;
|
||||
case CLOSED:
|
||||
throw new IllegalStateException("Billing service connection already closed, " +
|
||||
|
@ -175,7 +176,7 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
|
||||
LOGGER.i(TAG, "Purchase details obtained: " + skuDetails);
|
||||
if (mCallback != null)
|
||||
mCallback.onPurchaseDetailsLoaded(Factory.createPurchaseDetailsFrom(skuDetails));
|
||||
mCallback.onPurchaseDetailsLoaded(BillingFactory.createPurchaseDetailsFrom(skuDetails));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue