package .Adapter;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.andrealfredklug.ketorezepte.R;
import com.squareup.picasso.Picasso;
public class ListApdater extends ArrayAdapter<String> {
private final Activity context;
private final String[] id;
private final String[] name;
private final String[] link;
private final String[] carbs;
private final String[] protein;
private final String[] fett;
private final String[] kcal;
private final String[] time;
public ListApdater(Activity context, String[] id, String[] name, String[] link, String[] carbs, String[] protein, String[] fett, String[] kcal, String[] time){
super(context, R.layout.list_view, id);
this.context = context;
this.id = id;
this.name = name;
this.link = link;
this.carbs = carbs;
this.protein = protein;
this.fett = fett;
this.kcal = kcal;
this.time = time;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_view, null, true);
ImageView image = (ImageView) rowView.findViewById(R.id.list_imageView);
TextView nameText = (TextView)rowView.findViewById(R.id.list_name_textView);
TextView carbsText = (TextView) rowView.findViewById(R.id.list_kh_textView);
TextView proteinText = (TextView)rowView.findViewById(R.id.list_protein_textView);
TextView fettText = (TextView)rowView.findViewById(R.id.list_fett_textView);
TextView kcalText = (TextView)rowView.findViewById(R.id.list_kcal_textView);
nameText.setText(name[position]);
carbsText.setText(rowView.getResources().getString(R.string.kh) + ": " + carbs[position] + "g");
proteinText.setText(rowView.getResources().getString(R.string.protein) + ": " + protein[position] + "g");
fettText.setText(rowView.getResources().getString(R.string.fett) + ": " + fett[position] + "g");
kcalText.setText(rowView.getResources().getString(R.string.kcal) + ": " + kcal[position]);
String LinkString = link[position];
Log.e("Link", LinkString);
Picasso.get().load(link[position]).into(image);
return rowView;
}
}