mirror of
				https://github.com/bspeice/UNCCGameDay
				synced 2025-11-04 02:10:35 -05:00 
			
		
		
		
	Add lots more skeleton
This commit is contained in:
		@ -24,10 +24,11 @@ public class AlertDB {
 | 
			
		||||
		// Add multiple new dates to the database
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public List<Alert> fetchUnreadAlerts() {
 | 
			
		||||
		// Get a list of all currently unread alerts
 | 
			
		||||
		
 | 
			
		||||
		return null;
 | 
			
		||||
	public void deleteAlert(Alert alert) {
 | 
			
		||||
		// Remove a date from the database
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void deleteAlerts(List<Alert> alerts) {
 | 
			
		||||
		// Remove multiple dates from the database
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ import twitter4j.TwitterException;
 | 
			
		||||
import twitter4j.TwitterFactory;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.widget.Toast;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import com.uncc.gameday.R;
 | 
			
		||||
 | 
			
		||||
@ -22,96 +22,69 @@ public class AlertFetcher {
 | 
			
		||||
	public void fetchAlerts(Context ctx) {
 | 
			
		||||
		// Fetch all alerts. Responsible for discovering what sources need to be fetched.
 | 
			
		||||
		
 | 
			
		||||
		// 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_TIMED", false))
 | 
			
		||||
			// Fetch timed alerts
 | 
			
		||||
			this.fetchTimedAlerts(ctx);
 | 
			
		||||
		else if (settings.getBoolean("ALERT_ORGANIZATION", false))
 | 
			
		||||
			// Fetch organization alerts
 | 
			
		||||
			this.fetchOrganizationAlerts(ctx);
 | 
			
		||||
		else if (settings.getBoolean("ALERT_UNIVERSITY", false))
 | 
			
		||||
			// Fetch university alerts
 | 
			
		||||
			this.fetchUniversityAlerts(ctx);
 | 
			
		||||
		
 | 
			
		||||
		// And always fetch alerts made by us. Period.
 | 
			
		||||
		this.fetchGamedayAlerts(ctx);
 | 
			
		||||
		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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchTimedAlerts(Context ctx) {
 | 
			
		||||
		// Process the rules for all timed alerts.
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchOrganizationAlerts(Context ctx) {
 | 
			
		||||
	private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
 | 
			
		||||
		// Process fetching organization alerts (alerts retweeted by us)
 | 
			
		||||
		int duration = Toast.LENGTH_SHORT;
 | 
			
		||||
		String handle = ctx.getString(R.string.gameday_handle);
 | 
			
		||||
		Twitter twitter = TwitterFactory.getSingleton();
 | 
			
		||||
		List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			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
 | 
			
		||||
			
 | 
			
		||||
		} catch (TwitterException e) {
 | 
			
		||||
			Toast.makeText(ctx,
 | 
			
		||||
					"Unable to fetch alerts for organizations!\nAre you connected to the internet?",
 | 
			
		||||
					duration).show();
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		// 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
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchUniversityAlerts(Context ctx) {
 | 
			
		||||
	private void fetchUniversityAlerts(Context ctx) throws TwitterException {
 | 
			
		||||
		// Process fetching university alerts
 | 
			
		||||
		int duration = Toast.LENGTH_SHORT;
 | 
			
		||||
		String handle = ctx.getString(R.string.university_handle);
 | 
			
		||||
		Twitter twitter = TwitterFactory.getSingleton();
 | 
			
		||||
		List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			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
 | 
			
		||||
			
 | 
			
		||||
		} catch (TwitterException e) {
 | 
			
		||||
			Toast.makeText(ctx,
 | 
			
		||||
					"Unable to fetch alerts for the University!\nAre you connected to the internet?",
 | 
			
		||||
					duration).show();
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		}
 | 
			
		||||
		// List contains all valid alerts now
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void fetchGamedayAlerts(Context ctx) {
 | 
			
		||||
	private void fetchGamedayAlerts(Context ctx) throws TwitterException {
 | 
			
		||||
		// Process fetching alerts generated by staff of UNCCGameDay
 | 
			
		||||
		int duration = Toast.LENGTH_SHORT;
 | 
			
		||||
		String handle = ctx.getString(R.string.gameday_handle);
 | 
			
		||||
		Twitter twitter = TwitterFactory.getSingleton();
 | 
			
		||||
		List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			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.
 | 
			
		||||
			
 | 
			
		||||
		} catch (TwitterException e) {
 | 
			
		||||
			Toast.makeText(ctx,
 | 
			
		||||
					"Unable to fetch alerts from Gameday!\nAre you connected to the internet?",
 | 
			
		||||
					duration).show();
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		// 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.
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static List<Alert> createTimedAlerts(Context ctx) {
 | 
			
		||||
		// Create the timed alerts so we can add or remove them from the DB
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										18
									
								
								src/com/uncc/gameday/alerts/AlertService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/com/uncc/gameday/alerts/AlertService.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
package com.uncc.gameday.alerts;
 | 
			
		||||
 | 
			
		||||
import android.app.IntentService;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
 | 
			
		||||
public class AlertService extends IntentService {
 | 
			
		||||
	private static final String name = "AlertService";
 | 
			
		||||
 | 
			
		||||
	public AlertService() {
 | 
			
		||||
		super(name);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onHandleIntent(Intent intent) {
 | 
			
		||||
		// Go fetch all the alerts!
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user