mirror of
				https://github.com/bspeice/UNCCGameDay
				synced 2025-11-04 02:10:35 -05:00 
			
		
		
		
	Add basic twitter functionality
This commit is contained in:
		@ -1,5 +1,14 @@
 | 
			
		||||
package com.uncc.gameday.activities;
 | 
			
		||||
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import twitter4j.Paging;
 | 
			
		||||
import twitter4j.Status;
 | 
			
		||||
import twitter4j.Twitter;
 | 
			
		||||
import twitter4j.TwitterException;
 | 
			
		||||
import twitter4j.TwitterFactory;
 | 
			
		||||
 | 
			
		||||
import com.uncc.gameday.R;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
@ -11,6 +20,7 @@ import android.widget.Toast;
 | 
			
		||||
public class Alerts extends MenuActivity {
 | 
			
		||||
	
 | 
			
		||||
	Context ctx;
 | 
			
		||||
	int maxTweets = 5; // Most tweets at a time from any source
 | 
			
		||||
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
@ -40,15 +50,68 @@ public class Alerts extends MenuActivity {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchOrganizationAlerts() {
 | 
			
		||||
		// Process fetching organization alerts (alerts retweeted by us) 
 | 
			
		||||
		// Process fetching organization alerts (alerts retweeted by us)
 | 
			
		||||
		int duration = Toast.LENGTH_SHORT;
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			String handle = 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
 | 
			
		||||
			
 | 
			
		||||
		} catch (TwitterException e) {
 | 
			
		||||
			Toast.makeText(this.ctx, "Unable to fetch alerts for organizations!\nAre you connected to the internet?", duration).show();
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchUniversityAlerts() {
 | 
			
		||||
		// Process fetching university alerts
 | 
			
		||||
		int duration = Toast.LENGTH_SHORT;
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			String handle = 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
 | 
			
		||||
			
 | 
			
		||||
		} catch (TwitterException e) {
 | 
			
		||||
			Toast.makeText(this.ctx, "Unable to fetch alerts for the University!\nAre you connected to the internet?", duration).show();
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchGamedayAlerts() {
 | 
			
		||||
		// Process fetching alerts generated by staff of UNCCGameDay
 | 
			
		||||
		int duration = Toast.LENGTH_SHORT;
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			String handle = 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.
 | 
			
		||||
			
 | 
			
		||||
		} catch (TwitterException e) {
 | 
			
		||||
			Toast.makeText(this.ctx, "Unable to fetch alerts from Gameday!\nAre you connected to the internet?", duration).show();
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void onClickTimedAlerts(View view) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user