package com.oo.eye.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.baselibrary.commonUtil.CheckUtil;
import com.app.baselibrary.commonUtil.DensityUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.oo.eye.R;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Date : 2018/5/2.
 * Author:  cxh
 * 测试完成后
 */

public class AfterTestDialog extends Dialog{

    private SimpleDraweeView mHead_iv;
    private TextView mUsername_tv;
    private TextView mLeftEye;
    private TextView mRightEye;
    private TextView mTestTime;
    private TextView mNextName;
    private TextView mContinueText;
    private TextView mFinishText;

    private String userName;
    private String lefteye;
    private String righteye;
    private Date mDate;
    private String nextUserName;
    private boolean isShowContinueText;
    private AfterTestListener myListener;
    private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    public AfterTestDialog(Context context, int themeResId) {
        super(context, themeResId);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_after_eye_test);
        initView();
    }

    private void initView() {
        RelativeLayout rootView = (RelativeLayout) findViewById(R.id.root_view);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DensityUtil.getScreenWidth(), DensityUtil.getScreenHeight());
        rootView.setLayoutParams(params);
        mUsername_tv = (TextView) findViewById(R.id.tv_after_name);
        mNextName = (TextView) findViewById(R.id.tv_nest_name);
        mLeftEye = (TextView) findViewById(R.id.tv_after_result_left);
        mRightEye = (TextView) findViewById(R.id.tv_after_result_right);
        mTestTime = (TextView) findViewById(R.id.tv_after_time);

        mContinueText = (TextView) findViewById(R.id.tv_after_continue);
        mContinueText.setVisibility(isShowContinueText?View.VISIBLE:View.GONE);
        mContinueText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(myListener != null){
                    myListener.onContinue();
                }
                dismiss();
            }
        });
        mFinishText = (TextView) findViewById(R.id.tv_after_finish);
        mFinishText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(myListener != null){
                    myListener.onFinish();
                }
                dismiss();
            }
        });
        if(isShowContinueText && !CheckUtil.isEmpty(nextUserName)){
            mNextName.setVisibility(View.VISIBLE);
            mNextName.setText("下一位：  "+nextUserName);
        }else{
            mNextName.setVisibility(View.GONE);
        }
        mUsername_tv.setText("姓         名："+userName);
        mLeftEye.setText(lefteye);
        mRightEye.setText(righteye);
        mTestTime.setText("检测时间：  "+mSimpleDateFormat.format(mDate));
    }


    public interface AfterTestListener {
         void onFinish();
         void onContinue();
    }

    public static class Builder {
        private AfterTestDialog mDialog;

        public Builder(Context context, int themeResId) {
            mDialog = new AfterTestDialog(context, themeResId);
        }

        public Builder setUserName(String userName) {
            mDialog.userName = userName;
            return this;
        }

        public Builder setLeftEye(String trainPlan) {
            mDialog.lefteye = trainPlan;
            return this;
        }

        public Builder setRightEye(String trainCount) {
            mDialog.righteye = trainCount;
            return this;
        }

        public Builder setTrainTime(Date date) {
            mDialog.mDate = date;
            return this;
        }
        public Builder setShowContinueText(boolean isShow){
            mDialog.isShowContinueText = isShow;
            return this;
        }
        public Builder setNextName(String name){
            mDialog.nextUserName = name;
            return this;
        }

        public Builder setOnLittleHelperListener(AfterTestListener listener) {
            mDialog.myListener = listener;
            return this;
        }

        public AfterTestDialog create() {
            return mDialog;
        }

    }

}
