package com.example.bpa.view.from;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bpa.R;
import com.example.bpa.helper.T;
import com.example.bpa.view.control.ItemClickListener;
import com.example.bpa.view.control.MainMeunAdapter;
import com.example.bpa.view.control.MyLayoutManager;
import com.example.bpa.view.mode.MenuMode;

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

/**
 * 电子秤校验
 */
public class dzcjy_activity extends AppCompatActivity implements View.OnClickListener{
    //region 变量
    /**
     * 返回按钮
     */
    ImageView gongneng_fanhui;
    /**
     * 标题设置
     */
    TextView gongneng_title;
    RecyclerView recyclerView;
    MainMeunAdapter adapter;
    List<MenuMode> menuModes = new ArrayList<>();
    //endregion

    //region 私有函数
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dzcjy);
        Init();
        initEvents();
    }
    //endregion

    //region 公共函数

    /**
     * 初始化
     */
    private void Init(){
        gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui);
        gongneng_title = this.findViewById(R.id.gongneng_title);
        //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据
        String msg=getIntent().getStringExtra("data");
        gongneng_title.setText(msg);

        recyclerView = this.findViewById(R.id.recycler_view);

        menuModes.clear();
        menuModes.add(new MenuMode("设置最大称重",R.mipmap.zuidachengzhong));
        menuModes.add(new MenuMode("设置分度参数",R.mipmap.shezhifenducanshu));
        menuModes.add(new MenuMode("归零",R.mipmap.guiling));
        menuModes.add(new MenuMode("设置标准重量",R.mipmap.biaozhunzhongliang));
        menuModes.add(new MenuMode("称重校验",R.mipmap.chengzhongjiaoyan));

        MyLayoutManager layout = new MyLayoutManager();
        //必须，防止recyclerview高度为wrap时测量item高度0
        layout.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(layout);
        adapter = new MainMeunAdapter(this, menuModes);
        recyclerView.setAdapter(adapter);
        recyclerView.addOnItemTouchListener(new ItemClickListener(recyclerView, new ItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                TextView textView = (TextView) view.findViewById(R.id.meun_textview);
                T.show(view.getContext(),"打开窗体："+ textView.getText().toString());
                switch (textView.getText().toString())
                {
                    case "设置最大称重":
                        break;
                    case "设置分度参数":
                        break;
                    case "归零":
                        break;
                    case "设置标准重量":
                        break;
                    case "称重校验":
                    default:
                        break;
                }
            }
            @Override
            public void onItemLongClick(View view, int position) {

            }
        }));
    }

    /**
     * 初始化按钮事件
     */
    private void initEvents() {
        gongneng_fanhui.setOnClickListener(this);
    }
    //endregion

    //region 点击事件
    /**
     * 本页面点击事件监听
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.gongneng_fanhui://返回按钮
                this.finish();
                break;
        }
    }
    //endregion
}