package fr.membrives.dispotrains.adapters;

import java.util.Date;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import fr.membrives.dispotrains.R;
import fr.membrives.dispotrains.data.Elevator;

public class ElevatorAdapter extends ArrayAdapter<Elevator> {
    Context context;

    public ElevatorAdapter(Context context, List<Elevator> objects) {
        super(context, 0, objects);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        Elevator elevator = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.elevator_list_item,
                    parent, false);
        }
        ((TextView) convertView.findViewById(R.id.situation)).setText(elevator.getSituation());
        ((TextView) convertView.findViewById(R.id.direction)).setText(elevator.getDirection());
        ((TextView) convertView.findViewById(R.id.id)).setText(elevator.getId());
        ((TextView) convertView.findViewById(R.id.status)).setText(elevator.getStatusDescription());

        TextView dateView = (TextView) convertView.findViewById(R.id.date);
        Date date = elevator.getStatusDate();
        String dateStr = DateFormat.getMediumDateFormat(context).format(date);
        dateView.setText(dateStr);

        if (!elevator.getStatusDescription().equalsIgnoreCase("Disponible")) {
            convertView.setBackgroundColor(getContext().getResources().getColor(R.color.problem));
        } else {
            convertView.setBackgroundColor(Color.TRANSPARENT);
        }

        // Return the completed view to render on screen
        return convertView;
    }
}

@@ -82,16 +82,86 @@
 il.List;
+%0Aimport java.util.Locale;%0A%0Aimport org.joda.time.format.DateTimeFormat;
 %0A%0Aimport
@@ -221,47 +221,8 @@
 or;%0A
-import android.text.format.DateFormat;%0A
 impo
@@ -1664,55 +1664,103 @@
 Date
+Time
 Format.
-getMediumDateFormat(context).format(date
+forStyle(%22MS%22).withLocale(Locale.getDefault())%0A                .print(date.getTime()
 );%0A 

Fix date display