package com.oo.eye.activity;

import android.content.Intent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.baselibrary.base.common.BaseActivity;
import com.app.baselibrary.commonUtil.LogUtil;
import com.app.baselibrary.commonUtil.ToastUtil;
import com.oo.eye.EyeConfig;
import com.oo.eye.R;
import com.oo.eye.bean.StudentBean;
import com.oo.eye.db.DbManager;

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

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 视力测试
 */

public class EyeTestMainActivity extends BaseActivity {

    @BindView(R.id.test_setting)
    LinearLayout mTestSetting;
    @BindView(R.id.lin_eye_test)
    LinearLayout mLinEyeTest;
    @BindView(R.id.tv_eye_test_histroy)
    TextView mTvEyeTestHistroy;
    @BindView(R.id.lin_eye_test_histroy)
    LinearLayout mLinEyeTestHistroy;
    @BindView(R.id.lin_eye_test_statistics)
    LinearLayout mLinEyeTestStatistics;
    @BindView(R.id.lin_eye_test_setting)
    LinearLayout mLinEyeTestSetting;

    private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyyMMdd");

    private boolean isRequestFinish = false;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_eye_test_main;
    }

    @Override
    protected void init() {
    }

    protected void onResume() {
        super.onResume();
    }


    @Override
    protected void onPause() {
        super.onPause();
    }


    public void getEyeSuccee() {
        isRequestFinish = true;
    }

    public void getEyeFail(String msg) {
        isRequestFinish = false;
        ToastUtil.showLongMessage(msg);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        LogUtil.e("dispatchTouchEvent:" + ev.getAction());
        return super.dispatchTouchEvent(ev);
    }

    @OnClick({R.id.test_setting, R.id.lin_eye_test, R.id.lin_eye_test_histroy, R.id.lin_eye_test_statistics, R.id.lin_eye_test_setting})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.test_setting:
                startActivity(EyeSettingActivity.class);
                break;
            case R.id.lin_eye_test://单人测试
                startActivity(SinglePeopleTestActivity.class);
                break;
            case R.id.lin_eye_test_histroy://多人测试
                startActivity(MorePeopleTestActivity.class);
                break;
            case R.id.lin_eye_test_statistics:
                long count = DbManager.getDaoSession(EyeTestMainActivity.this).getStudentBeanDao().count();
                ArrayList<StudentBean> list = new ArrayList<>();
                StudentBean student = new StudentBean();
                student.setRealname("游客"+(count+1));
                student.setClasses(mSimpleDateFormat.format(new Date()));
                list.add(student);
                EyeConfig.getInstance().setStudents(list);
                Intent intent = new Intent(EyeTestMainActivity.this,BeforeEyeTestActivity.class);
                intent.putExtra("isTemporary",true);
                startActivity(intent);
                break;
            case R.id.lin_eye_test_setting://测试报表
                startActivity(TestResurtListActivity.class);
                break;
        }
    }
}
