package com.hardskygames.habro;

import java.util.ArrayList;

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

public class HabroActivity extends Activity
{
	public static RssItem selectedRssItem = null;
	static String feedUrl = "http://habrahabr.ru/rss/hubs/";
	ListView rssListView = null;
	ArrayList<RssItem> rssItems = new ArrayList<RssItem>();
	ArrayAdapter<RssItem> aa = null;
	
	public ListView getListView(){
		return rssListView;
	}
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		// get the listview from layout.xml
		rssListView = (ListView) findViewById(R.id.lstArticles);
		// here we specify what to execute when individual list items clicked
		rssListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		
			public void onItemClick(AdapterView<?> av, View view, int index, long arg3) {
			    selectedRssItem = rssItems.get(index);			
				// we call the other activity that shows a single rss item in
				// one page
				Intent intent = new Intent("com.hardskygames.habro.displayRssItem");
				startActivity(intent);
			}
		});
		
		//adapters are used to populate list. they take a collection,
		//a view (in our example R.layout.list_item
		aa = new ItemAdapter(this, R.layout.item_article, rssItems);
		    //here we bind array adapter to the list
		rssListView.setAdapter(aa);
		refressRssList();
		
    }
    
	private void refressRssList() {
	
	    ArrayList<RssItem> newItems = RssItem.getRssItems(feedUrl);
	    rssItems.clear();
	    rssItems.addAll(newItems);    
	    aa.notifyDataSetChanged();
	}
    
}

@@ -238,16 +238,46 @@
 dapter;%0A
+import android.widget.Button;%0A
 import a
@@ -300,16 +300,16 @@
 stView;%0A
-
 %0Apublic 
@@ -395,16 +395,26 @@
  null;%0A%09
+%0A%09private 
 static S
@@ -463,16 +463,24 @@
 ubs/%22;%0A%09
+private 
 ListView
@@ -501,16 +501,24 @@
  null;%0A%09
+private 
 ArrayLis
@@ -566,16 +566,24 @@
 em%3E();%0A%09
+private 
 ArrayAda
@@ -603,24 +603,61 @@
  aa = null;%0A
+%09private Button m_btnRefresh = null;%0A
 %09%0A%09public Li
@@ -1002,16 +1002,74 @@
 icles);%0A
+%09%09m_btnRefresh = (Button) findViewById(R.id.btn_refresh);%0A
 %09%09// her
@@ -1497,16 +1497,16 @@
 Item%22);%0A
-
 %09%09%09%09star
@@ -1535,16 +1535,162 @@
 %7D%0A%09%09%7D);%0A
+%09%09m_btnRefresh.setOnClickListener(new View.OnClickListener() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void onClick(View v) %7B%0A%09%09%09%09refressRssList();%0A%09%09%09%7D%0A%09%09%7D);%0A
 %09%09%0A%09%09//a

refresh button