package com.sybotan.android.demo.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.sybotan.android.demo.R;
import com.sybotan.android.demo.retrofit.Constant;


/**
 * Created by 何鑫欣 on 2017/8/16.
 */

public abstract class MyDialogViewSingle extends Dialog {
    private TextView contentview, bottomview, tv_info;
    private CheckBox checkBox;

    public MyDialogViewSingle(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_newcreate_dialog);
        contentview = (TextView) findViewById(R.id.contentTV);
        tv_info = findViewById(R.id.tv_info);
        bottomview = (TextView) findViewById(R.id.IKnowTV);
        checkBox = (CheckBox) findViewById(R.id.check_single);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            }
        });
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.IKnowTV:
                        try {
                            onBottomClick();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        dismiss();
                        break;
                }
            }
        };
        bottomview.setOnClickListener(listener);
    }

    public void setContent(String info) {
        contentview.setText(info);
    }

    public void setInfo(String info) {
        if (null == tv_info) {
            tv_info = findViewById(R.id.tv_info);
        }
        tv_info.setVisibility(View.VISIBLE);
        tv_info.setText(info);
    }

    public void setButtonNotice(String info) {
        bottomview.setText(info);
    }

    public void setCancel(boolean isCancel) {
        setCancelable(isCancel);
    }

    protected abstract void onBottomClick() throws InterruptedException;

    public MyDialogViewSingle setButtonviewText(String leftText) {
        bottomview.setText(leftText);
        return this;
    }

    public MyDialogViewSingle setContentviewText(String rightText) {
        contentview.setText(rightText);
        return this;
    }
}
