/*
 * Copyright 2016 Hippo Seven
 *
 * 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.hippo.ehviewer;

import android.content.Context;
import android.os.Bundle;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.hippo.scene.SceneFragment;

public final class Analytics {

    private static FirebaseAnalytics analytics;

    private Analytics() {}

    public static void start(Context context) {
        analytics = FirebaseAnalytics.getInstance(context);
        analytics.setUserId(Settings.getUserID());
    }

    public static boolean isEnabled() {
        return analytics != null && Settings.getEnableAnalytics();
    }

    public static void onSceneView(SceneFragment scene) {
        if (isEnabled()) {
            Bundle bundle = new Bundle();
            bundle.putString("scene_simple_class", scene.getClass().getSimpleName());
            bundle.putString("scene_class", scene.getClass().getName());
            analytics.logEvent("scene_view", bundle);
        }
    }
}

@@ -676,16 +676,47 @@
 Bundle;%0A
+import android.text.TextUtils;%0A
 import c
@@ -763,16 +763,16 @@
 lytics;%0A
-
 import c
@@ -800,16 +800,41 @@
 ragment;
+%0Aimport java.util.Locale;
 %0A%0Apublic
@@ -859,16 +859,86 @@
 tics %7B%0A%0A
+    private static final String DEVICE_LANGUAGE = %22device_language%22;%0A%0A
     priv
@@ -1114,16 +1114,16 @@
 ntext);%0A
-
         
@@ -1160,24 +1160,455 @@
 etUserID());
+%0A%0A        Locale locale = Locale.getDefault();%0A        String language = locale.getLanguage();%0A        if (TextUtils.isEmpty(language)) %7B%0A            language = %22none%22;%0A        %7D%0A        String country = locale.getCountry();%0A        if (!TextUtils.isEmpty(country)) %7B%0A            language = language + %22-%22 + country;%0A        %7D%0A        language = language.toLowerCase();%0A        analytics.setUserProperty(DEVICE_LANGUAGE, language);
 %0A    %7D%0A%0A    

Add device_language as user property