Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.apg.diabdis.utils;
- import android.content.Context;
- import android.os.Bundle;
- import com.google.firebase.analytics.FirebaseAnalytics;
- import pl.apg.diabdis.R;
- import pl.apg.diabdis.fragments.main.DiaryFragment;
- import pl.apg.diabdis.utils.firebase.CustomFirebaseAnalyticsEvent;
- import pl.apg.diabdis.utils.firebase.CustomFirebaseAnalyticsParam;
- /**
- * Created by bsliwa on 13.09.2016.
- */
- public class FirebaseAnalyticsClient {
- private static FirebaseAnalyticsClient firebaseClient;
- private final FirebaseAnalytics firebaseAnalytics;
- public FirebaseAnalyticsClient(Context context) {
- firebaseAnalytics = FirebaseAnalytics.getInstance(context);
- }
- public static FirebaseAnalyticsClient getFirebaseClient(Context context) {
- if (firebaseClient == null) {
- firebaseClient = new FirebaseAnalyticsClient(context);
- }
- return firebaseClient;
- }
- public void logOnMenuItemClickEvent(int itemId) {
- String name = "";
- switch (itemId) {
- case R.id.nav_messages: {
- name = "messages";
- }
- break;
- case R.id.nav_dashboard: {
- name = "dashboard";
- }
- break;
- case R.id.nav_settings: {
- name = "settings";
- }
- break;
- case R.id.nav_diary: {
- name = "glycemia";
- }
- break;
- case R.id.nav_log_out:{
- name = "logout";
- }
- }
- Bundle bundle = new Bundle();
- bundle.putString(CustomFirebaseAnalyticsParam.ITEM_ID, itemId + "");
- bundle.putString(CustomFirebaseAnalyticsParam.ITEM_NAME, name);
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, name);
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.SELECT_CONTENT, bundle);
- }
- public void logLoginEvent() {
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.LOGIN, bundle);
- }
- public void logAppOpen() {
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.APP_OPEN, bundle);
- }
- public void logSignUpEvent() {
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.SIGN_UP, bundle);
- }
- public void logPasswordResetEvent() {
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.PASS_RESET, bundle);
- }
- public void logMessageIconEvent() {
- Bundle bundle = new Bundle();
- String name = "messages_icon";
- bundle.putString(CustomFirebaseAnalyticsParam.ITEM_NAME, name);
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, name);
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.SELECT_CONTENT, bundle);
- }
- public void logGlycemyTabChangeEvent(int tabId) {
- Bundle bundle = new Bundle();
- String tabName = "";
- switch (tabId) {
- case DiaryFragment.MEASUREMENT_TAB: {
- tabName = CustomFirebaseAnalyticsParam.MEASUREMENT_TAB;
- break;
- }
- case DiaryFragment.DAY_TIME_TAB: {
- tabName = CustomFirebaseAnalyticsParam.DAY_TIME_TAB;
- break;
- }
- case DiaryFragment.DIARY_TAB: {
- tabName = CustomFirebaseAnalyticsParam.DIARY_TAB;
- break;
- }
- }
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, tabName);
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.GLYCEMY, bundle);
- }
- public void logRangeChange(int tabId, int rangeId) {
- Bundle bundle = new Bundle();
- switch (rangeId) {
- case DiaryFragment.SEVEN_DAYS: {
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE,
- String.valueOf(DiaryFragment.SEVEN_DAYS));
- break;
- }
- case DiaryFragment.THIRTY_DAYS: {
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE,
- String.valueOf(DiaryFragment.THIRTY_DAYS));
- break;
- }
- case DiaryFragment.NINETY_DAYS: {
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE,
- String.valueOf(DiaryFragment.NINETY_DAYS));
- break;
- }
- }
- switch (tabId) {
- case DiaryFragment.MEASUREMENT_TAB: {
- bundle.putString(CustomFirebaseAnalyticsParam.GLYCEMY_TAB, "MEASUREMENT");
- break;
- }
- case DiaryFragment.DAY_TIME_TAB: {
- bundle.putString(CustomFirebaseAnalyticsParam.GLYCEMY_TAB, "DAY_TIME");
- break;
- }
- case DiaryFragment.DIARY_TAB: {
- bundle.putString(CustomFirebaseAnalyticsParam.GLYCEMY_TAB, "DIARY");
- break;
- }
- }
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.RANGE_CHANGE, bundle);
- }
- public void logNoteAction(int noteActionId) {
- Bundle bundle = new Bundle();
- switch (noteActionId) {
- case R.id.item_add_note: {
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, "ADD");
- break;
- }
- case R.id.item_edit_note: {
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, "EDIT");
- break;
- }
- case R.id.item_delete_note: {
- bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, "DELETE");
- break;
- }
- }
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.NOTE, bundle);
- }
- public void logLogoutEvent() {
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.LOGOUT, bundle);
- }
- public void dismissDialogEvent() {
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.DISMISS_DIALOG, bundle);
- }
- public void openDiabdisPage(){
- Bundle bundle = new Bundle();
- firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.OPEN_PAGE, bundle);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement