package com.oo.eye.activity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.baselibrary.base.common.BaseActivity;
import com.oo.eye.R;
import com.oo.eye.adapter.PopuAdapter;
import com.oo.eye.adapter.TestResultListAdapter;
import com.oo.eye.bean.StudentBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Date : 2018/8/28.
 * Author:  cxh
 */

public class TestResurtListActivity extends BaseActivity {
    @BindView(R.id.ddd)
    LinearLayout mDdd;
    @BindView(R.id.recycle_view)
    RecyclerView mRecycleView;
    @BindView(R.id.selete_area_tv)
    TextView mSeleteAreaTv;
    @BindView(R.id.selete_area_iv)
    ImageView mSeleteAreaIv;
    @BindView(R.id.selete_area_lay)
    LinearLayout mSeleteAreaLay;
    @BindView(R.id.selete_tv)
    TextView mSeleteTv;
    @BindView(R.id.selete_iv)
    ImageView mSeleteIv;
    @BindView(R.id.selete_lay)
    LinearLayout mSeleteLay;
    @BindView(R.id.selete1_tv)
    TextView mSelete1Tv;
    @BindView(R.id.selete1_iv)
    ImageView mSelete1Iv;
    @BindView(R.id.selete1_lay)
    LinearLayout mSelete1Lay;
    @BindView(R.id.selete2_iv)
    ImageView mSelete2Iv;
    @BindView(R.id.selete2_tv)
    TextView mSelete2Tv;
    @BindView(R.id.selete2_lay)
    LinearLayout mSelete2Lay;
    @BindView(R.id.key_test)
    EditText mKeyTest;
    @BindView(R.id.do_search)
    TextView mDoSearch;
    @BindView(R.id.title_1)
    TextView mTitle1;
    @BindView(R.id.title_2)
    TextView mTitle2;
    @BindView(R.id.textView)
    TextView mTextView;

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

    @Override
    protected void init() {
        mTitle1.setSelected(true);
        mTitle2.setSelected(false);
        mRecycleView.setLayoutManager(new LinearLayoutManager(this));
        List<StudentBean> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            StudentBean chartsBean = new StudentBean();
            list.add(chartsBean);
        }
        mRecycleView.setAdapter(new TestResultListAdapter(list, this));
    }

    private boolean isA;

    @OnClick({R.id.title_1, R.id.title_2,R.id.back_iv, R.id.selete_area_lay, R.id.selete_lay, R.id.selete1_lay, R.id.selete2_lay, R.id.do_search})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_1:
                mTitle1.setSelected(true);
                mTitle2.setSelected(false);
                break;
            case R.id.title_2:
                mTitle1.setSelected(false);
                mTitle2.setSelected(true);
                break;
            case R.id.back_iv:
                finish();
                break;
            case R.id.selete_area_lay:
                showPopWindow(1);
                break;
            case R.id.selete_lay:
                showPopWindow(2);
                break;
            case R.id.selete1_lay:
                showPopWindow(3);
                break;
            case R.id.selete2_lay://仅看A类
                isA = !isA;
                if (isA) {
                    mSelete2Iv.setImageResource(R.drawable.select3_sel);
                } else {
                    mSelete2Iv.setImageResource(R.drawable.select3_nor);
                }
                break;
            case R.id.do_search:
                break;
        }
    }

    private void showPopWindow(int position) {
        LinearLayout view = mSeleteLay;
        switch (position) {
            case 1:
                view = mSeleteAreaLay;
                break;
            case 2:
                view = mSeleteLay;
                break;
            case 3:
                view = mSelete1Lay;
                break;
        }
        try {
            View conview = View.inflate(this, R.layout.popu_list, null);
            PopupWindow popupWindow = new PopupWindow(conview, RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            popupWindow.setFocusable(true);
            popupWindow.setOutsideTouchable(true);
            ColorDrawable cd = new ColorDrawable(0x00ffffff);// 背景颜色全透明
            popupWindow.setBackgroundDrawable(cd);
            ListView listView = (ListView) conview.findViewById(R.id.list_view);
            listView.setAdapter(new PopuAdapter(this, null));
            int[] location = new int[2];
            view.getLocationOnScreen(location);
//            popupWindow.setAnimationStyle(R.style.style_pop_animation);// 动画效果必须放在showAsDropDown()方法上边，否则无效
            conview.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            int xoff = -(conview.getMeasuredWidth() / 2 - view.getWidth() / 2);
            popupWindow.showAsDropDown(view, xoff, 0);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

}
