package com.sybotan.android.demo.activities;

import android.os.Bundle;
import android.util.Log;

import com.sybotan.android.demo.DemoApp;
import com.sybotan.android.demo.tools.LocalDataOperation;
import com.sybotan.android.demo.tools.NetUtil;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import java.io.File;
import java.util.Objects;

/**
 * Created by lihao.
 * Date: 2021/6/8
 */
public class BaseActivity extends RxAppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    /**
     * 获取图片路径-离线缓存模块的图片存储
     */
    public String getOfflineImagePath() {
        String saveDir = LocalDataOperation.getInstance().getOfflineImageFilePath(this);
        // 新建目录
        File dir = new File(saveDir);
        if (!dir.exists()) dir.mkdirs();
        return saveDir + File.separator + System.currentTimeMillis() + ".png";
    }

    /**
     * 判断是否有网络
     * @return
     */
    public static Boolean isHaveInternet() {
        int netMobile = NetUtil.getNetWorkState(Objects.requireNonNull(DemoApp.Companion.getContext()));
        Log.e("网络状态", netMobile + "");
        return netMobile == 1 || netMobile == 0;
    }

}
