Use new version of Checkout

This commit is contained in:
serso 2017-07-05 10:56:18 +02:00
parent db67e86fc2
commit cb9ece0108
7 changed files with 76 additions and 59 deletions

View File

@ -79,7 +79,7 @@ dependencies {
compile(project(':jscl')) { compile(project(':jscl')) {
exclude(module: 'xercesImpl') exclude(module: 'xercesImpl')
} }
compile 'org.solovyev.android:checkout:0.7.5@aar' compile 'org.solovyev.android:checkout:1.0.1'
compile 'org.solovyev.android:material:0.1.4@aar' compile 'org.solovyev.android:material:0.1.4@aar'
compile "com.google.android.gms:play-services-ads:${versions.gpsLib}" compile "com.google.android.gms:play-services-ads:${versions.gpsLib}"
compile "com.google.android.gms:play-services-base:${versions.gpsLib}" compile "com.google.android.gms:play-services-base:${versions.gpsLib}"
@ -109,8 +109,10 @@ dependencies {
androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5' androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3' androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
} // use version of jsr305 provided by Checkout
exclude group: 'com.google.code.findbugs', module: 'jsr305'
})}
apt { apt {
arguments { arguments {

View File

@ -9,28 +9,35 @@ import android.os.Looper;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import com.squareup.otto.GeneratedHandlerFinder; import com.squareup.otto.GeneratedHandlerFinder;
import dagger.Module;
import dagger.Provides;
import jscl.JsclMathEngine;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.wizard.CalculatorWizards; import org.solovyev.android.calculator.wizard.CalculatorWizards;
import org.solovyev.android.checkout.*; import org.solovyev.android.checkout.Billing;
import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.Inventory;
import org.solovyev.android.checkout.RobotmediaDatabase;
import org.solovyev.android.checkout.RobotmediaInventory;
import org.solovyev.android.plotter.Plot; import org.solovyev.android.plotter.Plot;
import org.solovyev.android.plotter.Plotter; import org.solovyev.android.plotter.Plotter;
import org.solovyev.android.wizard.Wizards; import org.solovyev.android.wizard.Wizards;
import java.io.File;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.io.File;
import java.util.Collections; import dagger.Module;
import java.util.concurrent.Executor; import dagger.Provides;
import java.util.concurrent.Executors; import jscl.JsclMathEngine;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@Module @Module
public class AppModule { public class AppModule {
@ -189,12 +196,6 @@ public class AppModule {
}); });
} }
@Singleton
@Provides
Products provideProducts() {
return Products.create().add(ProductTypes.IN_APP, Collections.singletonList("ad_free"));
}
@Singleton @Singleton
@Provides @Provides
Typeface provideTypeface() { Typeface provideTypeface() {

View File

@ -1,11 +1,12 @@
package org.solovyev.android.calculator.ads; package org.solovyev.android.calculator.ads;
import static org.solovyev.android.checkout.ProductTypes.IN_APP;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.view.View; import android.view.View;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.calculator.AdView; import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.checkout.CppCheckout; import org.solovyev.android.checkout.CppCheckout;
@ -15,7 +16,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.solovyev.android.checkout.ProductTypes.IN_APP; import butterknife.Bind;
import butterknife.ButterKnife;
public class AdUi { public class AdUi {
@ -47,13 +49,14 @@ public class AdUi {
if (adFree != null) { if (adFree != null) {
updateAdView(); updateAdView();
} else { } else {
checkout.loadInventory().whenLoaded(onMainThread(new Inventory.Listener() { checkout.loadInventory(Inventory.Request.create().loadAllPurchases(),
@Override onMainThread(new Inventory.Callback() {
public void onLoaded(@Nonnull Inventory.Products products) { @Override
adFree = products.get(IN_APP).isPurchased("ad_free"); public void onLoaded(@Nonnull Inventory.Products products) {
updateAdView(); adFree = products.get(IN_APP).isPurchased("ad_free");
} updateAdView();
})); }
}));
} }
} }
@ -70,18 +73,18 @@ public class AdUi {
} }
@Nonnull @Nonnull
private Inventory.Listener onMainThread(@Nonnull final Inventory.Listener listener) { private Inventory.Callback onMainThread(@Nonnull final Inventory.Callback callback) {
return new Inventory.Listener() { return new Inventory.Callback() {
@Override @Override
public void onLoaded(@Nonnull final Inventory.Products products) { public void onLoaded(@Nonnull final Inventory.Products products) {
if (handler.getLooper() == Looper.myLooper()) { if (handler.getLooper() == Looper.myLooper()) {
listener.onLoaded(products); callback.onLoaded(products);
return; return;
} }
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.onLoaded(products); callback.onLoaded(products);
} }
}); });
} }

View File

@ -8,6 +8,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.annotation.XmlRes; import android.support.annotation.XmlRes;
import android.util.SparseArray; import android.util.SparseArray;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent; import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.BaseActivity;
@ -16,7 +17,6 @@ import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.checkout.ActivityCheckout; import org.solovyev.android.checkout.ActivityCheckout;
import org.solovyev.android.checkout.Billing; import org.solovyev.android.checkout.Billing;
import org.solovyev.android.checkout.Checkout; import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.Products;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
@ -47,8 +47,6 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
@Inject @Inject
Billing billing; Billing billing;
@Inject @Inject
Products products;
@Inject
Languages languages; Languages languages;
public PreferencesActivity() { public PreferencesActivity() {
@ -87,7 +85,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
.commit(); .commit();
} }
checkout = Checkout.forActivity(this, billing, products); checkout = Checkout.forActivity(this, billing);
checkout.start(); checkout.start();
} }

