This commit is contained in:
Felix X. Fant 2013-12-08 21:10:42 -05:00
commit 5a47a5d07a
4 changed files with 138 additions and 123 deletions

View File

@ -120,7 +120,11 @@ public class Registration extends MenuActivity {
RegistrationClient client = new RegistrationClient(c); RegistrationClient client = new RegistrationClient(c);
client.registerAttendee(a); client.registerAttendee(a);
} catch (RetrofitError e) { } catch (RetrofitError e) {
Toast.makeText(c, R.string.internet_down_error, Toast.LENGTH_SHORT).show(); runOnUiThread(new Thread(){
public void run(){
Toast.makeText(c, R.string.internet_down_error, Toast.LENGTH_SHORT).show();
}
});
Log.e("Registration", e.getLocalizedMessage()); Log.e("Registration", e.getLocalizedMessage());
} }
} }

View File

@ -47,8 +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, runOnUiThread(new Thread(){
Toast.LENGTH_SHORT).show(); public void run(){
Toast.makeText(c, R.string.internet_down_error,
Toast.LENGTH_SHORT).show();
}
});
Log.e("Search", e.getMessage()); Log.e("Search", e.getMessage());
} }

View File

@ -55,7 +55,7 @@ public class LotViewFragment extends DialogFragment {
Bundle args = this.getArguments(); Bundle args = this.getArguments();
if (args.containsKey("CHOICE")) if (args.containsKey("CHOICE"))
pc = ParkingChoice.valueOf(String.valueOf((char[])args.get("CHOICE"))); pc = ParkingChoice.valueOf(String.valueOf(args.get("CHOICE")));
else else
pc = ParkingChoice.BLACK; pc = ParkingChoice.BLACK;

View File

@ -16,125 +16,131 @@ import com.uncc.gameday.twitter.TwitterClient;
* The Class AlertFetcher. * The Class AlertFetcher.
*/ */
public class AlertFetcher { public class AlertFetcher {
// Class responsible for fetching all alerts as necessary. // Class responsible for fetching all alerts as necessary.
/** The max tweets. */ /** The max tweets. */
private int maxTweets = 5; private int maxTweets = 5;
/** /**
* Fetch all alerts - Twitter, timed, etc. * Fetch all alerts - Twitter, timed, etc.
* *
* @param ctx the ctx * @param ctx
*/ * the ctx
public void fetchAlerts(Context ctx) { */
// Fetch all alerts. Responsible for discovering what sources need to be fetched. public void fetchAlerts(Context ctx) {
try { // Fetch all alerts. Responsible for discovering what sources need to be
// Note we have to use the SharedPreferences so that we have preferences no matter what activity // fetched.
// sent us this context try {
SharedPreferences settings = ctx.getSharedPreferences(ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE // Note we have to use the SharedPreferences so that we have
// preferences no matter what activity
// sent us this context
SharedPreferences settings = ctx.getSharedPreferences(
ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE
if (settings.getBoolean("ALERT_ORGANIZATION", false)) // Fetch organization alerts
// Fetch organization alerts this.fetchOrganizationAlerts(ctx);
this.fetchOrganizationAlerts(ctx); // Fetch university alerts
if (settings.getBoolean("ALERT_UNIVERSITY", false)) this.fetchUniversityAlerts(ctx);
// Fetch university alerts // And always fetch alerts made by us. Period.
this.fetchUniversityAlerts(ctx);
// And always fetch alerts made by us. Period. this.fetchGamedayAlerts(ctx);
this.fetchGamedayAlerts(ctx); } catch (TwitterException e) {
} catch (TwitterException e) { Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e);
Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e); }
} }
}
/** /**
* Fetch all Organization alerts from Twitter * Fetch all Organization alerts from Twitter
* *
* @param ctx - The Context needed to access the Internet * @param ctx
* @throws TwitterException - Error in using the Twitter API * - The Context needed to access the Internet
*/ * @throws TwitterException
private void fetchOrganizationAlerts(Context ctx) throws TwitterException { * - Error in using the Twitter API
// Process fetching organization alerts (alerts retweeted by us) */
// Guaranteed to return <= maxTweets private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
String handle = ctx.getString(R.string.gameday_handle); // Process fetching organization alerts (alerts retweeted by us)
TwitterClient tc = new TwitterClient(); // Guaranteed to return <= maxTweets
List<Status> statuses = tc.fetchTweets(handle, maxTweets); String handle = ctx.getString(R.string.gameday_handle);
TwitterClient tc = new TwitterClient();
List<Status> statuses = tc.fetchTweets(handle, maxTweets);
// Filter for anything created by us (retweet) // Filter for anything created by us (retweet)
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){ for (Iterator<Status> it = statuses.iterator(); it.hasNext();) {
// May need to switch to isRetweetByMe, not sure if // May need to switch to isRetweetByMe, not sure if
// We're using the right function (documentation is awful) // We're using the right function (documentation is awful)
if (!it.next().isRetweet()) if (!it.next().isRetweet())
it.remove(); it.remove();
} }
String type = AlertType.getValue(AlertType.ORGANIZATION); String type = AlertType.getValue(AlertType.ORGANIZATION);
pushToDatabase(statuses, type, ctx); pushToDatabase(statuses, type, ctx);
// List contains all valid alerts now
}
// List contains all valid alerts now /**
} * Fetch alerts from the University Twitter
*
* @param ctx
* - The Context for accessing the Internet
* @throws TwitterException
* - Throws an exception for misuse of Twitter API
*/
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
// Process fetching university alerts
// Guaranteed to get `maxTweets` tweets
/** String handle = ctx.getString(R.string.university_handle);
* Fetch alerts from the University Twitter TwitterClient tc = new TwitterClient();
* List<Status> statuses = tc.fetchTweets(handle, maxTweets);
* @param ctx - The Context for accessing the Internet
* @throws TwitterException - Throws an exception for misuse of Twitter API
*/
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
// Process fetching university alerts
// Guaranteed to get `maxTweets` tweets
String handle = ctx.getString(R.string.university_handle); String type = AlertType.getValue(AlertType.UNIVERSITY);
TwitterClient tc = new TwitterClient(); pushToDatabase(statuses, type, ctx);
List<Status> statuses = tc.fetchTweets(handle, maxTweets); }
String type = AlertType.getValue(AlertType.UNIVERSITY); /**
pushToDatabase(statuses, type, ctx); * Fetch gameday alerts.
} *
* @param ctx
* the ctx
* @throws TwitterException
* the twitter exception
*/
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
// Process fetching alerts generated by staff of UNCCGameDay
// Not guaranteed to get `maxTweets` tweets
/** String handle = ctx.getString(R.string.gameday_handle);
* Fetch gameday alerts. TwitterClient tc = new TwitterClient();
* List<Status> statuses = tc.fetchTweets(handle, maxTweets);
* @param ctx the ctx
* @throws TwitterException the twitter exception
*/
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
// Process fetching alerts generated by staff of UNCCGameDay
// Not guaranteed to get `maxTweets` tweets
String handle = ctx.getString(R.string.gameday_handle); // Filter out anything not from us
TwitterClient tc = new TwitterClient(); for (Iterator<Status> it = statuses.iterator(); it.hasNext();) {
List<Status> statuses = tc.fetchTweets(handle, maxTweets); // May need to switch to isRetweetByMe (documentation is awful)
if (it.next().isRetweet())
it.remove();
}
// Filter out anything not from us String type = AlertType.getValue(AlertType.GAMEDAY);
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){ pushToDatabase(statuses, type, ctx);
// May need to switch to isRetweetByMe (documentation is awful)
if (it.next().isRetweet())
it.remove();
}
String type = AlertType.getValue(AlertType.GAMEDAY); // List contains all valid alerts now.
pushToDatabase(statuses, type, ctx);
// List contains all valid alerts now. }
} // takes list of statuses
// converts it to Alert object type
// and persists to database
public void pushToDatabase(List<Status> statuses, String type, Context ctx) {
GregorianCalendar todayDate = new GregorianCalendar();
long currentDate = todayDate.getTimeInMillis();
//takes list of statuses AlertDB db = new AlertDB(ctx);
//converts it to Alert object type
//and persists to database
public void pushToDatabase(List<Status> statuses, String type, Context ctx)
{
GregorianCalendar todayDate = new GregorianCalendar();
long currentDate = todayDate.getTimeInMillis();
AlertDB db = new AlertDB(ctx); for (int i = 0; i < statuses.size(); i++) {
Alert temp = new Alert(currentDate, statuses.get(i).getText(), 0,
for(int i = 0; i < statuses.size(); i++) type);
{ db.persist(temp);
Alert temp = new Alert(currentDate, statuses.get(i).getText(), 0, type); }
db.persist(temp); }
}
}
} }