mirror of
https://github.com/bspeice/UNCCGameDay
synced 2024-11-04 23:28:12 -05:00
Handle the RSVP search list not connecting to the Internet
This commit is contained in:
parent
2f44e21d16
commit
a5bd595a48
@ -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<Attendee> 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<Attendee>() {
|
||||
@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<Attendee> adapter =
|
||||
new ArrayAdapter<Attendee>(c,android.R.layout.simple_list_item_1, rsvpList);
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
List<Attendee> 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<Attendee>() {
|
||||
@Override
|
||||
public int compare(Attendee a1, Attendee a2) {
|
||||
String compareName = a1.getLastName();
|
||||
String thisName = a2.getLastName();
|
||||
return compareName.compareTo(thisName);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
rsvpList = new ArrayList<Attendee>();
|
||||
}
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ListView listView = (ListView) findViewById(R.id.RSVPListView);
|
||||
ArrayAdapter<Attendee> adapter = new ArrayAdapter<Attendee>(
|
||||
c, android.R.layout.simple_list_item_1, rsvpList);
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user