1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GuiaTV/src/org/r3pek/guiatv/ProgramListSimpleAdapter.java

46 lines
1.3 KiB

package org.r3pek.guiatv;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
public class ProgramListSimpleAdapter extends SimpleAdapter {
private ProgramList programList;
public ProgramListSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to, ProgramList programList) {
super(context, data, resource, from, to);
this.programList = programList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if (programList == null) return v;
if (programList.getProgramCount() == 0) return v;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Program p = programList.getPrograms().get(position);
Date now = new Date(System.currentTimeMillis());
Date start = null, end = null;
try {
start = format.parse(p.getStartHour());
end = format.parse(p.getEndHour());
} catch (ParseException e) { }
if (now.after(start) && now.before(end))
v.setBackgroundColor(Color.GRAY);
else
v.setBackgroundDrawable(null);
return v;
}
}