Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. package pl.apg.diabdis.utils;
  2.  
  3. import android.content.Context;
  4. import android.os.Bundle;
  5.  
  6. import com.google.firebase.analytics.FirebaseAnalytics;
  7.  
  8. import pl.apg.diabdis.R;
  9. import pl.apg.diabdis.fragments.main.DiaryFragment;
  10. import pl.apg.diabdis.utils.firebase.CustomFirebaseAnalyticsEvent;
  11. import pl.apg.diabdis.utils.firebase.CustomFirebaseAnalyticsParam;
  12.  
  13. /**
  14. * Created by bsliwa on 13.09.2016.
  15. */
  16. public class FirebaseAnalyticsClient {
  17. private static FirebaseAnalyticsClient firebaseClient;
  18. private final FirebaseAnalytics firebaseAnalytics;
  19.  
  20. public FirebaseAnalyticsClient(Context context) {
  21. firebaseAnalytics = FirebaseAnalytics.getInstance(context);
  22. }
  23.  
  24.  
  25. public static FirebaseAnalyticsClient getFirebaseClient(Context context) {
  26. if (firebaseClient == null) {
  27. firebaseClient = new FirebaseAnalyticsClient(context);
  28. }
  29. return firebaseClient;
  30. }
  31.  
  32. public void logOnMenuItemClickEvent(int itemId) {
  33. String name = "";
  34.  
  35. switch (itemId) {
  36. case R.id.nav_messages: {
  37. name = "messages";
  38. }
  39. break;
  40. case R.id.nav_dashboard: {
  41. name = "dashboard";
  42. }
  43. break;
  44. case R.id.nav_settings: {
  45. name = "settings";
  46. }
  47. break;
  48. case R.id.nav_diary: {
  49. name = "glycemia";
  50. }
  51. break;
  52. case R.id.nav_log_out:{
  53. name = "logout";
  54. }
  55. }
  56.  
  57. Bundle bundle = new Bundle();
  58. bundle.putString(CustomFirebaseAnalyticsParam.ITEM_ID, itemId + "");
  59. bundle.putString(CustomFirebaseAnalyticsParam.ITEM_NAME, name);
  60. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, name);
  61. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.SELECT_CONTENT, bundle);
  62. }
  63.  
  64. public void logLoginEvent() {
  65. Bundle bundle = new Bundle();
  66. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.LOGIN, bundle);
  67. }
  68.  
  69. public void logAppOpen() {
  70. Bundle bundle = new Bundle();
  71. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.APP_OPEN, bundle);
  72. }
  73.  
  74. public void logSignUpEvent() {
  75. Bundle bundle = new Bundle();
  76. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.SIGN_UP, bundle);
  77. }
  78.  
  79. public void logPasswordResetEvent() {
  80. Bundle bundle = new Bundle();
  81. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.PASS_RESET, bundle);
  82. }
  83.  
  84. public void logMessageIconEvent() {
  85. Bundle bundle = new Bundle();
  86. String name = "messages_icon";
  87. bundle.putString(CustomFirebaseAnalyticsParam.ITEM_NAME, name);
  88. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, name);
  89. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.SELECT_CONTENT, bundle);
  90. }
  91.  
  92. public void logGlycemyTabChangeEvent(int tabId) {
  93. Bundle bundle = new Bundle();
  94. String tabName = "";
  95. switch (tabId) {
  96. case DiaryFragment.MEASUREMENT_TAB: {
  97. tabName = CustomFirebaseAnalyticsParam.MEASUREMENT_TAB;
  98. break;
  99. }
  100. case DiaryFragment.DAY_TIME_TAB: {
  101. tabName = CustomFirebaseAnalyticsParam.DAY_TIME_TAB;
  102. break;
  103. }
  104. case DiaryFragment.DIARY_TAB: {
  105. tabName = CustomFirebaseAnalyticsParam.DIARY_TAB;
  106. break;
  107. }
  108. }
  109. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, tabName);
  110. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.GLYCEMY, bundle);
  111. }
  112.  
  113.  
  114. public void logRangeChange(int tabId, int rangeId) {
  115. Bundle bundle = new Bundle();
  116.  
  117. switch (rangeId) {
  118. case DiaryFragment.SEVEN_DAYS: {
  119. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE,
  120. String.valueOf(DiaryFragment.SEVEN_DAYS));
  121. break;
  122. }
  123.  
  124. case DiaryFragment.THIRTY_DAYS: {
  125. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE,
  126. String.valueOf(DiaryFragment.THIRTY_DAYS));
  127. break;
  128. }
  129.  
  130. case DiaryFragment.NINETY_DAYS: {
  131. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE,
  132. String.valueOf(DiaryFragment.NINETY_DAYS));
  133. break;
  134. }
  135. }
  136.  
  137. switch (tabId) {
  138. case DiaryFragment.MEASUREMENT_TAB: {
  139. bundle.putString(CustomFirebaseAnalyticsParam.GLYCEMY_TAB, "MEASUREMENT");
  140. break;
  141. }
  142. case DiaryFragment.DAY_TIME_TAB: {
  143. bundle.putString(CustomFirebaseAnalyticsParam.GLYCEMY_TAB, "DAY_TIME");
  144. break;
  145. }
  146. case DiaryFragment.DIARY_TAB: {
  147. bundle.putString(CustomFirebaseAnalyticsParam.GLYCEMY_TAB, "DIARY");
  148. break;
  149. }
  150. }
  151. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.RANGE_CHANGE, bundle);
  152. }
  153.  
  154. public void logNoteAction(int noteActionId) {
  155. Bundle bundle = new Bundle();
  156. switch (noteActionId) {
  157. case R.id.item_add_note: {
  158. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, "ADD");
  159. break;
  160. }
  161. case R.id.item_edit_note: {
  162. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, "EDIT");
  163. break;
  164. }
  165. case R.id.item_delete_note: {
  166. bundle.putString(CustomFirebaseAnalyticsParam.CONTENT_TYPE, "DELETE");
  167. break;
  168. }
  169. }
  170. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.NOTE, bundle);
  171. }
  172.  
  173. public void logLogoutEvent() {
  174. Bundle bundle = new Bundle();
  175. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.LOGOUT, bundle);
  176. }
  177.  
  178. public void dismissDialogEvent() {
  179. Bundle bundle = new Bundle();
  180. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.DISMISS_DIALOG, bundle);
  181. }
  182.  
  183. public void openDiabdisPage(){
  184. Bundle bundle = new Bundle();
  185. firebaseAnalytics.logEvent(CustomFirebaseAnalyticsEvent.OPEN_PAGE, bundle);
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement