/*
 * Copyright (C) 2009-2014 Johan Nilsson <http://markupartist.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.markupartist.sthlmtraveling.utils;

import android.content.Context;

import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.markupartist.sthlmtraveling.MyApplication;

public class Analytics {

    private static String ACTION_CLICK = "Click";

    private static Analytics sInstance;
    private final Context mContext;

    public Analytics(final Context context) {
        mContext = context;
    }

    public static Analytics getInstance(final Context context) {
        if (sInstance == null) {
            sInstance = new Analytics(context);
        }
        return sInstance;
    }

    public void registerScreen(final String screenName) {
        Tracker tracker = ((MyApplication) mContext.getApplicationContext()).getTracker();
        tracker.setScreenName(screenName);
        tracker.send(new HitBuilders.AppViewBuilder().build());
    }

    public void event(final String category, final String action) {
        event(category, action, null);
    }

    public void event(final String category, final String action, final String label) {
        Tracker tracker = ((MyApplication) mContext.getApplicationContext()).getTracker();
        tracker.send(new HitBuilders.EventBuilder()
                .setCategory(category)
                .setAction(action)
                .setLabel(label)
                .build());
    }

}

@@ -708,16 +708,173 @@
 ntext;%0A%0A
+import com.crashlytics.android.answers.Answers;%0Aimport com.crashlytics.android.answers.ContentViewEvent;%0Aimport com.crashlytics.android.answers.CustomEvent;%0A
 import c
@@ -914,24 +914,24 @@
 itBuilders;%0A
-
 import com.g
@@ -1693,32 +1693,130 @@
 lder().build());
+%0A%0A        Answers.getInstance().logContentView(new ContentViewEvent().putContentName(screenName));
 %0A    %7D%0A%0A    publ
@@ -2259,16 +2259,16 @@
 (label)%0A
-
         
@@ -2285,16 +2285,333 @@
 uild());
+%0A%0A        CustomEvent answerEvent = new CustomEvent(category);%0A        if (action != null) %7B%0A            answerEvent.putCustomAttribute(%22action%22, action);%0A        %7D%0A        if (label != null) %7B%0A            answerEvent.putCustomAttribute(%22label%22, label);%0A        %7D%0A        Answers.getInstance().logCustom(answerEvent);
 %0A    %7D%0A%0A

Add Answers