package edu.yalestc.yalepublic.news;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import edu.yalestc.yalepublic.R;

/**
 * Created by Jason Liu on 10/17/14.
 */
public class NewsChooser extends Activity {

    private String rss_feeds[], rss_names[];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.news_items);
        rss_feeds = getResources().getStringArray(R.array.rss_feeds);
        rss_names = getResources().getStringArray(R.array.rss_names);

         /*String[] video_arrays = {"video1", "video2"};
        List<String> videos = new ArrayList<String>(Arrays.asList(video_arrays)); */

        // Parameters: Activity (Context), Layout file, Id of TextView, Array that's adapted
            /*final ArrayAdapter<String> mNewsAdapter;
            mNewsAdapter = new ArrayAdapter<String>(
                    this, R.layout.news_tab, R.id.tvTitle, rssTitles);*/

        //ArrayList<RssItem> rssItems = feed.getRssItems();
        //List<String> rssData = rssItems;
        // TODO: Convert ArrayList<rssItem> into an array of strings

        ListView listView = (ListView) findViewById(R.id.listNews);
        ArrayAdapter<String> mListAdapter = new ArrayAdapter<>(this, R.layout.tab, R.id.tab);
        mListAdapter.addAll(Arrays.asList(rss_names));
        //Collections.addAll(mListAdapter, rss_names);


        listView.setAdapter(mListAdapter);

        //set OnItemClickListener to open up a new activity in which we get
        //all the videos listed
        listView.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //redirect to new activity displaying all videos
                Intent showThem = new Intent(NewsChooser.this, NewsReader.class);
                showThem.putExtra("rssfeed", rss_feeds[arg2]);
                //For Debug purposes - show what is the playlistID
                Log.d("StartingActivityInVideoList", rss_feeds[arg2]);
                startActivity(showThem);
            }
        });
    }
}

@@ -844,16 +844,37 @@
 _feeds);
+ // Array of RSS URLs
 %0A       
@@ -939,668 +939,290 @@
 es);
-%0A%0A         /*String%5B%5D video_arrays = %7B%22video1%22, %22video2%22%7D;%0A        List%3CString%3E videos = new ArrayList%3CString%3E(Arrays.asList(video_arrays)); */%0A%0A        // Parameters: Activity (Context), Layout file, Id of TextView, Array that's adapted%0A            /*final ArrayAdapter%3CString%3E mNewsAdapter;%0A            mNewsAdapter = new ArrayAdapter%3CString%3E(%0A                    this, R.layout.news_tab, R.id.tvTitle, rssTitles);*/%0A%0A        //ArrayList%3CRssItem%3E rssItems = feed.getRssItems();%0A        //List%3CString%3E rssData = rssItems;%0A        // TODO: Convert ArrayList%3CrssItem%3E into an array of strings%0A%0A        ListView listView = (ListView) findViewById(R.id.listNews);
+ // Array of RSS Titles%0A%0A        // Set up the ListView listNews with all of the titles from rss_names%5B%5D.%0A        ListView listView = (ListView) findViewById(R.id.listNews);%0A        // Parameters for ArrayAdapter: Activity (Context), Layout file, TextView Id, %3CArray that's adapted%3E
 %0A   
@@ -1367,24 +1367,25 @@
 ames));%0A
+%0A
         
 //Collec
@@ -1380,99 +1380,86 @@
     
-//Collections.addAll(mListAdapter, rss_names);%0A%0A%0A        listView.setAdapter(mListAdapter);
+listView.setAdapter(mListAdapter);    // After constructing adapter, set it up
 %0A%0A  
@@ -1466,17 +1466,18 @@
       //
-s
+ S
 et OnIte
@@ -1536,40 +1536,25 @@
  get
-%0A        //all the videos listed
+ all the RSS data
 %0A   
@@ -2061,28 +2061,28 @@
 oList%22, rss_
-feed
+name
 s%5Barg2%5D);%0A  

Remove commented code, add documentation for setting up the adapter