Browse Source

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
agk512 5 years ago
parent
commit
c843d7f337

+ 2
- 2
.classpath View File

@@ -1,9 +1,9 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <classpath>
3
-	<classpathentry kind="src" path="src"/>
4
-	<classpathentry kind="src" path="gen"/>
5 3
 	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6 4
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7 5
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
6
+	<classpathentry kind="src" path="src"/>
7
+	<classpathentry kind="src" path="gen"/>
8 8
 	<classpathentry kind="output" path="bin/classes"/>
9 9
 </classpath>

+ 74
- 7
src/com/uncc/gameday/alerts/AlertFetcher.java View File

@@ -1,5 +1,6 @@
1 1
 package com.uncc.gameday.alerts;
2 2
 
3
+import java.util.Date;
3 4
 import java.util.Iterator;
4 5
 import java.util.List;
5 6
 
@@ -8,6 +9,9 @@ import twitter4j.Status;
8 9
 import twitter4j.Twitter;
9 10
 import twitter4j.TwitterException;
10 11
 import twitter4j.TwitterFactory;
12
+import twitter4j.conf.ConfigurationBuilder;
13
+import android.app.Activity;
14
+import android.app.Application;
11 15
 import android.content.Context;
12 16
 import android.content.SharedPreferences;
13 17
 import android.util.Log;
@@ -18,6 +22,8 @@ import com.uncc.gameday.R;
18 22
 /**
19 23
  * The Class AlertFetcher.
20 24
  */
