package com.qhclh.ytzh.home;

import android.app.Activity;

import com.qhclh.ytzh.configs.ConfigUtil;
import com.qhclh.ytzh.configs.LastLoginInfo;
import com.qhclh.ytzh.configs.ServerConfig;

import org.forks.jsonrpc.RpcFacade;
import org.litepal.LitePalApplication;

import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by 青花瓷 on 2017/11/23.
 */

public class MyApplication extends LitePalApplication {

    private final String NAME ="ytzh";
    static LastLoginInfo mLoginInfo;
    private static MyApplication instance;
//    String url= RpcUrl.BaseAppUrl;
    ServerConfig config;

    private List<Activity> activityList = new LinkedList<Activity>();

    public static  MyApplication getInstance(){
        if (null == instance) {
            instance = new MyApplication();
        }
        return instance;
    }
    @Override
    public void onCreate() {
        super.onCreate();

        mLoginInfo = new LastLoginInfo(this);
        ConfigUtil.Fill(mLoginInfo);

//        ///< 先暂时必须设置URL
//        config = new ServerConfig(this);
//        config.setServerUri(url);
//        ConfigUtil.Save(config);

        RpcFacade.init(this.getApplicationContext(),NAME);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
    }

    public void exit() {
        for (Activity activity : activityList) {
            activity.finish();
        }
        System.exit(0);
    }

    public static void ClearLogin() {
        mLoginInfo.Username = "";
        ConfigUtil.Save(mLoginInfo);
    }
}
