4 |
import java.util.ArrayList; |
import java.util.ArrayList; |
5 |
import java.util.List; |
import java.util.List; |
6 |
|
|
7 |
|
import android.app.Activity; |
8 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
9 |
import android.app.Dialog; |
import android.app.Dialog; |
|
import android.app.ListActivity; |
|
10 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
11 |
import android.content.DialogInterface; |
import android.content.DialogInterface; |
12 |
import android.content.Intent; |
import android.content.Intent; |
13 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
14 |
import android.os.Bundle; |
import android.os.Bundle; |
15 |
import android.util.Log; |
import android.widget.ListView; |
16 |
import android.widget.TextView; |
import android.widget.TextView; |
17 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
18 |
import dk.thoerup.traininfo.provider.TimetableProvider; |
import dk.thoerup.traininfo.provider.TimetableProvider; |
19 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
20 |
|
import static dk.thoerup.traininfo.R.string.*; |
21 |
|
|
22 |
public class TimetableList extends ListActivity { |
public class TimetableList extends Activity { |
23 |
|
|
24 |
private static final int DLG_PROGRESS = 8000; |
private static final int DLG_PROGRESS = 8000; |
25 |
DepartureBean departure; |
DepartureBean departure; |
38 |
provider = ProviderFactory.getTimetableProvider(); |
provider = ProviderFactory.getTimetableProvider(); |
39 |
|
|
40 |
adapter = new TimetableListAdapter(this); |
adapter = new TimetableListAdapter(this); |
41 |
setListAdapter(adapter); |
|
42 |
|
ListView lv = (ListView) findViewById(R.id.List); |
43 |
|
lv.setAdapter(adapter); |
44 |
|
|
45 |
|
|
46 |
Intent launchedBy = getIntent(); |
Intent launchedBy = getIntent(); |
47 |
departure = (DepartureBean) launchedBy.getSerializableExtra("departure"); |
departure = (DepartureBean) launchedBy.getSerializableExtra("departure"); |
48 |
|
|
49 |
((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber()); |
((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber()); |
50 |
((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); |
((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); |
51 |
|
((TextView)findViewById(R.id.Location)).setText(departure.getLocation()); |
52 |
((TextView)findViewById(R.id.Note)).setText(departure.getNote()); |
((TextView)findViewById(R.id.Note)).setText(departure.getNote()); |
53 |
((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString()); |
((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this)); |
54 |
|
|
55 |
|
|
56 |
if (savedInstanceState == null) { |
if (savedInstanceState == null) { |
57 |
startTimetableFetcher(); |
startTimetableFetcher(); |
68 |
outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables); |
outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables); |
69 |
} |
} |
70 |
|
|
|
/* case DLG_DETAILS: |
|
|
DepartureBean currentDeparture = departures.get(selectedItemId); |
|
|
((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime()); |
|
|
((TextView)dialog.findViewById(R.id.Train)).setText(currentDeparture.getTrainNumber()); |
|
|
((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination()); |
|
|
((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin()); |
|
|
((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation()); |
|
|
((TextView)dialog.findViewById(R.id.Updated)).setText(currentDeparture.getLastUpdateString()); |
|
|
((TextView)dialog.findViewById(R.id.Status)).setText(currentDeparture.getStatus()); |
|
|
((TextView)dialog.findViewById(R.id.Note)).setText(currentDeparture.getNote()); |
|
|
detailsDialog = dialog; |
|
|
break; |
|
|
|
|
|
*/ |
|
71 |
|
|
72 |
@Override |
@Override |
73 |
protected void onPrepareDialog(int id, Dialog dialog) { |
protected void onPrepareDialog(int id, Dialog dialog) { |
84 |
protected Dialog onCreateDialog(int id) { |
protected Dialog onCreateDialog(int id) { |
85 |
switch (id) { |
switch (id) { |
86 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
87 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
88 |
dlg.setMessage("Fetch timetable data"); |
dlg.setMessage( getString(timetablelist_fetchdata) ); |
89 |
dlg.setCancelable(true); |
dlg.setCancelable(true); |
90 |
return dlg; |
return dlg; |
91 |
default: |
default: |
112 |
if (success) { |
if (success) { |
113 |
adapter.setTimetable(timetables); |
adapter.setTimetable(timetables); |
114 |
if (timetables.size() == 0) { |
if (timetables.size() == 0) { |
115 |
MessageBox.showMessage(TimetableList.this, "No timetable found"); |
MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata)); |
116 |
} |
} |
117 |
} else { // communication or parse error |
} else { // communication or parse error |
118 |
AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); |
119 |
builder.setMessage("Error finding departures"); |
builder.setMessage(getString(timetablelist_fetcherror)); |
120 |
builder.setCancelable(true); |
builder.setCancelable(true); |
121 |
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
122 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
123 |
dialog.dismiss(); |
dialog.dismiss(); |
124 |
startTimetableFetcher(); |
startTimetableFetcher(); |
125 |
|
|
126 |
} |
} |
127 |
}); |
}); |
128 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
129 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
130 |
dialog.dismiss(); |
dialog.dismiss(); |
131 |
} |
} |
139 |
protected Void doInBackground(String... arg0) { |
protected Void doInBackground(String... arg0) { |
140 |
String trainID = arg0[0]; |
String trainID = arg0[0]; |
141 |
success = provider.lookupTimetable(trainID); |
success = provider.lookupTimetable(trainID); |
142 |
timetables = provider.getTimetable(); |
timetables = provider.getTimetable(trainID); |
143 |
|
|
144 |
return null; |
return null; |
145 |
} |
} |