package com.xunao.effectdemo.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.xunao.effectdemo.R;
import com.hpplay.sdk.source.browse.api.LelinkServiceInfo;

import java.util.List;

/**
 * author : 程中强
 * e-mail : 740479946@qq.com
 * date : 2022/9/2114:22
 * desc :
 * version: 1.0
 */
public class DeviceAdapter extends BaseAdapter {

	private List<LelinkServiceInfo> data;
	private Context context;

	public DeviceAdapter(Context context, @Nullable List<LelinkServiceInfo> data) {

		this.context = context;
		this.data = data;
	}

//	@Override
//	protected void convert(@NonNull BaseViewHolder helper, LelinkServiceInfo item) {
//		Log.e("MyTag","设备:"+item.getName());
//		helper
//				.setText(R.id.tv_name_item, TextUtils.isEmpty(item.getName())?"":item.getName())
//
//		;
//	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int i) {
		return data.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View convertView, ViewGroup viewGroup) {
		MyViewHolder holder;
		if (convertView == null) {
			holder = new MyViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_device, null);
			holder.tv_name = convertView.findViewById(R.id.tv_name_item);
			convertView.setTag(holder);
		} else {
			holder = (MyViewHolder) convertView.getTag();
		}
		Log.e("MyTag","结果收到消息111");
		holder.tv_name.setText(TextUtils.isEmpty(data.get(i).getName())?"":data.get(i).getName());
		return convertView;
	}

	class MyViewHolder {
		TextView tv_name;
	}
}
