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')) {
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 "com.google.android.gms:play-services-ads:${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:rules:0.5'
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 {
arguments {

View File

@ -9,28 +9,35 @@ import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.Log;
import com.squareup.otto.Bus;
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.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.Plotter;
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.Nullable;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.File;
import java.util.Collections;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import dagger.Module;
import dagger.Provides;
import jscl.JsclMathEngine;
@Module
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
@Provides
Typeface provideTypeface() {

View File

@ -1,11 +1,12 @@
package org.solovyev.android.calculator.ads;
import static org.solovyev.android.checkout.ProductTypes.IN_APP;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.view.View;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.R;
import org.solovyev.android.checkout.CppCheckout;
@ -15,7 +16,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.solovyev.android.checkout.ProductTypes.IN_APP;
import butterknife.Bind;
import butterknife.ButterKnife;
public class AdUi {
@ -47,7 +49,8 @@ public class AdUi {
if (adFree != null) {
updateAdView();
} else {
checkout.loadInventory().whenLoaded(onMainThread(new Inventory.Listener() {
checkout.loadInventory(Inventory.Request.create().loadAllPurchases(),
onMainThread(new Inventory.Callback() {
@Override
public void onLoaded(@Nonnull Inventory.Products products) {
adFree = products.get(IN_APP).isPurchased("ad_free");
@ -70,18 +73,18 @@ public class AdUi {
}
@Nonnull
private Inventory.Listener onMainThread(@Nonnull final Inventory.Listener listener) {
return new Inventory.Listener() {
private Inventory.Callback onMainThread(@Nonnull final Inventory.Callback callback) {
return new Inventory.Callback() {
@Override
public void onLoaded(@Nonnull final Inventory.Products products) {
if (handler.getLooper() == Looper.myLooper()) {
listener.onLoaded(products);
callback.onLoaded(products);
return;
}
handler.post(new Runnable() {
@Override
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.XmlRes;
import android.util.SparseArray;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent;
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.Billing;
import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.Products;
import javax.annotation.Nonnull;
import javax.inject.Inject;
@ -47,8 +47,6 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
@Inject
Billing billing;
@Inject
Products products;
@Inject
Languages languages;
public PreferencesActivity() {
@ -87,7 +85,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
.commit();
}
checkout = Checkout.forActivity(this, billing, products);
checkout = Checkout.forActivity(this, billing);
checkout.start();
}

View File

@ -1,5 +1,11 @@
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.Intent;
import android.content.SharedPreferences;
@ -11,13 +17,16 @@ import android.support.v4.app.FragmentActivity;
import android.util.SparseArray;
import android.view.View;
import android.widget.ListView;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.NumeralBase;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.ActivityLauncher;
import org.solovyev.android.calculator.AdView;
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.R;
import org.solovyev.android.calculator.feedback.FeedbackReporter;
import org.solovyev.android.calculator.language.Language;
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.common.text.CharacterMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Arrays;
import java.util.List;
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 javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.NumeralBase;
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);
prepareThemePreference(preference);
getCheckout().whenReady(new Checkout.ListenerAdapter() {
getCheckout().whenReady(new Checkout.EmptyListener() {
@Override
public void onReady(@Nonnull BillingRequests requests) {
requests.isPurchased(ProductTypes.IN_APP, "ad_free", new RequestListener<Boolean>() {

View File

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