package com.teamopensmartglasses.smartglassesmanager.speechrecognition.google.asr.asrhelpers;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.teamopensmartglasses.smartglassesmanager.R;

import java.util.List;

public class ResponseTextUiAdapter extends RecyclerView.Adapter<ResponseTextUiAdapter.ViewHolder> {
    private List<String> data;

    public ResponseTextUiAdapter(List<String> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.response_text_box, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String text = data.get(position);
        holder.textView.setText(text);
    }

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

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.textView);
        }
    }

    public void addText(String text) {
        data.add(text);
        notifyItemInserted(data.size() - 1);
    }

    public void clearTexts() {
        data.clear();
        notifyDataSetChanged();
    }
}