package com.example.jinyu_rfid;

import androidx.databinding.DataBindingUtil;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.jinyu_rfid.adapter.ResultAdapter;
import com.example.jinyu_rfid.base.BaseActivity;
import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityReadBinding;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
import com.example.jinyu_rfid.uitls.ASCIIUtil;

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

public class ReadActivity extends BaseActivity implements DataReturnCall {
    private ResultAdapter adapter;
    private RFIDModel rfidModel;
    private String[] stringArray;
    private List<ReadTyreNoResult> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityReadBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_read);
        binding.setTitle(getString(R.string.go_read));
        adapter = new ResultAdapter(this);
        binding.setAdapter(adapter);
        // 名称

        stringArray = getResources().getStringArray(R.array.project_list);
        rfidModel = new C5106Device(this);
        list = new ArrayList<>(11);
        adapter.setList(list);
    }

    public void readInfo(View view) {
        rfidModel.sanUser(80);
    }

    @Override
    public void readEpcCodeInfo(String info, boolean state, String stateInfo) {

    }

    @SuppressLint("NotifyDataSetChanged")
    @Override
    public void readUserInfo(String user, boolean state, String stateInfo) {
        list.clear();
        if (state) {
            music.start();
            String info = ASCIIUtil.hex2Str(user);
            Log.e("TAG", "readUserInfo:" + info);
            var infos = info.split("~");
            for (int i = 0; i < 12; i++) {
                list.add( new ReadTyreNoResult(i,stringArray[i],infos[i]));
            }
        }
        adapter.notifyDataSetChanged();
    }


}