package com.common.lib_base.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.common.lib_base.utils.LogUtils;
import com.common.lib_base.utils.ui.ToastUtils;
import com.gyf.immersionbar.ImmersionBar;

/**
 * Date: 2022/5/12 0012 11:26
 * Description:
 */
public abstract class BaseActivity<T> extends AppCompatActivity {

    // 当前类名
    public String mTag = getClass().getSimpleName()+"--";
    //
//    public String mNameTag = ;

    public Context mContext;
    public Activity mActivity;

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

        setContentView(setLayout());

        mContext = this;
        mActivity = this;

        setStatusBar();

        initView();

        initData();

        initListener();

        initLoginListener();

    }

    protected void initLoginListener(){

    }

    public void setStatusBar() {

        if (ImmersionBar.isSupportStatusBarDarkFont()) {
            LogUtils.i("setStatusBar---isSupportStatusBarDarkFont");
            // 状态栏字体颜色为深色(android6.0以上或者miuiv6以上或者flymeOS4+)
            ImmersionBar.with(this)
                    .fitsSystemWindows(true)
                    .statusBarDarkFont(true)
                    .init();
        } else {
            LogUtils.i("setStatusBar---默认");
            ImmersionBar.with(this)
                    .fitsSystemWindows(true)
                    .statusBarColorInt(Color.BLACK)
                    .navigationBarColorInt(Color.BLACK)
                    .autoDarkModeEnable(true)
                    .init();
        }

    }


    public abstract int setLayout();

    protected abstract void initView();

    protected abstract void initData();

    protected abstract void initListener();


    protected void startActivity(Class c) {
        this.startActivity(new Intent(this, c));
    }

    protected void startActivityAndFinish(Class c) {
        Intent intent = new Intent(this, c);
        intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP & intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

        this.finish();
    }

    protected void checkResultData(T t) {
        if (t == null) {
            ToastUtils.showLongToast(this,"暂无数据");
            LogUtils.e("ResultData == null");
            return;
        }
    }

}
