package com.sheep.gamegroup.absBase;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;

import com.sheep.gamegroup.view.dialog.DialogLoading;

import butterknife.ButterKnife;

/**
 * Created by kemllor on 2017/12/15.
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected DialogLoading dialogLoading;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        initView();
        initListener();
        initData();
    }

    public boolean isShowing() {
        return dialogLoading != null && dialogLoading.getAlertDialog() != null && dialogLoading.getAlertDialog().isShowing();
    }

    public void showProgress() {
        hideProgress();
        dialogLoading = DialogLoading.showDialog(this);
    }

    protected void showProgress(boolean cancel) {
        hideProgress();
        dialogLoading = DialogLoading.showDialog(this, cancel);
    }


    public void hideProgress() {
        if (isShowing()) {
            try {
                dialogLoading.getAlertDialog().dismiss();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        /*if (BuildConfig.DEBUG)
            if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                Intent intent = Chuck.getLaunchIntent(BaseActivity.this);
                startActivity(intent);
                return true;
            }*/
        return super.onKeyDown(keyCode, event);
    }

    protected abstract int getLayoutId();

    public abstract void initView();

    public abstract void initListener();

    public abstract void initData();


}
