mirror of
				https://github.com/bspeice/UNCCGameDay
				synced 2025-11-03 18:00:43 -05:00 
			
		
		
		
	AlertFetcher should be explicitly given its Context
Worst case, write a static method inside it.
This commit is contained in:
		@ -8,9 +8,9 @@ import twitter4j.Status;
 | 
				
			|||||||
import twitter4j.Twitter;
 | 
					import twitter4j.Twitter;
 | 
				
			||||||
import twitter4j.TwitterException;
 | 
					import twitter4j.TwitterException;
 | 
				
			||||||
import twitter4j.TwitterFactory;
 | 
					import twitter4j.TwitterFactory;
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
import android.widget.Toast;
 | 
					import android.widget.Toast;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.uncc.gameday.GameDay;
 | 
					 | 
				
			||||||
import com.uncc.gameday.R;
 | 
					import com.uncc.gameday.R;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AlertFetcher {
 | 
					public class AlertFetcher {
 | 
				
			||||||
@ -18,7 +18,7 @@ public class AlertFetcher {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	private int maxTweets = 5;
 | 
						private int maxTweets = 5;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public void fetchAlerts() {
 | 
						public void fetchAlerts(Context ctx) {
 | 
				
			||||||
		/* This method needs to be re-written to use better logic. */
 | 
							/* This method needs to be re-written to use better logic. */
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
@ -39,16 +39,16 @@ public class AlertFetcher {
 | 
				
			|||||||
		*/
 | 
							*/
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private void fetchTimedAlerts() {
 | 
						private void fetchTimedAlerts(Context ctx) {
 | 
				
			||||||
		// Process the rules for all timed alerts.
 | 
							// Process the rules for all timed alerts.
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private void fetchOrganizationAlerts() {
 | 
						private void fetchOrganizationAlerts(Context ctx) {
 | 
				
			||||||
		// Process fetching organization alerts (alerts retweeted by us)
 | 
							// Process fetching organization alerts (alerts retweeted by us)
 | 
				
			||||||
		int duration = Toast.LENGTH_SHORT;
 | 
							int duration = Toast.LENGTH_SHORT;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			String handle = GameDay.getAppContext().getString(R.string.gameday_handle);
 | 
								String handle = ctx.getString(R.string.gameday_handle);
 | 
				
			||||||
			Twitter twitter = TwitterFactory.getSingleton();
 | 
								Twitter twitter = TwitterFactory.getSingleton();
 | 
				
			||||||
			List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
								List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
@ -62,38 +62,38 @@ public class AlertFetcher {
 | 
				
			|||||||
			// List contains all valid alerts now
 | 
								// List contains all valid alerts now
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		} catch (TwitterException e) {
 | 
							} catch (TwitterException e) {
 | 
				
			||||||
			Toast.makeText(GameDay.getAppContext(),
 | 
								Toast.makeText(ctx,
 | 
				
			||||||
					"Unable to fetch alerts for organizations!\nAre you connected to the internet?",
 | 
										"Unable to fetch alerts for organizations!\nAre you connected to the internet?",
 | 
				
			||||||
					duration).show();
 | 
										duration).show();
 | 
				
			||||||
			e.printStackTrace();
 | 
								e.printStackTrace();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private void fetchUniversityAlerts() {
 | 
						private void fetchUniversityAlerts(Context ctx) {
 | 
				
			||||||
		// Process fetching university alerts
 | 
							// Process fetching university alerts
 | 
				
			||||||
		int duration = Toast.LENGTH_SHORT;
 | 
							int duration = Toast.LENGTH_SHORT;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			String handle = GameDay.getAppContext().getString(R.string.university_handle);
 | 
								String handle = ctx.getString(R.string.university_handle);
 | 
				
			||||||
			Twitter twitter = TwitterFactory.getSingleton();
 | 
								Twitter twitter = TwitterFactory.getSingleton();
 | 
				
			||||||
			List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
								List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			// List contains all valid alerts now
 | 
								// List contains all valid alerts now
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		} catch (TwitterException e) {
 | 
							} catch (TwitterException e) {
 | 
				
			||||||
			Toast.makeText(GameDay.getAppContext(),
 | 
								Toast.makeText(ctx,
 | 
				
			||||||
					"Unable to fetch alerts for the University!\nAre you connected to the internet?",
 | 
										"Unable to fetch alerts for the University!\nAre you connected to the internet?",
 | 
				
			||||||
					duration).show();
 | 
										duration).show();
 | 
				
			||||||
			e.printStackTrace();
 | 
								e.printStackTrace();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private void fetchGamedayAlerts() {
 | 
						private void fetchGamedayAlerts(Context ctx) {
 | 
				
			||||||
		// Process fetching alerts generated by staff of UNCCGameDay
 | 
							// Process fetching alerts generated by staff of UNCCGameDay
 | 
				
			||||||
		int duration = Toast.LENGTH_SHORT;
 | 
							int duration = Toast.LENGTH_SHORT;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			String handle = GameDay.getAppContext().getString(R.string.gameday_handle);
 | 
								String handle = ctx.getString(R.string.gameday_handle);
 | 
				
			||||||
			Twitter twitter = TwitterFactory.getSingleton();
 | 
								Twitter twitter = TwitterFactory.getSingleton();
 | 
				
			||||||
			List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
								List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
@ -107,7 +107,7 @@ public class AlertFetcher {
 | 
				
			|||||||
			// List contains all valid alerts now.
 | 
								// List contains all valid alerts now.
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		} catch (TwitterException e) {
 | 
							} catch (TwitterException e) {
 | 
				
			||||||
			Toast.makeText(GameDay.getAppContext(),
 | 
								Toast.makeText(ctx,
 | 
				
			||||||
					"Unable to fetch alerts from Gameday!\nAre you connected to the internet?",
 | 
										"Unable to fetch alerts from Gameday!\nAre you connected to the internet?",
 | 
				
			||||||
					duration).show();
 | 
										duration).show();
 | 
				
			||||||
			e.printStackTrace();
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user