27 |
public class DepartureList extends ListActivity { |
public class DepartureList extends ListActivity { |
28 |
|
|
29 |
public static final int DLG_PROGRESS = 1; |
public static final int DLG_PROGRESS = 1; |
30 |
public static final int DLG_DETAILS = 2; |
|
31 |
|
|
32 |
DepartureListAdapter adapter; |
DepartureListAdapter adapter; |
33 |
DepartureProvider provider; |
DepartureProvider provider; |
37 |
//DepartureBean currentDeparture; |
//DepartureBean currentDeparture; |
38 |
|
|
39 |
ProgressDialog pgDialog; |
ProgressDialog pgDialog; |
40 |
Dialog detailsDialog; |
|
41 |
DepartureFetcher fetcher; |
DepartureFetcher fetcher; |
42 |
int stationId; |
int stationId; |
43 |
|
|
82 |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
83 |
adapter.setDepartures(departures); |
adapter.setDepartures(departures); |
84 |
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
|
boolean detailsShowing = savedInstanceState.getBoolean("detailsShowing"); |
|
|
if (detailsShowing) |
|
|
showDialog(DLG_DETAILS); |
|
85 |
} |
} |
86 |
} |
} |
87 |
|
|
90 |
{ |
{ |
91 |
if (pgDialog != null && pgDialog.isShowing()) |
if (pgDialog != null && pgDialog.isShowing()) |
92 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
93 |
boolean detailsShowing = (detailsDialog != null && detailsDialog.isShowing()); |
|
|
if (detailsShowing) { |
|
|
dismissDialog(DLG_DETAILS); |
|
|
} |
|
|
outState.putBoolean("detailsShowing", detailsShowing); |
|
94 |
outState.putInt("selectedItemId", selectedItemId); |
outState.putInt("selectedItemId", selectedItemId); |
95 |
|
|
96 |
outState.putSerializable("departures", (ArrayList<DepartureBean>) departures); |
outState.putSerializable("departures", (ArrayList<DepartureBean>) departures); |
99 |
@Override |
@Override |
100 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
101 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
102 |
|
|
103 |
|
selectedItemId = position; |
104 |
|
|
105 |
selectedItemId = position; |
Intent intent = new Intent(this, TimetableList.class); |
106 |
showDialog(DLG_DETAILS); |
intent.putExtra("asd", 0); //Add all necessary data |
107 |
|
|
108 |
|
startActivity(intent); |
109 |
|
|
110 |
} |
} |
111 |
|
|
112 |
|
|
115 |
super.onPrepareDialog(id, dialog); |
super.onPrepareDialog(id, dialog); |
116 |
|
|
117 |
switch (id) { |
switch (id) { |
|
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; |
|
118 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
119 |
pgDialog = (ProgressDialog) dialog; |
pgDialog = (ProgressDialog) dialog; |
120 |
break; |
break; |
128 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
129 |
dlg.setMessage("Fetch departure data"); |
dlg.setMessage("Fetch departure data"); |
130 |
dlg.setCancelable(true); |
dlg.setCancelable(true); |
131 |
return dlg; |
return dlg; |
|
case DLG_DETAILS: |
|
|
//Context mContext = getApplicationContext(); |
|
|
Dialog dialog = new Dialog(this); |
|
|
dialog.setCancelable(true); |
|
|
|
|
|
dialog.setContentView(R.layout.departuredetails); |
|
|
dialog.setTitle("Departure details"); |
|
|
|
|
|
View root = dialog.findViewById(R.id.layout_root); |
|
|
root.setOnClickListener( new DialogDismisser(dialog) ); |
|
|
return dialog; |
|
132 |
default: |
default: |
133 |
return super.onCreateDialog(id); |
return super.onCreateDialog(id); |
134 |
} |
} |