Handle the RSVP search list not connecting to the Internet

This commit is contained in:
bspeice 2013-12-08 20:39:11 -05:00
parent 2f44e21d16
commit a5bd595a48

View File

@ -1,5 +1,6 @@
package com.uncc.gameday.activities; package com.uncc.gameday.activities;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -31,6 +32,7 @@ public class Search extends MenuActivity {
private class fetchAttendeesThread extends Thread { private class fetchAttendeesThread extends Thread {
Context c; Context c;
public fetchAttendeesThread(Context c) { public fetchAttendeesThread(Context c) {
this.c = c; this.c = c;
} }
@ -45,13 +47,13 @@ public class Search extends MenuActivity {
rsvpList = client.listAttendees(); rsvpList = client.listAttendees();
listFetched = true; listFetched = true;
} catch (RetrofitError e) { } catch (RetrofitError e) {
Toast.makeText(c, R.string.internet_down_error, Toast.LENGTH_SHORT).show(); Toast.makeText(c, R.string.internet_down_error,
Log.e("Search", e.getLocalizedMessage()); Toast.LENGTH_SHORT).show();
Log.e("Search", e.getMessage());
} }
// sorts RSVPList alphabetically by last name // sorts RSVPList alphabetically by last name
if(rsvpList != null) if (rsvpList != null) {
{
Collections.sort(rsvpList, new Comparator<Attendee>() { Collections.sort(rsvpList, new Comparator<Attendee>() {
@Override @Override
public int compare(Attendee a1, Attendee a2) { public int compare(Attendee a1, Attendee a2) {
@ -60,21 +62,20 @@ public class Search extends MenuActivity {
return compareName.compareTo(thisName); return compareName.compareTo(thisName);
} }
}); });
} else {
rsvpList = new ArrayList<Attendee>();
} }
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
ListView listView = (ListView) findViewById(R.id.RSVPListView); ListView listView = (ListView) findViewById(R.id.RSVPListView);
ArrayAdapter<Attendee> adapter = ArrayAdapter<Attendee> adapter = new ArrayAdapter<Attendee>(
new ArrayAdapter<Attendee>(c,android.R.layout.simple_list_item_1, rsvpList); c, android.R.layout.simple_list_item_1, rsvpList);
listView.setAdapter(adapter); listView.setAdapter(adapter);
} }
}); });
} }
} }
} }