package com.tenlionsoft.baselib.app;

import android.content.Context;
import android.view.Gravity;

import com.hjq.toast.ToastUtils;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.tenlionsoft.baselib.core.db.DataCenter;
import com.tenlionsoft.baselib.core.listener.ScreenListener;
import com.tenlionsoft.baselib.core.widget.refresh.BezierCircleHeader;

import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

/**
 * 作者: adam
 * 日期: 2021/10/29 - 9:48 上午
 * 邮箱: itgaojian@163.com
 * 描述:
 */
public class BaseAppContext extends MultiDexApplication {

    private static BaseAppContext app;
    private String username = "";
    private String roomId = "";
    private String otherUserId = "";

    public static DataCenter mDataCenter;
    /**
     * 锁屏监听器
     */
    private ScreenListener screenListener;

    //static 代码段可以防止内存泄露
    static {
//        设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context, layout) -> new BezierCircleHeader(context));
//        设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator((context, layout) -> new ClassicsFooter(context));
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        ToastUtils.init(this);
        ToastUtils.setGravity(Gravity.BOTTOM, 0, 100);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);

    }


    public static BaseAppContext getInstance() {
        return app;
    }

    public static DataCenter getDataCenter() {
        if (mDataCenter == null) {
            mDataCenter = DataCenter.getInstance();
        }
        return mDataCenter;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRoomId() {
        return roomId;
    }

    public void setRoomId(String roomId) {
        this.roomId = roomId;
    }

    public String getOtherUserId() {
        return otherUserId;
    }

    public void setOtherUserId(String otherUserId) {
        this.otherUserId = otherUserId;
    }


    private double mLat;
    private double mLng;
    private String mAddress;

    /**
     * 设置当前定位信息
     */
    public void setLat(double lat) {
        this.mLat = lat;
    }

    public void setLng(double lng) {
        this.mLng = lng;
    }

    public void setAddress(String address) {
        this.mAddress = address;
    }

    public double getLat() {
        return mLat;
    }

    public double getLng() {
        return mLng;
    }

    public String getAddress() {
        return mAddress;
    }
}
