package network.config;

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

import com.jess.arms.base.delegate.AppLifecycles;
import com.jess.arms.di.module.GlobalConfigModule;
import com.jess.arms.integration.ConfigModule;
import com.jess.arms.utils.DataHelper;
import com.gingersoft.gsa.cloud.base.utils.constans.HttpsConstans;
import java.io.File;
import java.util.List;
import androidx.fragment.app.FragmentManager;
import network.config.applyOptions.MyGlobalHttpHandler;
import network.config.applyOptions.MyGsonConfiguration;
import network.config.applyOptions.MyOkhttpConfiguration;
import network.config.applyOptions.MyResponseErrorListener;
import network.config.applyOptions.MyRetrofitConfiguration;
import network.config.applyOptions.MyRxCacheConfiguration;
import network.config.lifecyclesOptioins.MyActivityLifecycle;
import network.config.lifecyclesOptioins.MyAppLifecycles;

public class GlobalConfiguration implements ConfigModule {

    @Override
    public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
        //使用builder可以为框架配置一些配置信息
        builder
                .baseurl(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL)
                .okhttpConfiguration(new MyOkhttpConfiguration())
                .retrofitConfiguration(new MyRetrofitConfiguration())
                .globalHttpHandler(new MyGlobalHttpHandler())
                .rxCacheConfiguration(new MyRxCacheConfiguration())
                .responseErrorListener(new MyResponseErrorListener())
                .cacheFile(new File(DataHelper.getCacheFile(context), "rxCache"))
                .gsonConfiguration(new MyGsonConfiguration());
    }

    @Override
    public void injectAppLifecycle(Context context, List<AppLifecycles> lifecycles) {
        //向Application的生命周期中注入一些自定义逻辑
        lifecycles.add(new MyAppLifecycles());
    }


    @Override
    public void injectActivityLifecycle(Context context, List<Application.ActivityLifecycleCallbacks> lifecycles) {
        //向Activity的生命周期中注入一些自定义逻辑
        lifecycles.add(new MyActivityLifecycle());
    }


    @Override
    public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
        //向Fragment的生命周期中注入一些自定义逻辑
    }


}