mirror of
https://github.com/bspeice/UNCCGameDay
synced 2024-12-04 13:58:11 -05:00
Twitter Alerts now feeding into AlertDB >AGK
Twitter Alerts are now feeding into AlertDB properly, and are being displayed in both drop down notification and main page alert list. AGK
This commit is contained in:
parent
7471118550
commit
c843d7f337
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.uncc.gameday.alerts;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -8,6 +9,9 @@ import twitter4j.Status;
|
||||
import twitter4j.Twitter;
|
||||
import twitter4j.TwitterException;
|
||||
import twitter4j.TwitterFactory;
|
||||
import twitter4j.conf.ConfigurationBuilder;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
@ -18,6 +22,8 @@ import com.uncc.gameday.R;
|
||||
/**
|
||||
* The Class AlertFetcher.
|
||||
*/
|
||||
|
||||
|
||||
public class AlertFetcher {
|
||||
// Class responsible for fetching all alerts as necessary.
|
||||
|
||||
@ -31,7 +37,6 @@ public class AlertFetcher {
|
||||
*/
|
||||
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
|
||||
@ -58,10 +63,22 @@ public class AlertFetcher {
|
||||
* @throws TwitterException the twitter exception
|
||||
*/
|
||||
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
|
||||
|
||||
//creates configuration for twitter access
|
||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||
|
||||
cb.setDebugEnabled(true)
|
||||
.setOAuthConsumerKey("vfRa3Tr5QYaU8Jr2pKHtiA")
|
||||
.setOAuthConsumerSecret("gGRdIrhPdX2Vrg296xOvTqE4sgOISMphRmPdrGirbU")
|
||||
.setOAuthAccessToken("1912299896-uqrhDiif3oX9Ybkf8rM5pQDWN6mW4Y7vRLK47C7")
|
||||
.setOAuthAccessTokenSecret("kZ11I74dcA00pWgQDZelFQz1ADJJMK0ejr6snnU34jUVT");
|
||||
|
||||
TwitterFactory tf = new TwitterFactory(cb.build());
|
||||
|
||||
// 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();
|
||||
Twitter twitter = tf.getInstance();
|
||||
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
||||
|
||||
// Filter for anything created by us (retweet)
|
||||
@ -71,6 +88,10 @@ public class AlertFetcher {
|
||||
it.remove();
|
||||
}
|
||||
|
||||
String type = AlertType.getValue(AlertType.ORGANIZATION);
|
||||
pushToDatabase(statuses, type, ctx);
|
||||
|
||||
|
||||
// List contains all valid alerts now
|
||||
}
|
||||
|
||||
@ -83,10 +104,26 @@ public class AlertFetcher {
|
||||
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
|
||||
// Process fetching university alerts
|
||||
// Guaranteed to get `maxTweets` tweets
|
||||
|
||||
//creates configuration for twitter access
|
||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||
|
||||
cb.setDebugEnabled(true)
|
||||
.setOAuthConsumerKey("vfRa3Tr5QYaU8Jr2pKHtiA")
|
||||
.setOAuthConsumerSecret("gGRdIrhPdX2Vrg296xOvTqE4sgOISMphRmPdrGirbU")
|
||||
.setOAuthAccessToken("1912299896-uqrhDiif3oX9Ybkf8rM5pQDWN6mW4Y7vRLK47C7")
|
||||
.setOAuthAccessTokenSecret("kZ11I74dcA00pWgQDZelFQz1ADJJMK0ejr6snnU34jUVT");
|
||||
|
||||
TwitterFactory tf = new TwitterFactory(cb.build());
|
||||
|
||||
String handle = ctx.getString(R.string.university_handle);
|
||||
Twitter twitter = TwitterFactory.getSingleton();
|
||||
Twitter twitter = tf.getInstance();
|
||||
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
||||
|
||||
String type = AlertType.getValue(AlertType.UNIVERSITY);
|
||||
pushToDatabase(statuses, type, ctx);
|
||||
|
||||
System.out.println(statuses.get(0).getText());
|
||||
// List contains all valid alerts now
|
||||
}
|
||||
|
||||
@ -99,8 +136,20 @@ public class AlertFetcher {
|
||||
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
|
||||
// Process fetching alerts generated by staff of UNCCGameDay
|
||||
// Not guaranteed to get `maxTweets` tweets
|
||||
|
||||
//creates configuration for twitter access
|
||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||
|
||||
cb.setDebugEnabled(true)
|
||||
.setOAuthConsumerKey("vfRa3Tr5QYaU8Jr2pKHtiA")
|
||||
.setOAuthConsumerSecret("gGRdIrhPdX2Vrg296xOvTqE4sgOISMphRmPdrGirbU")
|
||||
.setOAuthAccessToken("1912299896-uqrhDiif3oX9Ybkf8rM5pQDWN6mW4Y7vRLK47C7")
|
||||
.setOAuthAccessTokenSecret("kZ11I74dcA00pWgQDZelFQz1ADJJMK0ejr6snnU34jUVT");
|
||||
|
||||
TwitterFactory tf = new TwitterFactory(cb.build());
|
||||
|
||||
String handle = ctx.getString(R.string.gameday_handle);
|
||||
Twitter twitter = TwitterFactory.getSingleton();
|
||||
Twitter twitter = tf.getInstance();
|
||||
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
||||
|
||||
// Filter out anything not from us
|
||||
@ -110,7 +159,25 @@ public class AlertFetcher {
|
||||
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<Status> statuses, String type, Context ctx)
|
||||
{
|
||||
AlertDB db = new AlertDB(ctx);
|
||||
Date todayDate = new Date();
|
||||
todayDate.getTime();
|
||||
for(int i = 0; i < statuses.size(); i++)
|
||||
{
|
||||
Alert temp = new Alert(todayDate, statuses.get(i).getText(), 0, type);
|
||||
db.persist(temp);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ public class AlertService extends IntentService {
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
// Go fetch all the alerts!
|
||||
//new AlertFetcher().fetchAlerts(this);
|
||||
new AlertFetcher().fetchAlerts(this);
|
||||
|
||||
//if first application run, create and store
|
||||
//timed alerts into database
|
||||
|
Loading…
Reference in New Issue
Block a user