package edu.yalestc.yalepublic.news;

import android.os.AsyncTask;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import org.xml.sax.SAXException;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import edu.yalestc.yalepublic.R;
import edu.yalestc.yalepublic.news.RssReader;
import edu.yalestc.yalepublic.news.RssFeed;

/**
 * Created by Jason Liu on 10/4/14.
 * This AsyncTask downloads RSS data from a given String URL and returns a RssFeed with all
 * of the RSS data parsed into different fields described in RssItem.
 */
public class NewsDownload extends AsyncTask<String, Integer, RssFeed> {

    public NewsDownload() {
        super();
    }

    @Override
    protected RssFeed doInBackground(String... strings) {
        URL url = null;
        try {
            url = new URL(strings[0]);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        RssFeed feed = null;
        try {
            feed = RssReader.read(url);
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (feed != null) {       // EHOSTUNREACH: No route to hoast
                ArrayList<RssItem> rssItems = feed.getRssItems();
            for (RssItem rssItem : rssItems) {
                Log.d("RSS Reader", rssItem.getTitle());
            }
        }
        return feed;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute(RssFeed s) {
        super.onPostExecute(s);
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
}

@@ -830,33 +830,97 @@
  URL url = null;
+         // Set our URL to the String passed in to the AsyncTask
 %0A
-
         try %7B%0A  
@@ -1072,16 +1072,78 @@
  = null;
+   // Call RssReader to download from our url, and return feed
 %0A       
@@ -1366,21 +1366,48 @@
 l) %7B    
-   //
+// If URL is bad, it will return
  EHOSTUN
@@ -1427,17 +1427,16 @@
 te to ho
-a
 st%0A     
@@ -1539,24 +1539,24 @@
 rssItems) %7B%0A
-
             
@@ -1599,16 +1599,53 @@
 itle());
+  // Log out all RSS Titles for debug
 %0A       

Add documentation to NewsDownload