mirror of
https://github.com/bspeice/UNCCGameDay
synced 2024-11-05 07:38:13 -05:00
Fetch University and UNCC alerts correctly
This commit is contained in:
parent
90f149b51a
commit
b9de3ac529
@ -24,23 +24,25 @@ public class AlertFetcher {
|
|||||||
/**
|
/**
|
||||||
* 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) {
|
public void fetchAlerts(Context ctx) {
|
||||||
// Fetch all alerts. Responsible for discovering what sources need to be fetched.
|
// Fetch all alerts. Responsible for discovering what sources need to be
|
||||||
|
// fetched.
|
||||||
try {
|
try {
|
||||||
// Note we have to use the SharedPreferences so that we have preferences no matter what activity
|
// Note we have to use the SharedPreferences so that we have
|
||||||
|
// preferences no matter what activity
|
||||||
// sent us this context
|
// sent us this context
|
||||||
SharedPreferences settings = ctx.getSharedPreferences(ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE
|
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);
|
||||||
if (settings.getBoolean("ALERT_UNIVERSITY", false))
|
|
||||||
// Fetch university alerts
|
// Fetch university alerts
|
||||||
this.fetchUniversityAlerts(ctx);
|
this.fetchUniversityAlerts(ctx);
|
||||||
|
|
||||||
// And always fetch alerts made by us. Period.
|
// 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);
|
||||||
@ -50,8 +52,10 @@ public class AlertFetcher {
|
|||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
* - Error in using the Twitter API
|
||||||
*/
|
*/
|
||||||
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
|
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
|
||||||
// Process fetching organization alerts (alerts retweeted by us)
|
// Process fetching organization alerts (alerts retweeted by us)
|
||||||
@ -61,7 +65,7 @@ public class AlertFetcher {
|
|||||||
List<Status> statuses = tc.fetchTweets(handle, maxTweets);
|
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())
|
||||||
@ -71,15 +75,16 @@ public class AlertFetcher {
|
|||||||
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
|
* Fetch alerts from the University Twitter
|
||||||
*
|
*
|
||||||
* @param ctx - The Context for accessing the Internet
|
* @param ctx
|
||||||
* @throws TwitterException - Throws an exception for misuse of Twitter API
|
* - The Context for accessing the Internet
|
||||||
|
* @throws TwitterException
|
||||||
|
* - Throws an exception for misuse of Twitter API
|
||||||
*/
|
*/
|
||||||
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
|
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
|
||||||
// Process fetching university alerts
|
// Process fetching university alerts
|
||||||
@ -96,8 +101,10 @@ public class AlertFetcher {
|
|||||||
/**
|
/**
|
||||||
* Fetch gameday alerts.
|
* Fetch gameday alerts.
|
||||||
*
|
*
|
||||||
* @param ctx the ctx
|
* @param ctx
|
||||||
* @throws TwitterException the twitter exception
|
* the ctx
|
||||||
|
* @throws TwitterException
|
||||||
|
* the twitter exception
|
||||||
*/
|
*/
|
||||||
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
|
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
|
||||||
// Process fetching alerts generated by staff of UNCCGameDay
|
// Process fetching alerts generated by staff of UNCCGameDay
|
||||||
@ -108,7 +115,7 @@ public class AlertFetcher {
|
|||||||
List<Status> statuses = tc.fetchTweets(handle, maxTweets);
|
List<Status> statuses = tc.fetchTweets(handle, maxTweets);
|
||||||
|
|
||||||
// Filter out anything not from us
|
// Filter out anything not from us
|
||||||
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
|
for (Iterator<Status> it = statuses.iterator(); it.hasNext();) {
|
||||||
// May need to switch to isRetweetByMe (documentation is awful)
|
// May need to switch to isRetweetByMe (documentation is awful)
|
||||||
if (it.next().isRetweet())
|
if (it.next().isRetweet())
|
||||||
it.remove();
|
it.remove();
|
||||||
@ -121,19 +128,18 @@ public class AlertFetcher {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//takes list of statuses
|
// takes list of statuses
|
||||||
//converts it to Alert object type
|
// converts it to Alert object type
|
||||||
//and persists to database
|
// and persists to database
|
||||||
public void pushToDatabase(List<Status> statuses, String type, Context ctx)
|
public void pushToDatabase(List<Status> statuses, String type, Context ctx) {
|
||||||
{
|
|
||||||
GregorianCalendar todayDate = new GregorianCalendar();
|
GregorianCalendar todayDate = new GregorianCalendar();
|
||||||
long currentDate = todayDate.getTimeInMillis();
|
long currentDate = todayDate.getTimeInMillis();
|
||||||
|
|
||||||
AlertDB db = new AlertDB(ctx);
|
AlertDB db = new AlertDB(ctx);
|
||||||
|
|
||||||
for(int i = 0; i < statuses.size(); i++)
|
for (int i = 0; i < statuses.size(); i++) {
|
||||||
{
|
Alert temp = new Alert(currentDate, statuses.get(i).getText(), 0,
|
||||||
Alert temp = new Alert(currentDate, statuses.get(i).getText(), 0, type);
|
type);
|
||||||
db.persist(temp);
|
db.persist(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user