package com.zhaohaoting.framework.abs;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.zhaohaoting.framework.R;
import com.zhaohaoting.framework.abs.contract.BaseContract;
import com.zhaohaoting.framework.abs.presenter.AbsActivity;


/**
 * author：Created by ZHT on 2017/11/1 11:15
 * email：526309416@qq.com
 * desc：activity基类
 */
public abstract class BaseActivity<PRESENTER extends BaseContract.BasePresenter> extends AbsActivity<PRESENTER> {
    public final String TAG = this.getClass().getSimpleName();

    protected AppBarLayout appBarLayout;
    protected Toolbar actionBar;
    protected TextView titleView;
    public FrameLayout flToolbar;
    public FrameLayout flContent;
    protected CoordinatorLayout rootLayout;
    protected View topLine;

    public Bundle getSavedInstanceState() {
        return savedInstanceState;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);//白色文字
        setContentView(R.layout.activity_base);
        //设置状态栏文字颜色及图标为深色
        appBarLayout = findViewById(R.id.appbar_layout);
        actionBar = findViewById(R.id.toolbar);
        titleView = findViewById(R.id.title);
        flToolbar = findViewById(R.id.fl_toolbar);
        flContent = findViewById(R.id.fl_content);
        topLine = findViewById(R.id.top_line);
        rootLayout = findViewById(R.id.root_layout);
//        flToolbar.setPadding(0, DensityUtil.getStatusBarHeight(this), 0, 0);
        setSupportActionBar(actionBar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        actionBar.setTitle("");
        actionBar.setNavigationIcon(R.mipmap.back);
        actionBar.setNavigationOnClickListener(v -> closeActivity());
        titleView.setText(getTitle());
        rootDataBinding = DataBindingUtil.inflate(LayoutInflater.from(this), getLayoutResId(), flContent, true);
        initialize();
    }

    public abstract int getLayoutResId();

    protected abstract void initialize();

    @Override
    public void setTitle(CharSequence title) {
        titleView.setText(title);
    }
}
