Fix for incorrect product id + GA now tracks more activities

This commit is contained in:
serso 2015-01-26 14:04:29 +01:00
parent 13b2558620
commit 13fb8203ea
9 changed files with 89 additions and 46 deletions

View File

@ -71,7 +71,7 @@
<activity android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/cpp_purchase_title" android:name=".preferences.CalculatorPurchaseDialogActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/cpp_purchase_title" android:name=".preferences.PurchaseDialogActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:name=".CalculatorDialogActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
/*
**********************************************************************
*

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}
});

View File

@ -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<Purchase> purchaseListener = new RequestListener<Purchase>() {
@ -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

View File

@ -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));
}
});