View File

@ -1,5 +1,11 @@
package org.solovyev.android.calculator.preferences; package org.solovyev.android.calculator.preferences;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Engine.Preferences.angleUnitName;
import static org.solovyev.android.calculator.Engine.Preferences.numeralBaseName;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
import static org.solovyev.android.wizard.WizardUi.startWizard;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -11,13 +17,16 @@ import android.support.v4.app.FragmentActivity;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import jscl.AngleUnit;
import jscl.JsclMathEngine; import org.solovyev.android.calculator.ActivityLauncher;
import jscl.NumeralBase; import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.Preferences.Gui.Theme; import org.solovyev.android.calculator.Preferences.Gui.Theme;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.feedback.FeedbackReporter; import org.solovyev.android.calculator.feedback.FeedbackReporter;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
@ -29,17 +38,16 @@ import org.solovyev.android.prefs.StringPreference;
import org.solovyev.android.wizard.Wizards; import org.solovyev.android.wizard.Wizards;
import org.solovyev.common.text.CharacterMapper; import org.solovyev.common.text.CharacterMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.solovyev.android.calculator.App.cast; import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.Engine.Preferences.angleUnitName; import javax.annotation.Nullable;
import static org.solovyev.android.calculator.Engine.Preferences.numeralBaseName; import javax.inject.Inject;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
import static org.solovyev.android.wizard.WizardUi.startWizard; import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.NumeralBase;
public class PreferencesFragment extends org.solovyev.android.material.preferences.PreferencesFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public class PreferencesFragment extends org.solovyev.android.material.preferences.PreferencesFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -114,7 +122,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
prepareLanguagePreference(preference); prepareLanguagePreference(preference);
prepareThemePreference(preference); prepareThemePreference(preference);
getCheckout().whenReady(new Checkout.ListenerAdapter() { getCheckout().whenReady(new Checkout.EmptyListener() {
@Override @Override
public void onReady(@Nonnull BillingRequests requests) { public void onReady(@Nonnull BillingRequests requests) {
requests.isPurchased(ProductTypes.IN_APP, "ad_free", new RequestListener<Boolean>() { requests.isPurchased(ProductTypes.IN_APP, "ad_free", new RequestListener<Boolean>() {

View File

@ -22,6 +22,8 @@
package org.solovyev.android.calculator.preferences; package org.solovyev.android.calculator.preferences;
import static org.solovyev.android.calculator.App.cast;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -30,25 +32,28 @@ import android.support.annotation.NonNull;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.BaseDialogFragment; import org.solovyev.android.calculator.BaseDialogFragment;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.checkout.*; import org.solovyev.android.checkout.ActivityCheckout;
import org.solovyev.android.checkout.Billing;
import org.solovyev.android.checkout.BillingRequests;
import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.ProductTypes;
import org.solovyev.android.checkout.Purchase;
import org.solovyev.android.checkout.RequestListener;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
public class PurchaseDialogActivity extends AppCompatActivity implements RequestListener<Purchase> { public class PurchaseDialogActivity extends AppCompatActivity implements RequestListener<Purchase> {
@Inject @Inject
Billing billing; Billing billing;
@Inject @Inject
Products products;
@Inject
Ga ga; Ga ga;
ActivityCheckout checkout; ActivityCheckout checkout;
@ -62,7 +67,7 @@ public class PurchaseDialogActivity extends AppCompatActivity implements Request
App.showDialog(new PurchaseDialogFragment(), PurchaseDialogFragment.FRAGMENT_TAG, getSupportFragmentManager()); App.showDialog(new PurchaseDialogFragment(), PurchaseDialogFragment.FRAGMENT_TAG, getSupportFragmentManager());
} }
checkout = Checkout.forActivity(this, billing, products); checkout = Checkout.forActivity(this, billing);
checkout.start(); checkout.start();
checkout.createPurchaseFlow(this); checkout.createPurchaseFlow(this);
} }
@ -80,7 +85,7 @@ public class PurchaseDialogActivity extends AppCompatActivity implements Request
} }
private void purchase() { private void purchase() {
checkout.whenReady(new Checkout.ListenerAdapter() { checkout.whenReady(new Checkout.EmptyListener() {
@Override @Override
public void onReady(@Nonnull BillingRequests requests) { public void onReady(@Nonnull BillingRequests requests) {
requests.purchase(ProductTypes.IN_APP, "ad_free", null, checkout.getPurchaseFlow()); requests.purchase(ProductTypes.IN_APP, "ad_free", null, checkout.getPurchaseFlow());

View File

@ -13,8 +13,8 @@ public class CppCheckout extends Checkout {
private int started = 0; private int started = 0;
@Inject @Inject
public CppCheckout(@NonNull Billing billing, @NonNull Products products) { public CppCheckout(@NonNull Billing billing) {
super(null, billing, products); super(null, billing);
} }
@Override @Override