package com.sjn.stamp.utils;

import android.content.Context;
import android.os.Bundle;

import com.google.firebase.analytics.FirebaseAnalytics;
import com.sjn.stamp.ui.activity.DrawerMenu;

import java.util.Date;

public class AnalyticsHelper {
    private static final String CREATE_STAMP = "create_stamp";
    private static final String PLAY_CATEGORY = "play_category";
    private static final String CHANGE_SCREEN = "change_screen";
    private static final String CHANGE_SETTING = "change_setting";
    private static final String CHANGE_RANKING_TERM = "change_ranking_term";

    public static void trackCategory(Context context, String mediaId) {
        String category = MediaIDHelper.extractBrowseCategoryValueFromMediaID(mediaId);
        if (category == null) {
            return;
        }
        Bundle payload = new Bundle();
        payload.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, category);
        FirebaseAnalytics.getInstance(context).logEvent(PLAY_CATEGORY, payload);
    }

    public static void trackScreen(Context context, DrawerMenu drawerMenu) {
        if (drawerMenu == null) {
            return;
        }
        Bundle payload = new Bundle();
        payload.putString(FirebaseAnalytics.Param.CONTENT, drawerMenu.toString());
        FirebaseAnalytics.getInstance(context).logEvent(CHANGE_SCREEN, payload);
    }

    public static void trackStamp(Context context, String stamp) {
        Bundle payload = new Bundle();
        payload.putString(FirebaseAnalytics.Param.ITEM_NAME, stamp);
        FirebaseAnalytics.getInstance(context).logEvent(CREATE_STAMP, payload);
    }

    public static void trackSetting(Context context, String name) {
        Bundle payload = new Bundle();
        payload.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
        FirebaseAnalytics.getInstance(context).logEvent(CHANGE_SETTING, payload);
    }

    public static void trackSetting(Context context, String name, String value) {
        Bundle payload = new Bundle();
        payload.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
        payload.putString(FirebaseAnalytics.Param.VALUE, value);
        FirebaseAnalytics.getInstance(context).logEvent(CHANGE_SETTING, payload);
    }

    public static void trackRankingTerm(Context context, Date start, Date end) {
        Bundle payload = new Bundle();
        payload.putString(FirebaseAnalytics.Param.START_DATE, start.toString());
        payload.putString(FirebaseAnalytics.Param.END_DATE, end.toString());
        FirebaseAnalytics.getInstance(context).logEvent(CHANGE_RANKING_TERM, payload);
    }
}

@@ -208,16 +208,79 @@
 .Date;%0A%0A
+import static com.sjn.stamp.utils.MediaIDHelper.getHierarchy;%0A%0A
 public c
@@ -724,77 +724,80 @@
     
-String category = MediaIDHelper.extractBrowseCategoryValueFromMediaID
+Bundle payload = new Bundle();%0A        String%5B%5D hierarchy = getHierarchy
 (med
@@ -819,24 +819,28 @@
 if (
-category == null
+hierarchy.length %3C 1
 ) %7B%0A
@@ -881,37 +881,38 @@
     
-Bundle payload = new Bundle()
+String category = hierarchy%5B0%5D
 ;%0A  

fix tracking category