/**
*
*/
package net.maxmilian.ftrdroid;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.http.impl.cookie.DateUtils;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* @author xhovor01
*
*/
public class ChannelGuideListing extends ListActivity {
private static class EfficientAdapter extends BaseAdapter {
static class ViewHolder {
TextView startTime;
TextView title;
TextView description;
}
private TProgramDetails[] programs;
private TSchedule[] schedules;
private TGuideChannel[] channels;
private LayoutInflater mInflater;
public EfficientAdapter(Context context, String channelId, ServerConnector sc) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
// Icons bound to the rows.
try
{
Calendar cal = Calendar.getInstance();
cal.get(Calendar.DATE);
Date lowerTime = cal.getTime();
lowerTime.setHours(0);
lowerTime.setMinutes(0);
lowerTime.setSeconds(0);
cal.add(Calendar.DAY_OF_MONTH, 1);
Date upperTime = cal.getTime();
upperTime.setHours(0);
upperTime.setMinutes(0);
upperTime.setSeconds(0);
channels = sc.getChannels(0);
int i;
for (i=0;i<channels.length;i++){
if (channels[i].getChannelId().compareTo(channelId) == 0)
break;
}
this.programs = sc.getChannelProgramsBetween(channels[i], lowerTime,upperTime);
this.schedules = sc.getUpcomingGuidePrograms(EScheduleType.RECORDING, true);
//ServerConnector.getRecordingFlags(this.programs, this.schedules);
}
catch (Exception je)
{
}
}
/**
* The number of items in the list is determined by the number of speeches
* in our array.
*
* @see android.widget.ListAdapter#getCount()
*/
public int getCount() {
return programs.length;
}
/**
* Since the data comes from an array, just returning the index is
* sufficent to get at the data. If we were using a more complex data
* structure, we would return whatever object represents one row in the
* list.
*
* @see android.widget.ListAdapter#getItem(int)
*/
public Object getItem(int position) {
return position;
}
/**
* Use the array index as a unique id.
*
* @see android.widget.ListAdapter#getItemId(int)
*/
public long getItemId(int position) {
return position;
}
/**
* Make a view to hold each row.
*
* @see android.widget.ListAdapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.channel_guide_vertical_row, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.startTime = (TextView) convertView.findViewById(R.id.txtChannelGuideVerticalStartTime);
holder.title = (TextView) convertView.findViewById(R.id.txtChannelGuideVerticalTitle);
holder.description = (TextView) convertView.findViewById(R.id.txtChannelGuideVerticalDescription);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
DateFormat df = DateFormat.getInstance();
Calendar cal = Calendar.getInstance();
cal.setTime(programs[position].getStartTime().getTime());
df.setCalendar(cal);
TProgramDetails program = programs[position];
String stime = DateUtils.formatDate(program.getStartTime().getTime(),"HH:mm");
holder.startTime.setText(stime);
holder.title.setText(program.getTitle() + ((program.getScheduled())?((program.getCanceled())?" (C)":" (R)"):""));
Boolean serial = false;
Boolean bezSerie = true;
//zjisteni, zda je program serialem
if(program.getEpisodeNumber() != null){
serial = true;
if(program.getEpisodeNumber() != null) {
bezSerie = false;
}
}
if (serial == false)
{
//Porad neni serial, nevypisuji epizody, pouze popis
holder.description.setText(program.getCategory());
}
else
{
//Porad je serial, vypisuji epizody a pak popis
holder.description.setText("S" + program.getSeriesNumber().toString() + "E" + program.getEpisodeNumber().toString());
}
return convertView;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ServerConnector sc = ((ServerConnector) this.getApplication());
try{
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
String guideChannelId = extras.getString("guideChannelId");
setListAdapter(new EfficientAdapter(this, guideChannelId,sc));
}
else {
setListAdapter(new EfficientAdapter(this, "6fca9fa0-2337-487e-a945-072401cfbb3c",sc));
}
}
catch (Exception e)
{
}
}
/* (non-Javadoc)
* @see android.app.Activity#onStart()
*/
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
}
|