package com.ihaoin.hooloo.device;

import android.app.Application;
import android.util.Log;

import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
import com.ihaoin.hooloo.device.util.StringUtils;

import cn.jpush.android.api.JPushInterface;

public class HLApplication extends Application {
    private static MainData mainData = new MainData();

    public static MainData getMainData() {
        return mainData;
    }

    public static void setMainData(MainData data) {
        mainData = data;
    }

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

        AppConfig.MACHINE_CODE = SharedPreferencesUtils.getMachineCode(this);

        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);

        String registrationId = JPushInterface.getRegistrationID(this);
        Log.d("PushMessageReceiver", registrationId);
        if (!StringUtils.isEmpty(registrationId)) {
            HttpUtil.postRegistrationId(registrationId, null);
        }
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }
}
