diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 7ba5962c4e..6d9a0dae34 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -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); diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java index e5a83715e9..0a041a6149 100644 --- a/android/src/com/mapswithme/maps/MwmApplication.java +++ b/android/src/com/mapswithme/maps/MwmApplication.java @@ -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; diff --git a/android/src/com/mapswithme/maps/purchase/BillingConnection.java b/android/src/com/mapswithme/maps/purchase/BillingConnection.java index 7cf744ff7c..0b9a198aca 100644 --- a/android/src/com/mapswithme/maps/purchase/BillingConnection.java +++ b/android/src/com/mapswithme/maps/purchase/BillingConnection.java @@ -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. diff --git a/android/src/com/mapswithme/maps/purchase/Factory.java b/android/src/com/mapswithme/maps/purchase/BillingFactory.java similarity index 97% rename from android/src/com/mapswithme/maps/purchase/Factory.java rename to android/src/com/mapswithme/maps/purchase/BillingFactory.java index 97acdfd62d..7b559e1b26 100644 --- a/android/src/com/mapswithme/maps/purchase/Factory.java +++ b/android/src/com/mapswithme/maps/purchase/BillingFactory.java @@ -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 { diff --git a/android/src/com/mapswithme/maps/purchase/PlayStoreBillingConnection.java b/android/src/com/mapswithme/maps/purchase/PlayStoreBillingConnection.java index 0e91393962..49be714d6a 100644 --- a/android/src/com/mapswithme/maps/purchase/PlayStoreBillingConnection.java +++ b/android/src/com/mapswithme/maps/purchase/PlayStoreBillingConnection.java @@ -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; } diff --git a/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java b/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java index 47dc11872c..ee4c04491c 100644 --- a/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java +++ b/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java @@ -54,13 +54,14 @@ public class PlayStoreBillingManager implements BillingManager