package com.videogo.widget.testlist;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * 测试功能列表适配器
 * 显示序号、标题和类名(类似iOS的UITableViewCellStyleSubtitle)
 */
public class TestItemAdapter extends BaseAdapter {
    
    private Context context;
    private List<TestItem> testItems;
    
    public TestItemAdapter(Context context, List<TestItem> testItems) {
        this.context = context;
        this.testItems = testItems;
    }
    
    @Override
    public int getCount() {
        return testItems != null ? testItems.size() : 0;
    }
    
    @Override
    public Object getItem(int position) {
        return testItems.get(position);
    }
    
    @Override
    public long getItemId(int position) {
        return position;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                ezviz.ezopensdk.R.layout.item_test_list, 
                parent, 
                false
            );
        }
        
        TestItem item = testItems.get(position);
        
        // 主标题: "序号 - 标题"
        TextView textTitle = convertView.findViewById(ezviz.ezopensdk.R.id.text_title);
        String prefix = (position < 9) ? "0" + (position + 1) : String.valueOf(position + 1);
        textTitle.setText(prefix + " - " + item.getTitle());
        
        // 副标题: 类名
        TextView textSubtitle = convertView.findViewById(ezviz.ezopensdk.R.id.text_subtitle);
        textSubtitle.setText(item.getClassName());
        
        return convertView;
    }
    
    /**
     * 更新数据
     */
    public void updateData(List<TestItem> newItems) {
        this.testItems = newItems;
        notifyDataSetChanged();
    }
}
