package com.wisewoods.base.app;

import android.app.Application;
import android.os.Handler;
import android.os.Looper;

import com.blankj.utilcode.util.CrashUtils;
import com.wisewoods.base.net.ApiService;
import com.wisewoods.base.net.HttpInterceptor;
import com.wisewoods.base.net.LogInterceptor;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class BaseApp extends Application {

    public static Handler mHandler;
    public static ApiService api;
    public static int SDKAPPID = 0;

    @Override
    public void onCreate() {
        super.onCreate();
        CrashUtils.init();
        initHttp();
        mHandler = new Handler(Looper.getMainLooper());
    }


    private void initHttp() {
        HttpInterceptor httpInterceptor = new HttpInterceptor();
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(httpInterceptor)
                .addNetworkInterceptor(new LogInterceptor(true))
                .build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ApiService.SERVER + ApiService.PROJECT)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        api = retrofit.create(ApiService.class);
    }


}
