package com.getui.ginsightdemo;

import java.util.ArrayList;
import java.util.List;

import com.getui.gis.sdk.GInsightManager;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

public class App extends Application {
    private List<GInsightEventListener> gInsightListeners;

    @Override
    public void onCreate() {
        super.onCreate();

        gInsightListeners = new ArrayList<>();

        GInsightManager.getInstance().init(this, "sBR4eTRMeD8UMdhmST40n9");
    }

    public void registerGInsightListener(GInsightEventListener listener) {
        gInsightListeners.add(listener);
    }

    public void unregisterGInsightListener(GInsightEventListener listener) {
        gInsightListeners.remove(listener);
    }

    public String getGiuid() {
        SharedPreferences sp = getSharedPreferences(getClass().getSimpleName(), Context.MODE_PRIVATE);
        return sp.getString("giuid", null);
    }

    public void setGiuid(String giuid) {
        SharedPreferences sp = getSharedPreferences(getClass().getSimpleName(), Context.MODE_PRIVATE);
        sp.edit().putString("giuid", giuid).apply();

        for (GInsightEventListener l : gInsightListeners) {
            l.onGiuid(giuid);
        }
    }
}
