From 9fc974402b702a851b1254ffe066d4deb1ec59e8 Mon Sep 17 00:00:00 2001 From: bspeice Date: Wed, 9 Oct 2013 19:39:20 -0400 Subject: [PATCH] Add lots more skeleton --- src/com/uncc/gameday/activities/Home.java | 24 ++-- src/com/uncc/gameday/alerts/AlertDB.java | 9 +- src/com/uncc/gameday/alerts/AlertFetcher.java | 129 +++++++----------- src/com/uncc/gameday/alerts/AlertService.java | 18 +++ 4 files changed, 89 insertions(+), 91 deletions(-) create mode 100644 src/com/uncc/gameday/alerts/AlertService.java diff --git a/src/com/uncc/gameday/activities/Home.java b/src/com/uncc/gameday/activities/Home.java index d28a203..d802c2a 100644 --- a/src/com/uncc/gameday/activities/Home.java +++ b/src/com/uncc/gameday/activities/Home.java @@ -1,13 +1,8 @@ package com.uncc.gameday.activities; -import java.util.List; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; - import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; import android.os.Bundle; import com.uncc.gameday.R; @@ -20,12 +15,23 @@ public class Home extends MenuActivity { setContentView(R.layout.activity_home); Context ctx = getApplicationContext(); - + this.onFirstRun(ctx); + } + + protected void onFirstRun(Context ctx) { + SharedPreferences settings = this.getPreferences(MODE_PRIVATE); + if (settings.getBoolean("FIRST_RUN", true)) { + // First run code + + Editor editor = settings.edit(); + editor.putBoolean("FIRST_RUN", false); + editor.commit(); + } } private void getRecentAlerts() { // Responsible for discovering what the most recent alerts are and showing them. // Likely should be implemented by querying a local DB of alerts, grabbing recent 20. - new AlertFetcher().fetchAlerts(); + } } diff --git a/src/com/uncc/gameday/alerts/AlertDB.java b/src/com/uncc/gameday/alerts/AlertDB.java index 5b6ac00..fd8fd13 100644 --- a/src/com/uncc/gameday/alerts/AlertDB.java +++ b/src/com/uncc/gameday/alerts/AlertDB.java @@ -24,10 +24,11 @@ public class AlertDB { // Add multiple new dates to the database } - public List fetchUnreadAlerts() { - // Get a list of all currently unread alerts - - return null; + public void deleteAlert(Alert alert) { + // Remove a date from the database } + public void deleteAlerts(List alerts) { + // Remove multiple dates from the database + } } diff --git a/src/com/uncc/gameday/alerts/AlertFetcher.java b/src/com/uncc/gameday/alerts/AlertFetcher.java index 2b3486c..ebd862f 100644 --- a/src/com/uncc/gameday/alerts/AlertFetcher.java +++ b/src/com/uncc/gameday/alerts/AlertFetcher.java @@ -10,7 +10,7 @@ import twitter4j.TwitterException; import twitter4j.TwitterFactory; import android.content.Context; import android.content.SharedPreferences; -import android.widget.Toast; +import android.util.Log; import com.uncc.gameday.R; @@ -22,96 +22,69 @@ public class AlertFetcher { public void fetchAlerts(Context ctx) { // Fetch all alerts. Responsible for discovering what sources need to be fetched. - // 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_TIMED", false)) - // Fetch timed alerts - this.fetchTimedAlerts(ctx); - else if (settings.getBoolean("ALERT_ORGANIZATION", false)) - // Fetch organization alerts - this.fetchOrganizationAlerts(ctx); - else if (settings.getBoolean("ALERT_UNIVERSITY", false)) - // Fetch university alerts - this.fetchUniversityAlerts(ctx); - - // And always fetch alerts made by us. Period. - this.fetchGamedayAlerts(ctx); + 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); + } } - private void fetchTimedAlerts(Context ctx) { - // Process the rules for all timed alerts. - } - - private void fetchOrganizationAlerts(Context ctx) { + private void fetchOrganizationAlerts(Context ctx) throws TwitterException { // Process fetching organization alerts (alerts retweeted by us) - int duration = Toast.LENGTH_SHORT; + String handle = ctx.getString(R.string.gameday_handle); + Twitter twitter = TwitterFactory.getSingleton(); + List statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets)); - try { - String handle = ctx.getString(R.string.gameday_handle); - Twitter twitter = TwitterFactory.getSingleton(); - List statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets)); - - // Filter for anything created by us (retweet) - for (Iterator it = statuses.iterator(); it.hasNext();){ - // May need to switch to isRetweetByMe (documentation is awful) - if (!it.next().isRetweet()) - it.remove(); - } - - // List contains all valid alerts now - - } catch (TwitterException e) { - Toast.makeText(ctx, - "Unable to fetch alerts for organizations!\nAre you connected to the internet?", - duration).show(); - e.printStackTrace(); + // Filter for anything created by us (retweet) + for (Iterator it = statuses.iterator(); it.hasNext();){ + // May need to switch to isRetweetByMe (documentation is awful) + if (!it.next().isRetweet()) + it.remove(); } + + // List contains all valid alerts now } - private void fetchUniversityAlerts(Context ctx) { + private void fetchUniversityAlerts(Context ctx) throws TwitterException { // Process fetching university alerts - int duration = Toast.LENGTH_SHORT; + String handle = ctx.getString(R.string.university_handle); + Twitter twitter = TwitterFactory.getSingleton(); + List statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets)); - try { - String handle = ctx.getString(R.string.university_handle); - Twitter twitter = TwitterFactory.getSingleton(); - List statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets)); - - // List contains all valid alerts now - - } catch (TwitterException e) { - Toast.makeText(ctx, - "Unable to fetch alerts for the University!\nAre you connected to the internet?", - duration).show(); - e.printStackTrace(); - } + // List contains all valid alerts now } - private void fetchGamedayAlerts(Context ctx) { + private void fetchGamedayAlerts(Context ctx) throws TwitterException { // Process fetching alerts generated by staff of UNCCGameDay - int duration = Toast.LENGTH_SHORT; + String handle = ctx.getString(R.string.gameday_handle); + Twitter twitter = TwitterFactory.getSingleton(); + List statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets)); - try { - String handle = ctx.getString(R.string.gameday_handle); - Twitter twitter = TwitterFactory.getSingleton(); - List statuses = twitter.getUserTimeline(handle, new Paging(1, 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(); - } - - // List contains all valid alerts now. - - } catch (TwitterException e) { - Toast.makeText(ctx, - "Unable to fetch alerts from Gameday!\nAre you connected to the internet?", - duration).show(); - e.printStackTrace(); + // 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(); } + + // List contains all valid alerts now. + + } + + public static List createTimedAlerts(Context ctx) { + // Create the timed alerts so we can add or remove them from the DB + return null; } } diff --git a/src/com/uncc/gameday/alerts/AlertService.java b/src/com/uncc/gameday/alerts/AlertService.java new file mode 100644 index 0000000..b899935 --- /dev/null +++ b/src/com/uncc/gameday/alerts/AlertService.java @@ -0,0 +1,18 @@ +package com.uncc.gameday.alerts; + +import android.app.IntentService; +import android.content.Intent; + +public class AlertService extends IntentService { + private static final String name = "AlertService"; + + public AlertService() { + super(name); + } + + @Override + protected void onHandleIntent(Intent intent) { + // Go fetch all the alerts! + } + +}