package com.rehome.meetingbook.base;

import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.viewbinding.ViewBinding;

import com.rehome.meetingbook.utils.ControllerActivity;

/**
 * Create By HuangWenFei
 * 创建日期：2022-12-06 17:35
 * 描述：
 */
public abstract class BaseActivity2<T extends ViewBinding> extends AppCompatActivity {

    protected T binding;
    protected Toolbar mToolbar;
    public Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        binding = getBinding();
        mToolbar = getToolbar();
        setContentView(binding.getRoot());
        context = this;
        ControllerActivity.getAppManager().addActivity(this);
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);

        initView();
        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();
    }

    protected abstract T getBinding();
    protected abstract Toolbar getToolbar();
    protected abstract void initView();
    protected abstract void initData();

}
