From 1090ba856fe7b54f7d02eac7dddcce2f93acfafb Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 6 Apr 2016 17:54:25 +0200 Subject: [PATCH] Add fragments to GA --- .../android/calculator/BaseDialogFragment.java | 17 +++++++++++++++-- .../org/solovyev/android/calculator/ga/Ga.java | 12 +++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseDialogFragment.java b/app/src/main/java/org/solovyev/android/calculator/BaseDialogFragment.java index 2e627b84..1d2049c4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseDialogFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseDialogFragment.java @@ -1,7 +1,5 @@ package org.solovyev.android.calculator; -import static org.solovyev.android.calculator.App.cast; - import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; @@ -17,13 +15,20 @@ import android.view.LayoutInflater; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; +import com.google.android.gms.analytics.HitBuilders; +import com.google.android.gms.analytics.Tracker; +import org.solovyev.android.calculator.ga.Ga; import javax.inject.Inject; +import static org.solovyev.android.calculator.App.cast; + public abstract class BaseDialogFragment extends DialogFragment implements View.OnClickListener, DialogInterface.OnClickListener { @Inject protected SharedPreferences preferences; + @Inject + Ga ga; @Nullable private Button positiveButton; @Nullable @@ -67,6 +72,14 @@ public abstract class BaseDialogFragment extends DialogFragment implements View. return dialog; } + @Override + public void onResume() { + super.onResume(); + final Tracker tracker = ga.getTracker(); + tracker.setScreenName(getClass().getSimpleName()); + tracker.send(new HitBuilders.ScreenViewBuilder().build()); + } + protected void onShowDialog(@NonNull AlertDialog dialog, boolean firstTime) { } diff --git a/app/src/main/java/org/solovyev/android/calculator/ga/Ga.java b/app/src/main/java/org/solovyev/android/calculator/ga/Ga.java index 6ed83605..2af7b76c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/ga/Ga.java +++ b/app/src/main/java/org/solovyev/android/calculator/ga/Ga.java @@ -46,6 +46,11 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe return analytics; } + @Nonnull + public Tracker getTracker() { + return tracker; + } + public void onButtonPressed(@Nullable String text) { if (TextUtils.isEmpty(text)) { return; @@ -72,13 +77,6 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences)); } - public void onBootStart() { - final HitBuilders.EventBuilder b = new HitBuilders.EventBuilder(); - b.setCategory("lifecycle"); - b.setAction("boot"); - tracker.send(b.build()); - } - public void onFloatingCalculatorOpened() { final HitBuilders.EventBuilder b = new HitBuilders.EventBuilder(); b.setCategory("lifecycle");