From e71f859c051d35cac2f1674a63671a11c524c382 Mon Sep 17 00:00:00 2001 From: bspeice Date: Sun, 8 Dec 2013 20:43:43 -0500 Subject: [PATCH 1/4] Display the Toast message for internet down correctly --- src/com/uncc/gameday/activities/Search.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/com/uncc/gameday/activities/Search.java b/src/com/uncc/gameday/activities/Search.java index 80357b9..c32740f 100644 --- a/src/com/uncc/gameday/activities/Search.java +++ b/src/com/uncc/gameday/activities/Search.java @@ -47,8 +47,13 @@ public class Search extends MenuActivity { rsvpList = client.listAttendees(); listFetched = true; } 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("Search", e.getMessage()); } From 2a366c5e43275169a16bbc6901c7761276c8815c Mon Sep 17 00:00:00 2001 From: bspeice Date: Sun, 8 Dec 2013 20:46:34 -0500 Subject: [PATCH 2/4] Minor tweak --- src/com/uncc/gameday/activities/parking/LotViewFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/uncc/gameday/activities/parking/LotViewFragment.java b/src/com/uncc/gameday/activities/parking/LotViewFragment.java index 35b3a65..87a5278 100644 --- a/src/com/uncc/gameday/activities/parking/LotViewFragment.java +++ b/src/com/uncc/gameday/activities/parking/LotViewFragment.java @@ -55,7 +55,7 @@ public class LotViewFragment extends DialogFragment { Bundle args = this.getArguments(); if (args.containsKey("CHOICE")) - pc = ParkingChoice.valueOf(String.valueOf((char[])args.get("CHOICE"))); + pc = ParkingChoice.valueOf(String.valueOf(args.get("CHOICE"))); else pc = ParkingChoice.BLACK; From 90f149b51a07ea1bac87c8fc25d3a54a0f1ee82c Mon Sep 17 00:00:00 2001 From: bspeice Date: Sun, 8 Dec 2013 20:47:45 -0500 Subject: [PATCH 3/4] Display the toast correctly in the Registration page if internet is down --- src/com/uncc/gameday/activities/Registration.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/com/uncc/gameday/activities/Registration.java b/src/com/uncc/gameday/activities/Registration.java index 4f8c536..2d6e629 100644 --- a/src/com/uncc/gameday/activities/Registration.java +++ b/src/com/uncc/gameday/activities/Registration.java @@ -120,7 +120,11 @@ public class Registration extends MenuActivity { RegistrationClient client = new RegistrationClient(c); client.registerAttendee(a); } 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()); } } From b9de3ac52935e8023748a61b66c4440d9cdbdd49 Mon Sep 17 00:00:00 2001 From: bspeice Date: Sun, 8 Dec 2013 20:52:29 -0500 Subject: [PATCH 4/4] Fetch University and UNCC alerts correctly --- src/com/uncc/gameday/alerts/AlertFetcher.java | 244 +++++++++--------- 1 file changed, 125 insertions(+), 119 deletions(-) diff --git a/src/com/uncc/gameday/alerts/AlertFetcher.java b/src/com/uncc/gameday/alerts/AlertFetcher.java index 2e493cd..85146bd 100644 --- a/src/com/uncc/gameday/alerts/AlertFetcher.java +++ b/src/com/uncc/gameday/alerts/AlertFetcher.java @@ -16,125 +16,131 @@ import com.uncc.gameday.twitter.TwitterClient; * The Class AlertFetcher. */ public class AlertFetcher { - // Class responsible for fetching all alerts as necessary. - - /** The max tweets. */ - private int maxTweets = 5; - - /** - * Fetch all alerts - Twitter, timed, etc. - * - * @param ctx the ctx - */ - public void fetchAlerts(Context ctx) { - // Fetch all alerts. Responsible for discovering what sources need to be fetched. - try { - // 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 - this.fetchOrganizationAlerts(ctx); - if (settings.getBoolean("ALERT_UNIVERSITY", false)) - // Fetch university alerts - this.fetchUniversityAlerts(ctx); - - // And always fetch alerts made by us. Period. - this.fetchGamedayAlerts(ctx); - } catch (TwitterException e) { - Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e); - } - } - - /** - * Fetch all Organization alerts from Twitter - * - * @param ctx - The Context needed to access the Internet - * @throws TwitterException - Error in using the Twitter API - */ - private void fetchOrganizationAlerts(Context ctx) throws TwitterException { - // Process fetching organization alerts (alerts retweeted by us) - // Guaranteed to return <= maxTweets - String handle = ctx.getString(R.string.gameday_handle); - TwitterClient tc = new TwitterClient(); - List statuses = tc.fetchTweets(handle, maxTweets); - - // Filter for anything created by us (retweet) - for (Iterator it = statuses.iterator(); it.hasNext();){ - // May need to switch to isRetweetByMe, not sure if - // We're using the right function (documentation is awful) - if (!it.next().isRetweet()) - it.remove(); - } - - String type = AlertType.getValue(AlertType.ORGANIZATION); - pushToDatabase(statuses, type, ctx); - - - // 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); - TwitterClient tc = new TwitterClient(); - List 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); - TwitterClient tc = new TwitterClient(); - List statuses = tc.fetchTweets(handle, maxTweets); - - // Filter out anything not from us - for (Iterator it = statuses.iterator(); it.hasNext();){ - // May need to switch to isRetweetByMe (documentation is awful) - if (it.next().isRetweet()) - it.remove(); - } - - String type = AlertType.getValue(AlertType.GAMEDAY); - pushToDatabase(statuses, type, ctx); + // Class responsible for fetching all alerts as necessary. - // List contains all valid alerts now. + /** The max tweets. */ + private int maxTweets = 5; - } - - //takes list of statuses - //converts it to Alert object type - //and persists to database - public void pushToDatabase(List 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, type); - db.persist(temp); - } - } + /** + * Fetch all alerts - Twitter, timed, etc. + * + * @param ctx + * the ctx + */ + public void fetchAlerts(Context ctx) { + // Fetch all alerts. Responsible for discovering what sources need to be + // fetched. + try { + // 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 + + // Fetch organization alerts + this.fetchOrganizationAlerts(ctx); + // Fetch university alerts + this.fetchUniversityAlerts(ctx); + // And always fetch alerts made by us. Period. + + this.fetchGamedayAlerts(ctx); + } catch (TwitterException e) { + Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e); + } + } + + /** + * Fetch all Organization alerts from Twitter + * + * @param ctx + * - The Context needed to access the Internet + * @throws TwitterException + * - Error in using the Twitter API + */ + private void fetchOrganizationAlerts(Context ctx) throws TwitterException { + // Process fetching organization alerts (alerts retweeted by us) + // Guaranteed to return <= maxTweets + String handle = ctx.getString(R.string.gameday_handle); + TwitterClient tc = new TwitterClient(); + List statuses = tc.fetchTweets(handle, maxTweets); + + // Filter for anything created by us (retweet) + for (Iterator it = statuses.iterator(); it.hasNext();) { + // May need to switch to isRetweetByMe, not sure if + // We're using the right function (documentation is awful) + if (!it.next().isRetweet()) + it.remove(); + } + + String type = AlertType.getValue(AlertType.ORGANIZATION); + pushToDatabase(statuses, type, ctx); + + // 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); + TwitterClient tc = new TwitterClient(); + List 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); + TwitterClient tc = new TwitterClient(); + List statuses = tc.fetchTweets(handle, maxTweets); + + // Filter out anything not from us + for (Iterator it = statuses.iterator(); it.hasNext();) { + // May need to switch to isRetweetByMe (documentation is awful) + if (it.next().isRetweet()) + it.remove(); + } + + String type = AlertType.getValue(AlertType.GAMEDAY); + 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 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, + type); + db.persist(temp); + } + } }