From d570181115b0901ed6e71d74392c1e43abe09d79 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Sun, 4 Sep 2016 17:20:15 +0100 Subject: [PATCH 01/12] Add Analytics tracking on Donate screen --- .../addevent/AddBirthdayActivity.java | 4 +- .../analytics/AnalyticsEvent.java | 18 +++++- .../specialdates/analytics/Screen.java | 3 +- .../settings/DailyReminderFragment.java | 2 +- .../support/SupportDonateDialog.java | 55 +++++++++++-------- .../ui/activity/MainActivity.java | 1 + mobile/src/main/res/values/strings.xml | 2 +- 7 files changed, 53 insertions(+), 32 deletions(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java index 2e1239e3..2fd86cf2 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java @@ -108,11 +108,11 @@ private void trackEventCreation() { } private AnalyticsEvent birthdayCreationSuccess() { - return new AnalyticsEvent(AnalyticsEvent.Events.ADD_BIRTHDAY).withData("success", "true"); + return new AnalyticsEvent(AnalyticsEvent.Events.ADD_BIRTHDAY).asSuccess(true); } private AnalyticsEvent birthdayCreationFailed() { - return new AnalyticsEvent(AnalyticsEvent.Events.ADD_BIRTHDAY).withData("success", "false"); + return new AnalyticsEvent(AnalyticsEvent.Events.ADD_BIRTHDAY).asSuccess(false); } private final BirthdayLabelView.OnEditListener onBirthdayLabelClicked = new BirthdayLabelView.OnEditListener() { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java index e922e786..af4c8b3c 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java @@ -6,6 +6,7 @@ public class AnalyticsEvent { private final Bundle bundle = new Bundle(); private final Events eventName; + private boolean enabled; public String getName() { return eventName.name; @@ -20,20 +21,31 @@ public AnalyticsEvent(Events eventName) { } public AnalyticsEvent withData(String key, String value) { - this.bundle.remove(key); this.bundle.putString(key, value); return this; } public AnalyticsEvent withData(String key, boolean value) { - this.bundle.remove(key); this.bundle.putBoolean(key, value); return this; } + public AnalyticsEvent asSuccess(boolean value) { + return withData("success", value); + } + + public AnalyticsEvent reason(String reason) { + return withData("reason", reason); + } + + public AnalyticsEvent setEnabled(boolean enabled) { + return withData("enabled", enabled); + } + public enum Events { ADD_BIRTHDAY("add birthday"), - DAILY_REMINDER("daily reminder"); + DAILY_REMINDER("daily reminder"), + DONATION("donation"); private final String name; diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java index 4c24144f..fe25de44 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java @@ -7,7 +7,8 @@ public enum Screen { ADD_BIRTHDAY("add birthday"), SEARCH("search"), SETTINGS("settings"), - DATE_DETAILS("date details"); + DATE_DETAILS("date details"), + DONATE("donate"); private final Bundle data; diff --git a/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java index 0bd8270e..a17d07ac 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java @@ -48,7 +48,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { boolean isChecked = (boolean) newValue; MainPreferenceActivity.setDailyReminder(context, isChecked); AnalyticsEvent event = new AnalyticsEvent(AnalyticsEvent.Events.DAILY_REMINDER) - .withData("enabled", isChecked); + .setEnabled(isChecked); analytics.track(event); if (isChecked) { DailyReminderIntentService.rescheduleAlarm(context); diff --git a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java index 1d5bcd48..75a37532 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java @@ -10,7 +10,10 @@ import android.widget.Toast; import com.alexstyl.specialdates.BuildConfig; +import com.alexstyl.specialdates.ErrorTracker; import com.alexstyl.specialdates.R; +import com.alexstyl.specialdates.analytics.Analytics; +import com.alexstyl.specialdates.analytics.AnalyticsEvent; import com.alexstyl.specialdates.billing.util.IabHelper; import com.alexstyl.specialdates.billing.util.IabResult; import com.alexstyl.specialdates.billing.util.Inventory; @@ -29,7 +32,7 @@ public class SupportDonateDialog extends MementoActivity implements View.OnClick private static final String TAG = "Donate"; - private IabHelper mHelper; + private IabHelper iabHelper; static final String ITEM_TEST = "android.test.purchased"; static final String ITEM_DONATE_1 = "com.alexstyl.specialdates.support_1"; @@ -57,7 +60,7 @@ public void onQueryInventoryFinished(IabResult result, Purchase donationPurchase = inventory.getPurchase(token); if (donationPurchase != null /*&& verifyDeveloperPayload(gasPurchase)*/) { android.util.Log.d(TAG, "We have token. Consuming it."); - mHelper.consumeAsync(inventory.getPurchase(token), null); + iabHelper.consumeAsync(inventory.getPurchase(token), null); } } // IAB is fully set up. @@ -70,7 +73,7 @@ public void onQueryInventoryFinished(IabResult result, public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.donate); - + analytics = Analytics.get(this); mTokens = new HashMap<>(); if (BuildConfig.DEBUG) { mTokens.put("1", ITEM_TEST); @@ -103,16 +106,18 @@ public void onCreate(Bundle savedInstanceState) { if (isBillingAvailable(this)) { initialiseBilling(); } else { - Log.e(TAG, "Billing is not available"); + ErrorTracker.track(new RuntimeException("Billing is not available")); finish(); } } + private Analytics analytics; + private IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase purchase) { // if we were disposed of in the meantime, quit. - if (mHelper == null) { + if (iabHelper == null) { return; } @@ -122,7 +127,7 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { } if (!result.isSuccess()) { - Log.e(TAG, "Error! " + result.getMessage()); + ErrorTracker.track(new RuntimeException("onIabPurchaseFinished error: " + result.getMessage())); return; } @@ -130,31 +135,38 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { Log.d(TAG, "Bought " + purchase.getSku()); // consume it so that the user can buy a donation again - mHelper.consumeAsync(purchase, null); + iabHelper.consumeAsync(purchase, null); Toast.makeText(SupportDonateDialog.this, R.string.thanks_for_support, Toast.LENGTH_SHORT).show(); + + analytics.track(successfulDonationEvent()); finish(); Log.d(TAG, "Purchase successful!"); } + }; + private AnalyticsEvent successfulDonationEvent() { + return new AnalyticsEvent(AnalyticsEvent.Events.DONATION).asSuccess(true); + } + private void initialiseBilling() { - if (mHelper != null) { + if (iabHelper != null) { return; } - mHelper = new IabHelper(this, BuildConfig.API_KEY_VENDING); + iabHelper = new IabHelper(this, BuildConfig.API_KEY_VENDING); - mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { + iabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { - if (mHelper == null) { + if (iabHelper == null) { return; } if (!result.isSuccess()) { + ErrorTracker.track(new RuntimeException("Problem setting up in-app billing: " + result.getMessage())); // Oh noes, there was a problem. - Log.e(TAG, "Problem setting up in-app billing: " + result.getMessage()); return; } - mHelper.queryInventoryAsync(mGotInventoryListener); + iabHelper.queryInventoryAsync(mGotInventoryListener); } }); @@ -175,24 +187,19 @@ public void onClick(View v) { } else { String index = String.valueOf(v.getTag()); token = mTokens.get(index); -// if (token == null) { -// Log.e(TAG, "got index " + index); -// return; -// } } if (mBillingServiceReady) { - mHelper.launchPurchaseFlow(this, token, REQUEST_CODE_TEST, mPurchaseFinishedListener); + iabHelper.launchPurchaseFlow(this, token, REQUEST_CODE_TEST, mPurchaseFinishedListener); } else { - Log.w(TAG, "Tried to buy but billing was not ready"); + ErrorTracker.track(new RuntimeException("Tried to buy but billing was not ready")); } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - - if (mHelper == null || !mHelper.handleActivityResult(requestCode, resultCode, data)) { + if (iabHelper == null || !iabHelper.handleActivityResult(requestCode, resultCode, data)) { super.onActivityResult(requestCode, resultCode, data); } } @@ -200,9 +207,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { @Override public void onDestroy() { super.onDestroy(); - if (mHelper != null) { - mHelper.dispose(); - mHelper = null; + if (iabHelper != null) { + iabHelper.dispose(); + iabHelper = null; } } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java index 9166efca..843cdbd4 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java @@ -101,6 +101,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void openDonateDialog() { + analytics.trackScreen(Screen.DONATE); SupportDonateDialog.displayDialog(this); } diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 5109e98c..50e5203d 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -2,7 +2,7 @@ - @string/app_name + Memento Namedays Today Tomorrow Birthday From b84250235e11f0dacdd8ba6e7057db4d056c48cf Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Sun, 4 Sep 2016 17:25:33 +0100 Subject: [PATCH 02/12] Include version name on api --- mobile/build.gradle | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mobile/build.gradle b/mobile/build.gradle index fe63002c..0410268a 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -15,6 +15,16 @@ android { compileSdkVersion 23 buildToolsVersion '23.0.2' + + applicationVariants.all { variant -> + variant.outputs.each { output -> + output.outputFile = new File( + output.outputFile.parent, + output.outputFile.name.replace(".apk", "-${variant.versionName}.apk")) + } + } + + defaultConfig { applicationId 'com.alexstyl.specialdates' minSdkVersion 16 @@ -25,6 +35,7 @@ android { manifestPlaceholders = [crashlyticsApiKey: crashlyticsKey] buildConfigField 'String', 'API_KEY_VENDING', '\"' + androidVendingKey + "\"" } + buildTypes { release { minifyEnabled true From 4d3ca5a224e137219930881de2ab62b03001c4e0 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Sun, 4 Sep 2016 17:26:18 +0100 Subject: [PATCH 03/12] Remove secrets from gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 06580c51..e5c57e83 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ captures/ # Mac .DS_Store +# secrets +secret.gradle +/mobile/google-services.json From f312b99264e45a1315a6352ee6046256a7c48d4d Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Sun, 4 Sep 2016 19:52:39 +0100 Subject: [PATCH 04/12] Create birthday with valid years --- .../addevent/ui/BirthdayDatePicker.java | 4 ++-- .../specialdates/contact/Birthday.java | 22 ++++++++++++++----- .../contact/DeviceContactFactory.java | 2 +- .../events/BirthdayDatabaseRefresher.java | 2 +- .../specialdates/contact/BirthdayTest.java | 21 ++++++++++++++++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/addevent/ui/BirthdayDatePicker.java b/mobile/src/main/java/com/alexstyl/specialdates/addevent/ui/BirthdayDatePicker.java index 9ae0ceb6..7c5ba697 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/addevent/ui/BirthdayDatePicker.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/addevent/ui/BirthdayDatePicker.java @@ -125,9 +125,9 @@ public Birthday getDisplayingBirthday() { int month = getMonth(); if (isDisplayingYear()) { int year = getYear(); - return new Birthday(dayOfMonth, month, year); + return Birthday.on(dayOfMonth, month, year); } else { - return new Birthday(dayOfMonth, month); + return Birthday.on(dayOfMonth, month); } } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/contact/Birthday.java b/mobile/src/main/java/com/alexstyl/specialdates/contact/Birthday.java index bc2eb543..e5f47525 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/contact/Birthday.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/contact/Birthday.java @@ -2,6 +2,7 @@ import com.alexstyl.specialdates.Optional; import com.alexstyl.specialdates.date.AnnualEvent; +import com.alexstyl.specialdates.date.Date; import com.alexstyl.specialdates.date.DateDisplayStringCreator; import com.alexstyl.specialdates.date.DayDate; @@ -11,16 +12,27 @@ public class Birthday implements ShortDate { private final Optional yearOfBirth; public static Birthday on(DayDate date) { - return new Birthday(date.getDayOfMonth(), date.getMonth(), date.getYear()); + if (date.getYear() == Date.NO_YEAR) { + return new Birthday(date.getDayOfMonth(), date.getMonth(), Optional.absent()); + } else { + return new Birthday(date.getDayOfMonth(), date.getMonth(), new Optional<>(date.getYear())); + } + } + + public static Birthday on(int dayOfMonth, int month) { + return new Birthday(dayOfMonth, month, Optional.absent()); } - public Birthday(int day, int month) { - this(day, month, DayDate.NO_YEAR); + public static Birthday on(int dayOfMonth, int month, int year) { + if (year <= Date.NO_YEAR) { + throw new IllegalArgumentException("A birthday cannot have negative year"); + } + return new Birthday(dayOfMonth, month, new Optional<>(year)); } - public Birthday(int dayOfMonth, int month, int year) { + private Birthday(int dayOfMonth, int month, Optional year) { this.date = new AnnualEvent(dayOfMonth, month); - this.yearOfBirth = new Optional<>(year); + this.yearOfBirth = year; } public int getDayOfMonth() { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/contact/DeviceContactFactory.java b/mobile/src/main/java/com/alexstyl/specialdates/contact/DeviceContactFactory.java index dbc6c0ae..13cf1c20 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/contact/DeviceContactFactory.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/contact/DeviceContactFactory.java @@ -75,7 +75,7 @@ private Birthday getBirthdayFrom(Cursor cursor) { String birthday = cursor.getString(ContactsQuery.BIRTHDAY); try { DayDate parse = dateParser.parse(birthday); - return new Birthday(parse.getDayOfMonth(), parse.getMonth(), parse.getYear()); + return Birthday.on(parse); } catch (DateParseException e) { ErrorTracker.track(e); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/events/BirthdayDatabaseRefresher.java b/mobile/src/main/java/com/alexstyl/specialdates/events/BirthdayDatabaseRefresher.java index bfcfc0de..1d1f0ceb 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/events/BirthdayDatabaseRefresher.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/events/BirthdayDatabaseRefresher.java @@ -95,7 +95,7 @@ private DisplayName getDisplayNameFrom(Cursor cursor) { private Birthday birthdayOn(String bday) throws DateParseException { DayDate parsedDate = dateParser.parse(bday); - return new Birthday(parsedDate.getDayOfMonth(), parsedDate.getMonth(), parsedDate.getYear()); + return Birthday.on(parsedDate); } private boolean isInvalid(Cursor cursor) { diff --git a/mobile/src/test/java/com/alexstyl/specialdates/contact/BirthdayTest.java b/mobile/src/test/java/com/alexstyl/specialdates/contact/BirthdayTest.java index c44eca5b..46c1abdf 100644 --- a/mobile/src/test/java/com/alexstyl/specialdates/contact/BirthdayTest.java +++ b/mobile/src/test/java/com/alexstyl/specialdates/contact/BirthdayTest.java @@ -11,13 +11,30 @@ public class BirthdayTest { @Test public void shortNameWithYear() { - Birthday aBirthday = new Birthday(1, 2, 1990); + Birthday aBirthday = Birthday.on(1, 2, 1990); assertThat(aBirthday.toShortDate()).isEqualTo("--02-01"); } @Test public void shortNameWithNoYear() { - Birthday aBirthday = new Birthday(1, 2); + Birthday aBirthday = Birthday.on(1, 2); assertThat(aBirthday.toShortDate()).isEqualTo("--02-01"); } + + @Test + public void whenNoYearIsPresent_ItDoesNotIncludeYear() { + Birthday birthday = Birthday.on(1, 2); + assertThat(birthday.includesYear()).isFalse(); + } + + @Test + public void whenYearIsPresent_ItDoesIncludeYear() { + Birthday birthday = Birthday.on(1, 2, 1990); + assertThat(birthday.includesYear()).isTrue(); + } + + @Test(expected = IllegalArgumentException.class) + public void whenInvalidYearInPassed_thenExceptionIsThrown() { + Birthday.on(1, 2, -1); + } } From a61949f0b65d5dbbb3ba50de978db36fdf2e5c36 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Sun, 4 Sep 2016 20:06:48 +0100 Subject: [PATCH 05/12] Version increment --- mobile/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mobile/build.gradle b/mobile/build.gradle index fb64dc0d..74abfabe 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -29,8 +29,8 @@ android { applicationId 'com.alexstyl.specialdates' minSdkVersion 16 targetSdkVersion 22 - versionCode 56 - versionName '3.7' + versionCode 57 + versionName '3.8' manifestPlaceholders = [crashlyticsApiKey: crashlyticsKey] buildConfigField 'String', 'API_KEY_VENDING', '\"' + androidVendingKey + "\"" From 22870ef320ee95b904386de7b56efc2628306260 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Mon, 5 Sep 2016 23:33:02 +0100 Subject: [PATCH 06/12] Release resources onUnregisterObserver instead of onAbandon --- .../alexstyl/specialdates/datedetails/DateDetailsLoader.java | 4 ++-- .../java/com/alexstyl/specialdates/search/SearchLoader.java | 4 ++-- .../alexstyl/specialdates/upcoming/UpcomingEventsLoader.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsLoader.java b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsLoader.java index 5ce0b381..4812f952 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsLoader.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsLoader.java @@ -55,8 +55,8 @@ public void onContactsUpdated() { } @Override - protected void onAbandon() { - super.onAbandon(); + protected void onUnregisterObserver() { + super.onUnregisterObserver(); contactsObserver.unregister(); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/search/SearchLoader.java b/mobile/src/main/java/com/alexstyl/specialdates/search/SearchLoader.java index 44c82dd4..8663601f 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/search/SearchLoader.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/search/SearchLoader.java @@ -33,8 +33,8 @@ public void onContactsUpdated() { } @Override - protected void onAbandon() { - super.onAbandon(); + protected void onUnregisterObserver() { + super.onUnregisterObserver(); observer.unregister(); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsLoader.java b/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsLoader.java index 753c7d1b..d1ec68bc 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsLoader.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsLoader.java @@ -46,8 +46,8 @@ public UpcomingEventsLoader(Context context, PeopleEventsProvider peopleEventsPr } @Override - protected void onAbandon() { - super.onAbandon(); + protected void onUnregisterObserver() { + super.onUnregisterObserver(); contactsObserver.unregister(); } From 64795e81f78c10e732ead8ccc6165b69ce771588 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Tue, 6 Sep 2016 21:08:56 +0100 Subject: [PATCH 07/12] Remove TODO --- .../specialdates/widgetprovider/TodayWidgetProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/widgetprovider/TodayWidgetProvider.java b/mobile/src/main/java/com/alexstyl/specialdates/widgetprovider/TodayWidgetProvider.java index b24dcedc..2c819462 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/widgetprovider/TodayWidgetProvider.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/widgetprovider/TodayWidgetProvider.java @@ -67,7 +67,7 @@ private void updateForDate(Context context, final AppWidgetManager appWidgetMana UpcomingWidgetPreferences preferences = new UpcomingWidgetPreferences(context); WidgetVariant selectedVariant = preferences.getSelectedVariant(); TransparencyColorCalculator transparencyColorCalculator = new TransparencyColorCalculator(); - float opacity = preferences.getOppacityLevel(); //TODO + float opacity = preferences.getOppacityLevel(); int selectedTextColor = context.getResources().getColor(selectedVariant.getTextColor()); WidgetColorCalculator calculator = new WidgetColorCalculator(selectedTextColor); From c64fd57b78db2d6196dec6f6661d44cfe971c876 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Tue, 6 Sep 2016 22:30:35 +0100 Subject: [PATCH 08/12] Update Analytics API --- .../specialdates/debug/DebugActivity.java | 5 ++ .../com/alexstyl/specialdates/Navigator.java | 5 ++ .../addevent/AddBirthdayActivity.java | 22 ++++--- .../specialdates/analytics/Action.java | 19 ++++++ .../specialdates/analytics/Analytics.java | 30 +-------- .../analytics/AnalyticsAction.java | 33 ++++++++++ .../analytics/AnalyticsEvent.java | 65 ------------------- .../specialdates/analytics/Firebase.java | 46 +++++++++++++ .../specialdates/analytics/Screen.java | 19 +++--- .../contact/actions/CallAction.java | 5 ++ .../contact/actions/EMailAction.java | 5 ++ .../contact/actions/IntentAction.java | 2 + .../contact/actions/SMSAction.java | 5 ++ .../datedetails/DateDetailsActivity.java | 3 - .../datedetails/DateDetailsFragment.java | 13 +++- .../specialdates/facebook/FacebookUtils.java | 44 ------------- .../specialdates/search/SearchActivity.java | 5 -- .../settings/DailyReminderFragment.java | 11 ++-- .../settings/MainPreferenceActivity.java | 4 -- .../support/SupportDonateDialog.java | 42 ++++++------ .../ui/activity/MainActivity.java | 5 +- .../upcoming/UpcomingEventsFragment.java | 20 ++++-- .../com/alexstyl/specialdates/util/Utils.java | 5 ++ ...EventsTest.java => ContactActionTest.java} | 2 +- 24 files changed, 215 insertions(+), 200 deletions(-) create mode 100644 mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java create mode 100644 mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java delete mode 100644 mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java create mode 100644 mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java delete mode 100644 mobile/src/main/java/com/alexstyl/specialdates/facebook/FacebookUtils.java rename mobile/src/test/java/com/alexstyl/specialdates/events/{ContactEventsTest.java => ContactActionTest.java} (98%) diff --git a/mobile/src/debug/java/com/alexstyl/specialdates/debug/DebugActivity.java b/mobile/src/debug/java/com/alexstyl/specialdates/debug/DebugActivity.java index e881d228..2e1ff275 100644 --- a/mobile/src/debug/java/com/alexstyl/specialdates/debug/DebugActivity.java +++ b/mobile/src/debug/java/com/alexstyl/specialdates/debug/DebugActivity.java @@ -85,6 +85,11 @@ public void onStartAction(Context context) throws ActivityNotFoundException { startActivity(intent); } + + @Override + public String getName() { + return "date debug"; + } }; Utils.openIntentSafely(getActivity(), i); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/Navigator.java b/mobile/src/main/java/com/alexstyl/specialdates/Navigator.java index 09f71865..848626ec 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/Navigator.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/Navigator.java @@ -76,6 +76,11 @@ public void onStartAction(Context context) throws ActivityNotFoundException { Intent intent = Utils.getSupportEmailIntent(context); context.startActivity(intent); } + + @Override + public String getName() { + return "email support"; + } }); } } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java index 2fd86cf2..479b4776 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java @@ -8,8 +8,10 @@ import com.alexstyl.specialdates.R; import com.alexstyl.specialdates.addevent.ui.ContactHeroView; import com.alexstyl.specialdates.addevent.ui.ContactsAutoCompleteView; +import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsEvent; +import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.contact.Birthday; import com.alexstyl.specialdates.contact.Contact; @@ -33,7 +35,7 @@ public class AddBirthdayActivity extends ThemedActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - analytics = Analytics.get(this); + analytics = Firebase.get(this); analytics.trackScreen(Screen.ADD_BIRTHDAY); MementoTheme theme = Themer.get().getCurrentTheme(); setContentView(R.layout.activity_add_birthday, theme); @@ -98,21 +100,21 @@ protected void onDestroy() { } private void trackEventCreation() { - AnalyticsEvent analyticsEvent; + AnalyticsAction analyticsAction; if (eventCreated) { - analyticsEvent = birthdayCreationSuccess(); + analyticsAction = birthdayCreationSuccess(); } else { - analyticsEvent = birthdayCreationFailed(); + analyticsAction = birthdayCreationFailed(); } - analytics.track(analyticsEvent); + analytics.trackAction(analyticsAction); } - private AnalyticsEvent birthdayCreationSuccess() { - return new AnalyticsEvent(AnalyticsEvent.Events.ADD_BIRTHDAY).asSuccess(true); + private AnalyticsAction birthdayCreationSuccess() { + return new AnalyticsAction(Action.ADD_BIRTHDAY, "success", "true"); } - private AnalyticsEvent birthdayCreationFailed() { - return new AnalyticsEvent(AnalyticsEvent.Events.ADD_BIRTHDAY).asSuccess(false); + private AnalyticsAction birthdayCreationFailed() { + return new AnalyticsAction(Action.ADD_BIRTHDAY, "success", "false"); } private final BirthdayLabelView.OnEditListener onBirthdayLabelClicked = new BirthdayLabelView.OnEditListener() { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java new file mode 100644 index 00000000..c312ffe3 --- /dev/null +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java @@ -0,0 +1,19 @@ +package com.alexstyl.specialdates.analytics; + +public enum Action { + ADD_BIRTHDAY("add birthday"), + DAILY_REMINDER("enable daily reminder"), + DONATION("donate"), + INTERACT_CONTACT("interact contact"); + + private final String name; + + Action(String name) { + this.name = name; + } + + public String getName() { + return name; + } + +} diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java index 853d14ed..92884489 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java @@ -1,31 +1,7 @@ package com.alexstyl.specialdates.analytics; -import android.content.Context; +public interface Analytics { + void trackAction(AnalyticsAction event); -import com.google.firebase.analytics.FirebaseAnalytics; - -public class Analytics { - - private final FirebaseAnalytics firebaseAnalytics; - - private static Analytics INSTANCE; - - public static Analytics get(Context context) { - if (INSTANCE == null) { - INSTANCE = new Analytics(FirebaseAnalytics.getInstance(context)); - } - return INSTANCE; - } - - public Analytics(FirebaseAnalytics firebaseAnalytics) { - this.firebaseAnalytics = firebaseAnalytics; - } - - public void track(AnalyticsEvent event) { - firebaseAnalytics.logEvent(event.getName(), event.data()); - } - - public void trackScreen(Screen screen) { - firebaseAnalytics.logEvent("screen_view", screen.getData()); - } + void trackScreen(Screen screen); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java new file mode 100644 index 00000000..67d7efd4 --- /dev/null +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java @@ -0,0 +1,33 @@ +package com.alexstyl.specialdates.analytics; + +public final class AnalyticsAction { + + private final Action actionName; + private final String label; + private final String value; + + public AnalyticsAction(Action actionName, String label, String value) { + this.actionName = actionName; + this.label = label; + this.value = value; + } + + public AnalyticsAction(Action action, String label, boolean value) { + this.actionName = action; + this.label = label; + this.value = value ? "true" : "false"; + } + + public String getName() { + return actionName.getName(); + } + + public String getLabel() { + return label; + } + + public String getValue() { + return value; + } + +} diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java deleted file mode 100644 index af4c8b3c..00000000 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.alexstyl.specialdates.analytics; - -import android.os.Bundle; - -public class AnalyticsEvent { - - private final Bundle bundle = new Bundle(); - private final Events eventName; - private boolean enabled; - - public String getName() { - return eventName.name; - } - - public Bundle data() { - return bundle; - } - - public AnalyticsEvent(Events eventName) { - this.eventName = eventName; - } - - public AnalyticsEvent withData(String key, String value) { - this.bundle.putString(key, value); - return this; - } - - public AnalyticsEvent withData(String key, boolean value) { - this.bundle.putBoolean(key, value); - return this; - } - - public AnalyticsEvent asSuccess(boolean value) { - return withData("success", value); - } - - public AnalyticsEvent reason(String reason) { - return withData("reason", reason); - } - - public AnalyticsEvent setEnabled(boolean enabled) { - return withData("enabled", enabled); - } - - public enum Events { - ADD_BIRTHDAY("add birthday"), - DAILY_REMINDER("daily reminder"), - DONATION("donation"); - - private final String name; - - Events(String name) { - this.name = name; - } - - } - - @Override - public String toString() { - return "AnalyticsEvent{" + - "eventName=" + eventName + - ", bundle=" + bundle + - '}'; - } -} diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java new file mode 100644 index 00000000..12304694 --- /dev/null +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java @@ -0,0 +1,46 @@ +package com.alexstyl.specialdates.analytics; + +import android.content.Context; +import android.os.Bundle; + +import com.google.firebase.analytics.FirebaseAnalytics; +import com.novoda.notils.logger.simple.Log; + +import java.util.Locale; + +public class Firebase implements Analytics { + + private static final Bundle NO_DATA = null; + + private final FirebaseAnalytics firebaseAnalytics; + + private static Firebase INSTANCE; + + public static Firebase get(Context context) { + if (INSTANCE == null) { + INSTANCE = new Firebase(FirebaseAnalytics.getInstance(context)); + } + return INSTANCE; + } + + public Firebase(FirebaseAnalytics firebaseAnalytics) { + this.firebaseAnalytics = firebaseAnalytics; + } + + @Override + public void trackAction(AnalyticsAction action) { + String formattedAction = format(action); + firebaseAnalytics.logEvent(formattedAction, NO_DATA); + Log.d("Tracking event:" + formattedAction); + } + + @Override + public void trackScreen(Screen screen) { + firebaseAnalytics.logEvent("screen_view:" + screen.screenName(), NO_DATA); + Log.d("Tracking screen_view:" + screen); + } + + private String format(AnalyticsAction action) { + return String.format(Locale.US, "%s:%s:%s", action.getName(), action.getLabel(), action.getValue()); + } +} diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java index fe25de44..7b1cbf34 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Screen.java @@ -1,23 +1,26 @@ package com.alexstyl.specialdates.analytics; -import android.os.Bundle; - public enum Screen { HOME("home"), ADD_BIRTHDAY("add birthday"), SEARCH("search"), SETTINGS("settings"), DATE_DETAILS("date details"), - DONATE("donate"); + DONATE("donate"), + ABOUT("about"); - private final Bundle data; + private final String screenName; Screen(String screenName) { - data = new Bundle(1); - data.putString("screen", screenName); + this.screenName = screenName; + } + + public String screenName() { + return screenName; } - public Bundle getData() { - return data; + @Override + public String toString() { + return screenName; } } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/CallAction.java b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/CallAction.java index 62e217c9..45689dfc 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/CallAction.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/CallAction.java @@ -43,4 +43,9 @@ public void onStartAction(Context context) throws ActivityNotFoundException { } + @Override + public String getName() { + return "call"; + } + } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/EMailAction.java b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/EMailAction.java index 702555be..b4b3cacc 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/EMailAction.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/EMailAction.java @@ -43,4 +43,9 @@ public void onStartAction(Context context) throws ActivityNotFoundException { } + @Override + public String getName() { + return "email"; + } + } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/IntentAction.java b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/IntentAction.java index fd28460a..fb8ea0a2 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/IntentAction.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/IntentAction.java @@ -5,4 +5,6 @@ public interface IntentAction { void onStartAction(Context context) throws ActivityNotFoundException; + + String getName(); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/SMSAction.java b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/SMSAction.java index b401ea25..d7457775 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/SMSAction.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/contact/actions/SMSAction.java @@ -43,4 +43,9 @@ public void onStartAction(Context context) throws ActivityNotFoundException { } + @Override + public String getName() { + return "SMS"; + } + } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsActivity.java index e8ce2e16..f4f418fa 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsActivity.java @@ -10,8 +10,6 @@ import com.alexstyl.specialdates.ErrorTracker; import com.alexstyl.specialdates.Optional; import com.alexstyl.specialdates.R; -import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.date.DateFormatUtils; import com.alexstyl.specialdates.date.DayDate; import com.alexstyl.specialdates.support.AskForSupport; @@ -46,7 +44,6 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_date_details); MementoToolbar toolbar = Views.findById(this, R.id.memento_toolbar); - Analytics.get(this).trackScreen(Screen.DATE_DETAILS); toolbar.displayAsUp(); setSupportActionBar(toolbar); diff --git a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java index cbae161d..fa54f245 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java @@ -25,6 +25,9 @@ import com.alexstyl.specialdates.BuildConfig; import com.alexstyl.specialdates.Navigator; import com.alexstyl.specialdates.R; +import com.alexstyl.specialdates.analytics.Analytics; +import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.contact.Contact; import com.alexstyl.specialdates.contact.actions.LabeledAction; import com.alexstyl.specialdates.date.ContactEvent; @@ -34,6 +37,7 @@ import com.alexstyl.specialdates.support.AskForSupport; import com.alexstyl.specialdates.support.OnSupportCardClickListener; import com.alexstyl.specialdates.ui.base.MementoFragment; +import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.ui.dialog.ProgressFragmentDialog; import com.alexstyl.specialdates.util.ShareNamedaysIntentCreator; @@ -41,6 +45,8 @@ public class DateDetailsFragment extends MementoFragment implements LoaderManager.LoaderCallbacks> { + private static final AnalyticsAction CONTACT_INTERACT_EXTERNAL = new AnalyticsAction(Action.INTERACT_CONTACT, "source", "external"); + public static final String KEY_DISPLAYING_YEAR = BuildConfig.APPLICATION_ID + ".displaying_year"; public static final String KEY_DISPLAYING_MONTH = BuildConfig.APPLICATION_ID + ".displaying_month"; public static final String KEY_DISPLAYING_DAY_OF_MONTH = BuildConfig.APPLICATION_ID + ".displaying_dayOfMonth"; @@ -49,10 +55,10 @@ public class DateDetailsFragment extends MementoFragment implements LoaderManage private static final int LOADER_ID_EVENTS = 503; private static final int SPAN_SIZE = 1; - private DayDate date; private ProgressBar progress; private GridWithHeaderSpacesItemDecoration spacingDecoration; + private Navigator navigator; public static Fragment newInstance(int year, int month, int dayofMonth) { @@ -69,11 +75,13 @@ public static Fragment newInstance(int year, int month, int dayofMonth) { private GridLayoutManager layoutManager; private DateDetailsAdapter adapter; + private Analytics analytics; private final ContactCardListener contactCardListener = new ContactCardListener() { @Override public void onCardClicked(View v, Contact contact) { + analytics.trackAction(CONTACT_INTERACT_EXTERNAL); contact.displayQuickInfo(getActivity(), v); } @@ -123,6 +131,8 @@ public void run() { ); } action.fire(getActivity()); + AnalyticsAction analyticsAction = new AnalyticsAction(Action.INTERACT_CONTACT, "source", action.getAction().getName()); + analytics.trackAction(analyticsAction); } }; @@ -146,6 +156,7 @@ public void onActivityCreated(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); navigator = new Navigator(getActivity()); + analytics = Firebase.get(getActivity()); } @Override diff --git a/mobile/src/main/java/com/alexstyl/specialdates/facebook/FacebookUtils.java b/mobile/src/main/java/com/alexstyl/specialdates/facebook/FacebookUtils.java deleted file mode 100644 index c59b4cd2..00000000 --- a/mobile/src/main/java/com/alexstyl/specialdates/facebook/FacebookUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.alexstyl.specialdates.facebook; - -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; - -import com.alexstyl.specialdates.contact.actions.IntentAction; -import com.alexstyl.specialdates.util.Utils; - -/** - *

Created by Alex on 6/8/2014.

- */ -public class FacebookUtils { - - private static final String PAGE_ID = "529432650512872"; - public static final String DATA_PROFILE = "fb://profile/"; - private static final String FB_PAGE_NAME = "days.official"; - private static final String URL_FACEBOOK_PAGE = "https://www.facebook.com/" + FB_PAGE_NAME; - public static final String URL_MESSENGER = "https://www.facebook.com/messages/"; - public static final String URL_FACEBOOK = "https://m.facebook.com/"; - public static final String DATA_COMPOSE = "fb://messaging/compose/"; - - public static void openFacebookPage(Context context) throws ActivityNotFoundException { - - try { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(DATA_PROFILE + PAGE_ID)); - context.startActivity(intent); - } catch (ActivityNotFoundException e) { - // the fb app is not installed. try via the browser - final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_FACEBOOK_PAGE)); - Utils.openIntentSafely( - context, new IntentAction() { - @Override - public void onStartAction(Context context) throws ActivityNotFoundException { - context.startActivity(intent); - } - } - ); - } - - } - -} diff --git a/mobile/src/main/java/com/alexstyl/specialdates/search/SearchActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/search/SearchActivity.java index 6cdc478d..cdea9c5a 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/search/SearchActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/search/SearchActivity.java @@ -3,19 +3,14 @@ import android.os.Bundle; import com.alexstyl.specialdates.R; -import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.ui.base.ThemedActivity; public class SearchActivity extends ThemedActivity { - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); - - Analytics.get(this).trackScreen(Screen.SEARCH); } } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java index a17d07ac..bf75f38f 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java @@ -15,8 +15,10 @@ import android.view.MenuItem; import com.alexstyl.specialdates.R; +import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsEvent; +import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.service.DailyReminderIntentService; import com.alexstyl.specialdates.ui.widget.TimePreference; import com.alexstyl.specialdates.util.Utils; @@ -34,7 +36,7 @@ public class DailyReminderFragment extends MyPreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - analytics = Analytics.get(getActivity()); + analytics = Firebase.get(getActivity()); setHasOptionsMenu(true); addPreferencesFromResource(R.xml.preference_dailyreminder); @@ -47,9 +49,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { Context context = getActivity(); boolean isChecked = (boolean) newValue; MainPreferenceActivity.setDailyReminder(context, isChecked); - AnalyticsEvent event = new AnalyticsEvent(AnalyticsEvent.Events.DAILY_REMINDER) - .setEnabled(isChecked); - analytics.track(event); + AnalyticsAction event = new AnalyticsAction(Action.DAILY_REMINDER, "enabled", isChecked); + analytics.trackAction(event); if (isChecked) { DailyReminderIntentService.rescheduleAlarm(context); } else { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceActivity.java index b3f8b908..e673df7f 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceActivity.java @@ -11,8 +11,6 @@ import android.view.MenuItem; import com.alexstyl.specialdates.R; -import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.service.DailyReminderIntentService; import com.alexstyl.specialdates.theming.Themer; import com.alexstyl.specialdates.ui.activity.MainActivity; @@ -30,8 +28,6 @@ protected void onCreate(Bundle savedInstanceState) { Themer.get().initialiseActivity(this); setContentView(R.layout.activity_settings); - Analytics.get(this).trackScreen(Screen.SETTINGS); - MementoToolbar toolbar = Views.findById(this, R.id.memento_toolbar); setSupportActionBar(toolbar); toolbar.displayAsUp(); diff --git a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java index 75a37532..9ba3dc81 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java @@ -12,8 +12,10 @@ import com.alexstyl.specialdates.BuildConfig; import com.alexstyl.specialdates.ErrorTracker; import com.alexstyl.specialdates.R; +import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsEvent; +import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.billing.util.IabHelper; import com.alexstyl.specialdates.billing.util.IabResult; import com.alexstyl.specialdates.billing.util.Inventory; @@ -30,36 +32,36 @@ */ public class SupportDonateDialog extends MementoActivity implements View.OnClickListener { - private static final String TAG = "Donate"; + private static final String ITEM_TEST = "android.test.purchased"; - private IabHelper iabHelper; - static final String ITEM_TEST = "android.test.purchased"; + private static final String ITEM_DONATE_1 = "com.alexstyl.specialdates.support_1"; + private static final String ITEM_DONATE_2 = "com.alexstyl.specialdates.support_2"; + private static final String ITEM_DONATE_3 = "com.alexstyl.specialdates.support_3"; + private static final String ITEM_DONATE_4 = "com.alexstyl.specialdates.support_4"; + private static final String ITEM_DONATE_5 = "com.alexstyl.specialdates.support_5"; + + private static final int REQUEST_CODE_TEST = 10001; - static final String ITEM_DONATE_1 = "com.alexstyl.specialdates.support_1"; - static final String ITEM_DONATE_2 = "com.alexstyl.specialdates.support_2"; - static final String ITEM_DONATE_3 = "com.alexstyl.specialdates.support_3"; - static final String ITEM_DONATE_4 = "com.alexstyl.specialdates.support_4"; - static final String ITEM_DONATE_5 = "com.alexstyl.specialdates.support_5"; + private IabHelper iabHelper; - private int REQUEST_CODE_TEST = 10001; private boolean mBillingServiceReady; private HashMap mTokens = new HashMap<>(); IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) { - android.util.Log.d(TAG, "Query inventory finished."); + Log.d("Query inventory finished."); if (result.isFailure()) { - Log.e(TAG, "Failed to query inventory: " + result); + Log.e("Failed to query inventory: " + result); return; } - android.util.Log.d(TAG, "Query inventory was successful."); + Log.d("Query inventory was successful."); for (String token : mTokens.values()) { Purchase donationPurchase = inventory.getPurchase(token); if (donationPurchase != null /*&& verifyDeveloperPayload(gasPurchase)*/) { - android.util.Log.d(TAG, "We have token. Consuming it."); + Log.d("We have token. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(token), null); } } @@ -73,7 +75,7 @@ public void onQueryInventoryFinished(IabResult result, public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.donate); - analytics = Analytics.get(this); + analytics = Firebase.get(this); mTokens = new HashMap<>(); if (BuildConfig.DEBUG) { mTokens.put("1", ITEM_TEST); @@ -132,21 +134,21 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { } // Purchase was success! Update accordingly - Log.d(TAG, "Bought " + purchase.getSku()); + Log.d("Bought " + purchase.getSku()); // consume it so that the user can buy a donation again iabHelper.consumeAsync(purchase, null); Toast.makeText(SupportDonateDialog.this, R.string.thanks_for_support, Toast.LENGTH_SHORT).show(); - analytics.track(successfulDonationEvent()); + analytics.trackAction(successfulDonationEvent()); finish(); - Log.d(TAG, "Purchase successful!"); + Log.d("Purchase successful!"); } }; - private AnalyticsEvent successfulDonationEvent() { - return new AnalyticsEvent(AnalyticsEvent.Events.DONATION).asSuccess(true); + private AnalyticsAction successfulDonationEvent() { + return new AnalyticsAction(Action.DONATION, "success", true); } private void initialiseBilling() { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java index 843cdbd4..45274bc6 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java @@ -12,6 +12,7 @@ import com.alexstyl.specialdates.about.AboutActivity; import com.alexstyl.specialdates.addevent.AddBirthdayActivity; import com.alexstyl.specialdates.analytics.Analytics; +import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.settings.MainPreferenceActivity; import com.alexstyl.specialdates.support.AskForSupport; @@ -41,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); reapplier = new ThemeReapplier(this); - analytics = Analytics.get(this); + analytics = Firebase.get(this); analytics.trackScreen(Screen.HOME); Toolbar toolbar = Views.findById(this, R.id.memento_toolbar); @@ -106,11 +107,13 @@ private void openDonateDialog() { } private void openAboutScreen() { + Firebase.get(this).trackScreen(Screen.ABOUT); startActivity(new Intent(this, AboutActivity.class)); } private void openSettings() { + Firebase.get(this).trackScreen(Screen.SETTINGS); startActivity(new Intent(this, MainPreferenceActivity.class)); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java index eac49da4..af26bdd3 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java @@ -12,10 +12,15 @@ import android.widget.TextView; import com.alexstyl.specialdates.R; +import com.alexstyl.specialdates.analytics.Action; +import com.alexstyl.specialdates.analytics.Analytics; +import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.Firebase; +import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.date.CelebrationDate; import com.alexstyl.specialdates.date.ContactEvent; -import com.alexstyl.specialdates.datedetails.DateDetailsActivity; import com.alexstyl.specialdates.date.DayDate; +import com.alexstyl.specialdates.datedetails.DateDetailsActivity; import com.alexstyl.specialdates.search.SearchActivity; import com.alexstyl.specialdates.theming.Themer; import com.alexstyl.specialdates.ui.base.MementoFragment; @@ -27,26 +32,25 @@ public class UpcomingEventsFragment extends MementoFragment { + private static final AnalyticsAction action = new AnalyticsAction(Action.INTERACT_CONTACT, "source", "external"); + private UpcomingEventsListView upcomingEventsListView; private ProgressBar progressBar; private TextView emptyView; - private SettingsMonitor monitor; private MonthTitleSetter titleSetter; - private UpcomingEventsProvider upcomingEventsProvider; - private boolean mustScrollToPosition = true; private GoToTodayEnabler goToTodayEnabler; - private Themer themer; + private Analytics firebase; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); themer = Themer.get(); - + firebase = Firebase.get(getActivity()); monitor = SettingsMonitor.newInstance(getActivity()); monitor.initialise(); titleSetter = MonthTitleSetter.createSetterFor(getActivity()); @@ -147,13 +151,16 @@ private void showLoading() { } private final UpcomingEventsListView.Listener listClickListener = new UpcomingEventsListView.Listener() { + @Override public void onContactEventPressed(View view, ContactEvent contact) { + firebase.trackAction(action); contact.getContact().displayQuickInfo(getActivity(), view); } @Override public void onCardPressed(DayDate date) { + firebase.trackScreen(Screen.DATE_DETAILS); Intent intent = DateDetailsActivity.getStartIntent(getActivity(), date.getDayOfMonth(), date.getMonth(), date.getYear()); startActivity(intent); } @@ -165,6 +172,7 @@ public void onDifferentMonthScrolled(int month) { }; public boolean onSearchRequested() { + Firebase.get(getActivity()).trackScreen(Screen.SEARCH); Intent intent = new Intent(getActivity(), SearchActivity.class); startActivity(intent); return true; diff --git a/mobile/src/main/java/com/alexstyl/specialdates/util/Utils.java b/mobile/src/main/java/com/alexstyl/specialdates/util/Utils.java index 9942a7ee..45d68b8b 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/util/Utils.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/util/Utils.java @@ -242,6 +242,11 @@ public void onStartAction(Context context) throws ActivityNotFoundException { intent2.putExtra(Intent.EXTRA_TEXT, shareText); context.startActivity(Intent.createChooser(intent2, context.getString(R.string.share_via))); } + + @Override + public String getName() { + return "share"; + } } ); } diff --git a/mobile/src/test/java/com/alexstyl/specialdates/events/ContactEventsTest.java b/mobile/src/test/java/com/alexstyl/specialdates/events/ContactActionTest.java similarity index 98% rename from mobile/src/test/java/com/alexstyl/specialdates/events/ContactEventsTest.java rename to mobile/src/test/java/com/alexstyl/specialdates/events/ContactActionTest.java index 2c9976d5..c2904948 100644 --- a/mobile/src/test/java/com/alexstyl/specialdates/events/ContactEventsTest.java +++ b/mobile/src/test/java/com/alexstyl/specialdates/events/ContactActionTest.java @@ -13,7 +13,7 @@ import static org.fest.assertions.api.Assertions.assertThat; -public class ContactEventsTest { +public class ContactActionTest { private final List ANY_CONTACTS = new ArrayList<>(); private final TestContact CONTACT_ONE = new TestContact(1, DisplayName.from("Alex Styl")); From 259884e712d07cd364db9278f112dfb168eda59f Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Tue, 6 Sep 2016 22:43:09 +0100 Subject: [PATCH 09/12] Add more events to analytics --- .../addevent/AddBirthdayActivity.java | 18 +++++++++--------- .../specialdates/analytics/Action.java | 4 +++- ...csAction.java => ActionWithParameters.java} | 6 +++--- .../specialdates/analytics/Analytics.java | 4 +++- .../specialdates/analytics/Firebase.java | 11 +++++++++-- .../datedetails/DateDetailsFragment.java | 8 ++++---- .../settings/DailyReminderFragment.java | 4 ++-- .../settings/MainPreferenceFragment.java | 8 +++++++- .../support/SupportDonateDialog.java | 6 +++--- .../specialdates/ui/activity/MainActivity.java | 4 ++-- .../upcoming/UpcomingEventsFragment.java | 11 ++++++++--- 11 files changed, 53 insertions(+), 31 deletions(-) rename mobile/src/main/java/com/alexstyl/specialdates/analytics/{AnalyticsAction.java => ActionWithParameters.java} (73%) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java index 479b4776..cc5df3b4 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/addevent/AddBirthdayActivity.java @@ -10,7 +10,7 @@ import com.alexstyl.specialdates.addevent.ui.ContactsAutoCompleteView; import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.ActionWithParameters; import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.contact.Birthday; @@ -100,21 +100,21 @@ protected void onDestroy() { } private void trackEventCreation() { - AnalyticsAction analyticsAction; + ActionWithParameters actionWithParameters; if (eventCreated) { - analyticsAction = birthdayCreationSuccess(); + actionWithParameters = birthdayCreationSuccess(); } else { - analyticsAction = birthdayCreationFailed(); + actionWithParameters = birthdayCreationFailed(); } - analytics.trackAction(analyticsAction); + analytics.trackAction(actionWithParameters); } - private AnalyticsAction birthdayCreationSuccess() { - return new AnalyticsAction(Action.ADD_BIRTHDAY, "success", "true"); + private ActionWithParameters birthdayCreationSuccess() { + return new ActionWithParameters(Action.ADD_BIRTHDAY, "success", "true"); } - private AnalyticsAction birthdayCreationFailed() { - return new AnalyticsAction(Action.ADD_BIRTHDAY, "success", "false"); + private ActionWithParameters birthdayCreationFailed() { + return new ActionWithParameters(Action.ADD_BIRTHDAY, "success", "false"); } private final BirthdayLabelView.OnEditListener onBirthdayLabelClicked = new BirthdayLabelView.OnEditListener() { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java index c312ffe3..9b192da8 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java @@ -4,7 +4,9 @@ public enum Action { ADD_BIRTHDAY("add birthday"), DAILY_REMINDER("enable daily reminder"), DONATION("donate"), - INTERACT_CONTACT("interact contact"); + INTERACT_CONTACT("interact contact"), + SELECT_THEME("select theme"), + GO_TO_TODAY("go to today"); private final String name; diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/ActionWithParameters.java similarity index 73% rename from mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java rename to mobile/src/main/java/com/alexstyl/specialdates/analytics/ActionWithParameters.java index 67d7efd4..4b455c5b 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/AnalyticsAction.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/ActionWithParameters.java @@ -1,18 +1,18 @@ package com.alexstyl.specialdates.analytics; -public final class AnalyticsAction { +public final class ActionWithParameters { private final Action actionName; private final String label; private final String value; - public AnalyticsAction(Action actionName, String label, String value) { + public ActionWithParameters(Action actionName, String label, String value) { this.actionName = actionName; this.label = label; this.value = value; } - public AnalyticsAction(Action action, String label, boolean value) { + public ActionWithParameters(Action action, String label, boolean value) { this.actionName = action; this.label = label; this.value = value ? "true" : "false"; diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java index 92884489..2da83786 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Analytics.java @@ -1,7 +1,9 @@ package com.alexstyl.specialdates.analytics; public interface Analytics { - void trackAction(AnalyticsAction event); + void trackAction(Action goToToday); + + void trackAction(ActionWithParameters event); void trackScreen(Screen screen); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java index 12304694..8761c6b9 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java @@ -28,7 +28,14 @@ public Firebase(FirebaseAnalytics firebaseAnalytics) { } @Override - public void trackAction(AnalyticsAction action) { + public void trackAction(Action goToToday) { + String actionName = goToToday.getName(); + firebaseAnalytics.logEvent(actionName, NO_DATA); + Log.d("Tracking event:" + actionName); + } + + @Override + public void trackAction(ActionWithParameters action) { String formattedAction = format(action); firebaseAnalytics.logEvent(formattedAction, NO_DATA); Log.d("Tracking event:" + formattedAction); @@ -40,7 +47,7 @@ public void trackScreen(Screen screen) { Log.d("Tracking screen_view:" + screen); } - private String format(AnalyticsAction action) { + private String format(ActionWithParameters action) { return String.format(Locale.US, "%s:%s:%s", action.getName(), action.getLabel(), action.getValue()); } } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java index fa54f245..f2ebabf1 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/datedetails/DateDetailsFragment.java @@ -26,7 +26,7 @@ import com.alexstyl.specialdates.Navigator; import com.alexstyl.specialdates.R; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.ActionWithParameters; import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.contact.Contact; import com.alexstyl.specialdates.contact.actions.LabeledAction; @@ -45,7 +45,7 @@ public class DateDetailsFragment extends MementoFragment implements LoaderManager.LoaderCallbacks> { - private static final AnalyticsAction CONTACT_INTERACT_EXTERNAL = new AnalyticsAction(Action.INTERACT_CONTACT, "source", "external"); + private static final ActionWithParameters CONTACT_INTERACT_EXTERNAL = new ActionWithParameters(Action.INTERACT_CONTACT, "source", "external"); public static final String KEY_DISPLAYING_YEAR = BuildConfig.APPLICATION_ID + ".displaying_year"; public static final String KEY_DISPLAYING_MONTH = BuildConfig.APPLICATION_ID + ".displaying_month"; @@ -131,8 +131,8 @@ public void run() { ); } action.fire(getActivity()); - AnalyticsAction analyticsAction = new AnalyticsAction(Action.INTERACT_CONTACT, "source", action.getAction().getName()); - analytics.trackAction(analyticsAction); + ActionWithParameters actionWithParameters = new ActionWithParameters(Action.INTERACT_CONTACT, "source", action.getAction().getName()); + analytics.trackAction(actionWithParameters); } }; diff --git a/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java index bf75f38f..e0d3cee5 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/settings/DailyReminderFragment.java @@ -17,7 +17,7 @@ import com.alexstyl.specialdates.R; import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.ActionWithParameters; import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.service.DailyReminderIntentService; import com.alexstyl.specialdates.ui.widget.TimePreference; @@ -49,7 +49,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { Context context = getActivity(); boolean isChecked = (boolean) newValue; MainPreferenceActivity.setDailyReminder(context, isChecked); - AnalyticsAction event = new AnalyticsAction(Action.DAILY_REMINDER, "enabled", isChecked); + ActionWithParameters event = new ActionWithParameters(Action.DAILY_REMINDER, "enabled", isChecked); analytics.trackAction(event); if (isChecked) { DailyReminderIntentService.rescheduleAlarm(context); diff --git a/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceFragment.java index eb26bd6e..97c27a30 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/settings/MainPreferenceFragment.java @@ -7,6 +7,9 @@ import com.alexstyl.specialdates.ErrorTracker; import com.alexstyl.specialdates.R; +import com.alexstyl.specialdates.analytics.Action; +import com.alexstyl.specialdates.analytics.ActionWithParameters; +import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.events.namedays.NamedayLocale; import com.alexstyl.specialdates.events.namedays.NamedayPreferences; import com.alexstyl.specialdates.theming.MementoTheme; @@ -26,6 +29,8 @@ final public class MainPreferenceFragment extends MementoPreferenceFragment { private MainPreferenceActivity activity; + private Firebase analytics; + @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -36,7 +41,7 @@ public void onAttach(Activity activity) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_main); - + analytics = Firebase.get(getActivity()); Preference bankholidaysLanguage = findPreference(R.string.key_bankholidays_language); bankholidaysLanguage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override @@ -130,6 +135,7 @@ public void onResume() { @Override public void onThemeSelected(MementoTheme theme) { + analytics.trackAction(new ActionWithParameters(Action.SELECT_THEME, "theme name", theme.getThemeName())); themingPreferences.setSelectedTheme(theme); activity.reapplyTheme(); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java index 9ba3dc81..aa131c24 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java @@ -14,7 +14,7 @@ import com.alexstyl.specialdates.R; import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.ActionWithParameters; import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.billing.util.IabHelper; import com.alexstyl.specialdates.billing.util.IabResult; @@ -147,8 +147,8 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { }; - private AnalyticsAction successfulDonationEvent() { - return new AnalyticsAction(Action.DONATION, "success", true); + private ActionWithParameters successfulDonationEvent() { + return new ActionWithParameters(Action.DONATION, "success", true); } private void initialiseBilling() { diff --git a/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java b/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java index 45274bc6..3d65b75e 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/ui/activity/MainActivity.java @@ -107,13 +107,13 @@ private void openDonateDialog() { } private void openAboutScreen() { - Firebase.get(this).trackScreen(Screen.ABOUT); + analytics.trackScreen(Screen.ABOUT); startActivity(new Intent(this, AboutActivity.class)); } private void openSettings() { - Firebase.get(this).trackScreen(Screen.SETTINGS); + analytics.trackScreen(Screen.SETTINGS); startActivity(new Intent(this, MainPreferenceActivity.class)); } diff --git a/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java b/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java index af26bdd3..9ddbd96d 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/upcoming/UpcomingEventsFragment.java @@ -14,7 +14,7 @@ import com.alexstyl.specialdates.R; import com.alexstyl.specialdates.analytics.Action; import com.alexstyl.specialdates.analytics.Analytics; -import com.alexstyl.specialdates.analytics.AnalyticsAction; +import com.alexstyl.specialdates.analytics.ActionWithParameters; import com.alexstyl.specialdates.analytics.Firebase; import com.alexstyl.specialdates.analytics.Screen; import com.alexstyl.specialdates.date.CelebrationDate; @@ -32,7 +32,7 @@ public class UpcomingEventsFragment extends MementoFragment { - private static final AnalyticsAction action = new AnalyticsAction(Action.INTERACT_CONTACT, "source", "external"); + private static final ActionWithParameters action = new ActionWithParameters(Action.INTERACT_CONTACT, "source", "external"); private UpcomingEventsListView upcomingEventsListView; private ProgressBar progressBar; @@ -77,7 +77,7 @@ private boolean isUsingDarkIcons() { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_today: - upcomingEventsListView.scrollToToday(true); + onGoToTodayRequested(); return true; case R.id.action_search: { onSearchRequested(); @@ -89,6 +89,11 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + private void onGoToTodayRequested() { + Firebase.get(getActivity()).trackAction(Action.GO_TO_TODAY); + upcomingEventsListView.scrollToToday(true); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_upcoming_events, container, false); From d4f606f99ccccea5f49769a0e9f8d3778f533489 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Tue, 6 Sep 2016 22:48:04 +0100 Subject: [PATCH 10/12] Reduce visibility of firebase analytics constructor --- .../main/java/com/alexstyl/specialdates/analytics/Firebase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java index 8761c6b9..e002cce4 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/analytics/Firebase.java @@ -23,7 +23,7 @@ public static Firebase get(Context context) { return INSTANCE; } - public Firebase(FirebaseAnalytics firebaseAnalytics) { + private Firebase(FirebaseAnalytics firebaseAnalytics) { this.firebaseAnalytics = firebaseAnalytics; } From 79dbfafa53c776557cf0aa5fcb741cb7424b6ec1 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Tue, 6 Sep 2016 22:58:48 +0100 Subject: [PATCH 11/12] Add donation cancelled event --- .../support/SupportDonateDialog.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java index aa131c24..fe171195 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java @@ -40,12 +40,17 @@ public class SupportDonateDialog extends MementoActivity implements View.OnClick private static final String ITEM_DONATE_4 = "com.alexstyl.specialdates.support_4"; private static final String ITEM_DONATE_5 = "com.alexstyl.specialdates.support_5"; + private static final ActionWithParameters DONATION_SUCCED = new ActionWithParameters(Action.DONATION, "success", true); + private static final ActionWithParameters DONATION_FAILED = new ActionWithParameters(Action.DONATION, "success", false); + private static final ActionWithParameters DONATION_CANCELED = new ActionWithParameters(Action.DONATION, "success", "canceled"); + private static final int REQUEST_CODE_TEST = 10001; private IabHelper iabHelper; - private boolean mBillingServiceReady; - private HashMap mTokens = new HashMap<>(); + + private final HashMap mTokens = new HashMap<>(); + private Analytics analytics; IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, @@ -60,7 +65,7 @@ public void onQueryInventoryFinished(IabResult result, for (String token : mTokens.values()) { Purchase donationPurchase = inventory.getPurchase(token); - if (donationPurchase != null /*&& verifyDeveloperPayload(gasPurchase)*/) { + if (donationPurchase != null) { Log.d("We have token. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(token), null); } @@ -113,8 +118,6 @@ public void onCreate(Bundle savedInstanceState) { } } - private Analytics analytics; - private IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase purchase) { @@ -125,10 +128,12 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { // Don't complain if cancelling if (result.getResponse() == IabHelper.IABHELPER_USER_CANCELLED) { + analytics.trackAction(DONATION_CANCELED); return; } if (!result.isSuccess()) { + analytics.trackAction(DONATION_FAILED); ErrorTracker.track(new RuntimeException("onIabPurchaseFinished error: " + result.getMessage())); return; } @@ -140,17 +145,13 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) { iabHelper.consumeAsync(purchase, null); Toast.makeText(SupportDonateDialog.this, R.string.thanks_for_support, Toast.LENGTH_SHORT).show(); - analytics.trackAction(successfulDonationEvent()); + analytics.trackAction(DONATION_SUCCED); finish(); Log.d("Purchase successful!"); } }; - private ActionWithParameters successfulDonationEvent() { - return new ActionWithParameters(Action.DONATION, "success", true); - } - private void initialiseBilling() { if (iabHelper != null) { return; From adac4660e78d6c192d834eeed3c8f9564d6b1a00 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Tue, 6 Sep 2016 23:04:58 +0100 Subject: [PATCH 12/12] Remove final --- .../com/alexstyl/specialdates/support/SupportDonateDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java index fe171195..7426cdb6 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/support/SupportDonateDialog.java @@ -49,7 +49,7 @@ public class SupportDonateDialog extends MementoActivity implements View.OnClick private IabHelper iabHelper; private boolean mBillingServiceReady; - private final HashMap mTokens = new HashMap<>(); + private HashMap mTokens = new HashMap<>(); private Analytics analytics; IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {