AlertDB being re-commited to Git

This commit is contained in:
agk512
2013-11-21 14:03:23 -05:00
parent c6e0587f1d
commit a06aa20207
7 changed files with 342 additions and 223 deletions

View File

@ -19,109 +19,98 @@ import com.uncc.gameday.R;
* The Class AlertFetcher.
*/
public class AlertFetcher {
// Class responsible for fetching all alerts as necessary.
/** The max tweets. */
private int maxTweets = 5;
/**
* Fetch alerts.
*
* @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 organization alerts.
*
* @param ctx the ctx
* @throws TwitterException the twitter exception
*/
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
// Process fetching organization alerts (alerts retweeted by us)
// Will not necessarily fetch `maxTweets` tweets.
String handle = ctx.getString(R.string.gameday_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// Filter for anything created by us (retweet)
for (Iterator<Status> 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
}
/**
* Fetch university alerts.
*
* @param ctx the ctx
* @throws TwitterException the twitter exception
*/
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
// Process fetching university alerts
// Guaranteed to get `maxTweets` tweets
String handle = ctx.getString(R.string.university_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// List contains all valid alerts now
}
/**
* 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);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// Filter out anything not from us
for (Iterator<Status> 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.
// Class responsible for fetching all alerts as necessary.
/** The max tweets. */
private int maxTweets = 5;
/**
* Fetch alerts.
*
* @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 organization alerts.
*
* @param ctx the ctx
* @throws TwitterException the twitter exception
*/
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
// Process fetching organization alerts (alerts retweeted by us)
// Will not necessarily fetch `maxTweets` tweets.
String handle = ctx.getString(R.string.gameday_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// Filter for anything created by us (retweet)
for (Iterator<Status> 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
}
/**
* Fetch university alerts.
*
* @param ctx the ctx
* @throws TwitterException the twitter exception
*/
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
// Process fetching university alerts
// Guaranteed to get `maxTweets` tweets
String handle = ctx.getString(R.string.university_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// List contains all valid alerts now
}
/**
* 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);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// Filter out anything not from us
for (Iterator<Status> 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.
}
/**
* Creates the timed alerts.
*
* @param ctx the ctx
* @return the list
*/
public static List<Alert> createTimedAlerts(Context ctx) {
// Create the timed alerts so we can add or remove them from the DB
return null;
}
}
}
}