From 13fb8203eabf3a46d9cc246d378ed594b54e2093 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 26 Jan 2015 14:04:29 +0100 Subject: [PATCH] Fix for incorrect product id + GA now tracks more activities --- android-app/src/main/AndroidManifest.xml | 2 +- .../android/calculator/ActivityUi.java | 8 +++++ .../org/solovyev/android/calculator/App.java | 36 +++++++++++++++++++ .../calculator/CalculatorApplication.java | 26 +------------- .../android/calculator/FragmentUi.java | 10 +++--- .../preferences/BasePreferencesActivity.java | 24 ++++++++++--- .../preferences/PreferencesActivity.java | 2 +- ...ivity.java => PurchaseDialogActivity.java} | 23 ++++++++---- .../calculator/wizard/FinalWizardStep.java | 4 +-- 9 files changed, 89 insertions(+), 46 deletions(-) rename android-app/src/main/java/org/solovyev/android/calculator/preferences/{CalculatorPurchaseDialogActivity.java => PurchaseDialogActivity.java} (87%) diff --git a/android-app/src/main/AndroidManifest.xml b/android-app/src/main/AndroidManifest.xml index 6935051a..e5581a6d 100644 --- a/android-app/src/main/AndroidManifest.xml +++ b/android-app/src/main/AndroidManifest.xml @@ -71,7 +71,7 @@ - + diff --git a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java index e27e2f45..788666d8 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java @@ -328,10 +328,18 @@ public class ActivityUi extends BaseUi { } public void onStop(@Nonnull Activity activity) { + reportActivityStop(activity); + } + + public static void reportActivityStop(@Nonnull Activity activity) { App.getGa().getAnalytics().reportActivityStop(activity); } public void onStart(@Nonnull Activity activity) { + reportActivityStart(activity); + } + + public static void reportActivityStart(@Nonnull Activity activity) { App.getGa().getAnalytics().reportActivityStart(activity); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/App.java b/android-app/src/main/java/org/solovyev/android/calculator/App.java index 5b51d7a7..6083570b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/App.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/App.java @@ -27,6 +27,7 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import org.solovyev.android.UiThreadExecutor; import org.solovyev.android.calculator.ga.Ga; +import org.solovyev.android.checkout.*; import org.solovyev.common.listeners.JEvent; import org.solovyev.common.listeners.JEventListener; import org.solovyev.common.listeners.JEventListeners; @@ -35,6 +36,8 @@ import org.solovyev.common.threads.DelayedExecutor; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.concurrent.Executor; /** * User: serso @@ -81,6 +84,12 @@ public final class App { @Nonnull private static volatile Ga ga; + @Nonnull + private static volatile Billing billing; + + @Nonnull + private static final Products products = Products.create().add(ProductTypes.IN_APP, Arrays.asList("ad_free")); + private App() { throw new AssertionError(); } @@ -111,6 +120,23 @@ public final class App { App.uiThreadExecutor = uiThreadExecutor; App.eventBus = eventBus; App.ga = new Ga(application, preferences, eventBus); + App.billing = new Billing(application, new Billing.DefaultConfiguration() { + @Nonnull + @Override + public String getPublicKey() { + return CalculatorSecurity.getPK(); + } + + @Nullable + @Override + public Inventory getFallbackInventory(@Nonnull Checkout checkout, @Nonnull Executor onLoadExecutor) { + if (RobotmediaDatabase.exists(billing.getContext())) { + return new RobotmediaInventory(checkout, onLoadExecutor); + } else { + return null; + } + } + }); if (serviceLocator != null) { App.locator = serviceLocator; } else { @@ -178,4 +204,14 @@ public final class App { public static Ga getGa() { return ga; } + + @Nonnull + public static Billing getBilling() { + return billing; + } + + @Nonnull + public static Products getProducts() { + return products; + } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 55380525..89a362aa 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -105,25 +105,6 @@ public class CalculatorApplication extends android.app.Application implements Sh @Nonnull private Typeface typeFace; - @Nonnull - private final Billing billing = new Billing(this, new Billing.DefaultConfiguration() { - @Nonnull - @Override - public String getPublicKey() { - return CalculatorSecurity.getPK(); - } - - @Nullable - @Override - public Inventory getFallbackInventory(@Nonnull Checkout checkout, @Nonnull Executor onLoadExecutor) { - if (RobotmediaDatabase.exists(billing.getContext())) { - return new RobotmediaInventory(checkout, onLoadExecutor); - } else { - return null; - } - } - }); - /* ********************************************************************** * @@ -200,7 +181,7 @@ public class CalculatorApplication extends android.app.Application implements Sh Locator.getInstance().getCalculator().init(); - billing.connect(); + App.getBilling().connect(); new Thread(new Runnable() { @Override @@ -265,11 +246,6 @@ public class CalculatorApplication extends android.app.Application implements Sh return typeFace; } - @Nonnull - public Billing getBilling() { - return billing; - } - /* ********************************************************************** * diff --git a/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java b/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java index 8ad2772b..c2781e40 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/FragmentUi.java @@ -28,15 +28,15 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import org.solovyev.android.checkout.*; +import org.solovyev.android.checkout.ActivityCheckout; +import org.solovyev.android.checkout.Checkout; +import org.solovyev.android.checkout.Inventory; +import org.solovyev.android.checkout.ProductTypes; import javax.annotation.Nonnull; import javax.annotation.Nullable; - import java.util.Locale; -import static java.util.Arrays.asList; - /** * User: serso * Date: 9/26/12 @@ -91,7 +91,7 @@ public class FragmentUi extends BaseUi { public void onCreate(@Nonnull Fragment fragment) { final FragmentActivity activity = fragment.getActivity(); super.onCreate(activity); - checkout = Checkout.forActivity(activity, CalculatorApplication.getInstance().getBilling(), Products.create().add(ProductTypes.IN_APP, asList("ad_free"))); + checkout = Checkout.forActivity(activity, App.getBilling(), App.getProducts()); if (listenersOnCreate) { if (fragment instanceof CalculatorEventListener) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java index c1fafefa..fdad814e 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java @@ -4,18 +4,20 @@ import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import com.actionbarsherlock.app.SherlockPreferenceActivity; +import org.solovyev.android.calculator.ActivityUi; import org.solovyev.android.calculator.AdView; -import org.solovyev.android.calculator.CalculatorApplication; +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.R; -import org.solovyev.android.checkout.*; +import org.solovyev.android.checkout.ActivityCheckout; +import org.solovyev.android.checkout.Checkout; +import org.solovyev.android.checkout.Inventory; +import org.solovyev.android.checkout.ProductTypes; import javax.annotation.Nonnull; -import static java.util.Arrays.asList; - public abstract class BasePreferencesActivity extends SherlockPreferenceActivity { - private final ActivityCheckout checkout = Checkout.forActivity(this, CalculatorApplication.getInstance().getBilling(), Products.create().add(ProductTypes.IN_APP, asList("ad_free"))); + private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts()); private Inventory inventory; private AdView adView; @@ -73,6 +75,18 @@ public abstract class BasePreferencesActivity extends SherlockPreferenceActivity inventory.whenLoaded(new InventoryListener()); } + @Override + protected void onStart() { + super.onStart(); + ActivityUi.reportActivityStart(this); + } + + @Override + protected void onStop() { + ActivityUi.reportActivityStop(this); + super.onStop(); + } + @Override protected void onPause() { if (adView != null) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java index 6e52e7c2..4cf356f4 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java @@ -91,7 +91,7 @@ public class PreferencesActivity extends BasePreferencesActivity implements Shar adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(getApplicationContext(), CalculatorPurchaseDialogActivity.class)); + startActivity(new Intent(getApplicationContext(), PurchaseDialogActivity.class)); return true; } }); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPurchaseDialogActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java similarity index 87% rename from android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPurchaseDialogActivity.java rename to android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java index 5a9b204f..e2f2e946 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPurchaseDialogActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java @@ -29,10 +29,7 @@ import android.text.method.ScrollingMovementMethod; import android.view.View; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragmentActivity; -import org.solovyev.android.calculator.CalculatorApplication; -import org.solovyev.android.calculator.CalculatorFragment; -import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.*; import org.solovyev.android.checkout.*; import org.solovyev.android.fragments.FragmentUtils; @@ -44,10 +41,10 @@ import javax.annotation.Nullable; * Date: 1/20/13 * Time: 2:36 PM */ -public class CalculatorPurchaseDialogActivity extends SherlockFragmentActivity { +public class PurchaseDialogActivity extends SherlockFragmentActivity { @Nonnull - private final ActivityCheckout checkout = Checkout.forActivity(this, CalculatorApplication.getInstance().getBilling(), Products.create().add("ad_free")); + private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts()); @Nonnull private final RequestListener purchaseListener = new RequestListener() { @@ -90,13 +87,25 @@ public class CalculatorPurchaseDialogActivity extends SherlockFragmentActivity { public void onClick(View v) { final Activity activity = getActivity(); if (activity != null) { - ((CalculatorPurchaseDialogActivity) activity).purchase(); + ((PurchaseDialogActivity) activity).purchase(); } } }); } } + @Override + protected void onStart() { + super.onStart(); + ActivityUi.reportActivityStart(this); + } + + @Override + protected void onStop() { + ActivityUi.reportActivityStop(this); + super.onStop(); + } + private void purchase() { checkout.whenReady(new Checkout.ListenerAdapter() { @Override diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/FinalWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/FinalWizardStep.java index 700212a5..cff8bf85 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/FinalWizardStep.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/FinalWizardStep.java @@ -9,7 +9,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.preferences.CalculatorPurchaseDialogActivity; +import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import static android.content.Intent.ACTION_VIEW; @@ -35,7 +35,7 @@ public class FinalWizardStep extends Fragment { donateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - startActivity(new Intent(getActivity(), CalculatorPurchaseDialogActivity.class)); + startActivity(new Intent(getActivity(), PurchaseDialogActivity.class)); } });