package com.example.Maps013;

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

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class ListBaseAdapter extends BaseAdapter {

    ArrayList<RUN> myList = new ArrayList<RUN>();
    LayoutInflater inflater;
    Context context;


    public ListBaseAdapter(Context context, ArrayList<RUN> myList) 
    {
        this.myList = myList;
        this.context = context;
        inflater = LayoutInflater.from(this.context);
    }

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

    @Override
    public RUN getItem(int position) {
        return myList.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder mViewHolder;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.row_listrun, parent, false);
            mViewHolder = new MyViewHolder(convertView);
            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (MyViewHolder) convertView.getTag();
        }

        RUN currentRUN = getItem(position);

        
      
        
        
        mViewHolder.tvTitle.setText(currentRUN.nom);
        
    
        //String s = Double.toString(currentGPS.nom);
//        String s = Long.toString(currentRUN.date);
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss");
        String time = sdf.format(currentRUN.date);
        
        mViewHolder.tvDesc.setText(time);

        return convertView;
    }

    private class MyViewHolder {
        TextView tvTitle, tvDesc;
        ImageView ivIcon;

        public MyViewHolder(View item) {
            tvTitle = (TextView) item.findViewById(R.id.tvTitle);
            tvDesc = (TextView) item.findViewById(R.id.tvDesc);
           
        }
    }
}