25
+
26
+
21 27
 public class AlertFetcher {
22 28
         // Class responsible for fetching all alerts as necessary.
23 29
         
@@ -30,8 +36,7 @@ public class AlertFetcher {
30 36
          * @param ctx the ctx
31 37
          */
32 38
         public void fetchAlerts(Context ctx) {
33
-                // Fetch all alerts. Responsible for discovering what sources need to be fetched.
34
-                
39
+                // Fetch all alerts. Responsible for discovering what sources need to be fetched.          
35 40
                 try {
36 41
                         // Note we have to use the SharedPreferences so that we have preferences no matter what activity
37 42
                         // sent us this context
@@ -50,18 +55,30 @@ public class AlertFetcher {
50 55
                         Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e);
51 56
                 }
52 57
         }
53
-        
58
+    
54 59
         /**
55 60
          * Fetch organization alerts.
56
-         *
61
+         * 
57 62
          * @param ctx the ctx
58 63
          * @throws TwitterException the twitter exception
59 64
          */
60 65
         private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
66
+        	
67
+    	    //creates configuration for twitter access
68
+    	    ConfigurationBuilder cb = new ConfigurationBuilder();
69
+    	    
70
+            cb.setDebugEnabled(true)
71
+            	.setOAuthConsumerKey("vfRa3Tr5QYaU8Jr2pKHtiA")
72
+            	.setOAuthConsumerSecret("gGRdIrhPdX2Vrg296xOvTqE4sgOISMphRmPdrGirbU")
73
+            	.setOAuthAccessToken("1912299896-uqrhDiif3oX9Ybkf8rM5pQDWN6mW4Y7vRLK47C7")
74
+            	.setOAuthAccessTokenSecret("kZ11I74dcA00pWgQDZelFQz1ADJJMK0ejr6snnU34jUVT");
75
+            
76
+            TwitterFactory tf = new TwitterFactory(cb.build());
77
+            
61 78
                 // Process fetching organization alerts (alerts retweeted by us)
62 79
                 // Will not necessarily fetch `maxTweets` tweets.
63 80
                 String handle = ctx.getString(R.string.gameday_handle);
64
-                Twitter twitter = TwitterFactory.getSingleton();
81
+                Twitter twitter = tf.getInstance();
65 82
                 List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
66 83
                 
67 84
                 // Filter for anything created by us (retweet)
@@ -71,6 +88,10 @@ public class AlertFetcher {
71 88
                                 it.remove();
72 89
                 }
73 90
                 
91
+                String type = AlertType.getValue(AlertType.ORGANIZATION);
92
+                pushToDatabase(statuses, type, ctx);
93
+                
94
+                
74 95
                 // List contains all valid alerts now
75 96
         }
76 97
         
@@ -83,10 +104,26 @@ public class AlertFetcher {
83 104
         private void fetchUniversityAlerts(Context ctx) throws TwitterException {
84 105
                 // Process fetching university alerts
85 106
                 // Guaranteed to get `maxTweets` tweets
107
+        	
108
+    	    //creates configuration for twitter access
109
+    	    ConfigurationBuilder cb = new ConfigurationBuilder();
110
+    	    
111
+            cb.setDebugEnabled(true)
112
+            	.setOAuthConsumerKey("vfRa3Tr5QYaU8Jr2pKHtiA")
113
+            	.setOAuthConsumerSecret("gGRdIrhPdX2Vrg296xOvTqE4sgOISMphRmPdrGirbU")
114
+            	.setOAuthAccessToken("1912299896-uqrhDiif3oX9Ybkf8rM5pQDWN6mW4Y7vRLK47C7")
115
+            	.setOAuthAccessTokenSecret("kZ11I74dcA00pWgQDZelFQz1ADJJMK0ejr6snnU34jUVT");
116
+            
117
+            TwitterFactory tf = new TwitterFactory(cb.build());
118
+            
86 119
                 String handle = ctx.getString(R.string.university_handle);
87
-                Twitter twitter = TwitterFactory.getSingleton();
120
+                Twitter twitter = tf.getInstance();
88 121
                 List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
89 122
                 
123
+                String type = AlertType.getValue(AlertType.UNIVERSITY);
124
+                pushToDatabase(statuses, type, ctx);
125
+                
126
+                System.out.println(statuses.get(0).getText());
90 127
                 // List contains all valid alerts now
91 128
         }
92 129
         
@@ -99,8 +136,20 @@ public class AlertFetcher {
99 136
         private void fetchGamedayAlerts(Context ctx) throws TwitterException {
100 137
                 // Process fetching alerts generated by staff of UNCCGameDay
101 138
                 // Not guaranteed to get `maxTweets` tweets
139
+        	
140
+        	    //creates configuration for twitter access
141
+        	    ConfigurationBuilder cb = new ConfigurationBuilder();
142
+        	    
143
+                cb.setDebugEnabled(true)
144
+                	.setOAuthConsumerKey("vfRa3Tr5QYaU8Jr2pKHtiA")
145
+                	.setOAuthConsumerSecret("gGRdIrhPdX2Vrg296xOvTqE4sgOISMphRmPdrGirbU")
146
+                	.setOAuthAccessToken("1912299896-uqrhDiif3oX9Ybkf8rM5pQDWN6mW4Y7vRLK47C7")
147
+                	.setOAuthAccessTokenSecret("kZ11I74dcA00pWgQDZelFQz1ADJJMK0ejr6snnU34jUVT");
148
+                
149
+                TwitterFactory tf = new TwitterFactory(cb.build());
150
+            
102 151
                 String handle = ctx.getString(R.string.gameday_handle);
103
-                Twitter twitter = TwitterFactory.getSingleton();
152
+                Twitter twitter = tf.getInstance();
104 153
                 List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
105 154
                 
106 155
                 // Filter out anything not from us
@@ -110,7 +159,25 @@ public class AlertFetcher {
110 159
                                 it.remove();
111 160
                 }
112 161
                 
162
+                String type = AlertType.getValue(AlertType.GAMEDAY);
163
+                pushToDatabase(statuses, type, ctx);
164
+
113 165
                 // List contains all valid alerts now.
114 166
 
115 167
         }
168
+        
169
+        //takes list of statuses
170
+        //converts it to Alert object type
171
+        //and persists to database
172
+        public void pushToDatabase(List<Status> statuses, String type, Context ctx)
173
+        {
174
+    		AlertDB db = new AlertDB(ctx);
175
+        	Date todayDate = new Date();
176
+        	todayDate.getTime();
177
+        	for(int i = 0; i < statuses.size(); i++)
178
+        	{
179
+        		Alert temp = new Alert(todayDate, statuses.get(i).getText(), 0, type);
180
+        		db.persist(temp);
181
+        	}
182
+        }
116 183
 }

+ 1
- 1
src/com/uncc/gameday/alerts/AlertService.java View File

@@ -18,7 +18,7 @@ public class AlertService extends IntentService {
18 18
 	@Override
19 19
 	protected void onHandleIntent(Intent intent) {
20 20
 		// Go fetch all the alerts!
21
-		//new AlertFetcher().fetchAlerts(this);
21
+		new AlertFetcher().fetchAlerts(this);
22 22
 	
23 23
 		//if first application run, create and store
24 24
 		//timed alerts into database

Loading…
Cancel
Save