package com.rehome.meetingbook.base;


import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.rehome.meetingbook.R;
import com.rehome.meetingbook.utils.ControllerActivity;
import com.zhy.autolayout.AutoLayoutActivity;


/**
 * Create By HuangWenFei
 * 创建日期：2022-12-07 14:29
 * 描述：
 */
public abstract class BaseActivity extends AutoLayoutActivity {

    public static final int CX_FLAG = 0;//查询的状态码
    public static final int SC_FLAG = 1;//上传的状态码

    public Toolbar mToolbar;
    public TextView title;
    public Context context;

    private String readResult = "";
    private PendingIntent pendingIntent;
    private IntentFilter[] mFilters;
    private String[][] mTechLists;
    private boolean isFirst = true;
    private IntentFilter ndef;


    public abstract int getContentViewID();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        setContentView(getContentViewID());
        context = this;
        ControllerActivity.getAppManager().addActivity(this);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        title = (TextView) findViewById(R.id.title);
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);

        initView();
        initData();
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
    }

    /**
     * 初始化View
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ControllerActivity.getAppManager().finishActivity(this);
        context = null;
    }

    /**
     * 显示toast
     *
     * @param text
     */
    public void showToast(String text) {
        if (text != null && !text.trim().equals("")) {
            Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
        }
    }

    public void showToast(int id) {
        Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
    }


    public void setTitle(String title) {
        this.title.setText(title);
    }

    public void setBack() {
        mToolbar.setNavigationIcon(R.mipmap.back);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

}
