From a5bd595a4896f6e5756db56a64bfc050d18bdec6 Mon Sep 17 00:00:00 2001 From: bspeice Date: Sun, 8 Dec 2013 20:39:11 -0500 Subject: [PATCH] Handle the RSVP search list not connecting to the Internet --- src/com/uncc/gameday/activities/Search.java | 117 ++++++++++---------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/src/com/uncc/gameday/activities/Search.java b/src/com/uncc/gameday/activities/Search.java index efc7634..80357b9 100644 --- a/src/com/uncc/gameday/activities/Search.java +++ b/src/com/uncc/gameday/activities/Search.java @@ -1,5 +1,6 @@ package com.uncc.gameday.activities; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -18,63 +19,63 @@ import com.uncc.gameday.registration.Attendee; import com.uncc.gameday.registration.RegistrationClient; public class Search extends MenuActivity { - - List rsvpList; - boolean listFetched = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_search_rsvp); - new fetchAttendeesThread(this).start(); - } - - private class fetchAttendeesThread extends Thread { - Context c; - public fetchAttendeesThread(Context c) { - this.c = c; - } - - public void run() { - - if (Looper.myLooper() == null) { - Looper.prepare(); - } - try { - RegistrationClient client = new RegistrationClient(this.c); - rsvpList = client.listAttendees(); - listFetched = true; - } catch (RetrofitError e) { - Toast.makeText(c, R.string.internet_down_error, Toast.LENGTH_SHORT).show(); - Log.e("Search", e.getLocalizedMessage()); - } - - //sorts RSVPList alphabetically by last name - if(rsvpList != null) - { - Collections.sort(rsvpList, new Comparator() { - @Override - public int compare(Attendee a1, Attendee a2) { - String compareName = a1.getLastName(); - String thisName = a2.getLastName(); - return compareName.compareTo(thisName); - } - }); - } - - runOnUiThread(new Runnable() { - @Override - public void run() { - ListView listView = (ListView)findViewById(R.id.RSVPListView); - ArrayAdapter adapter = - new ArrayAdapter(c,android.R.layout.simple_list_item_1, rsvpList); - listView.setAdapter(adapter); - } - }); - - - - } -} + List rsvpList; + boolean listFetched = false; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_search_rsvp); + new fetchAttendeesThread(this).start(); + } + + private class fetchAttendeesThread extends Thread { + Context c; + + public fetchAttendeesThread(Context c) { + this.c = c; + } + + public void run() { + + if (Looper.myLooper() == null) { + Looper.prepare(); + } + try { + RegistrationClient client = new RegistrationClient(this.c); + rsvpList = client.listAttendees(); + listFetched = true; + } catch (RetrofitError e) { + Toast.makeText(c, R.string.internet_down_error, + Toast.LENGTH_SHORT).show(); + Log.e("Search", e.getMessage()); + } + + // sorts RSVPList alphabetically by last name + if (rsvpList != null) { + Collections.sort(rsvpList, new Comparator() { + @Override + public int compare(Attendee a1, Attendee a2) { + String compareName = a1.getLastName(); + String thisName = a2.getLastName(); + return compareName.compareTo(thisName); + } + }); + } else { + rsvpList = new ArrayList(); + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + ListView listView = (ListView) findViewById(R.id.RSVPListView); + ArrayAdapter adapter = new ArrayAdapter( + c, android.R.layout.simple_list_item_1, rsvpList); + listView.setAdapter(adapter); + } + }); + + } + } } \ No newline at end of file