News are shown.

This commit is contained in:
Robert Kolner committed 2012-03-01 19:13:03 +01:00
1 parent 855ae6c055
commit 63549b1f05
6 files changed
+25 -17

No files matched your search

@@ -1,7 +1,9 @@
package com.studentersamfundet.app;
import java.io.Serializable;
import org.w3c.dom.NodeList;
public interface IRSSParser {
public interface IRSSParser extends Serializable {
public DataHandler parse(NodeList nodes);
}
@@ -5,6 +5,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class RSSParserNews implements IRSSParser {
private static final long serialVersionUID = -2654591623794449527L;
private final DataHandler dh;
public RSSParserNews() {
@@ -37,7 +38,7 @@ public class RSSParserNews implements IRSSParser {
NodeList titleNodes = (itemElement).getElementsByTagName("title");
NodeList descriptionNodes = (itemElement).getElementsByTagName("description");
NodeList linkNodes = (itemElement).getElementsByTagName("link");
NodeList textNodes = (itemElement).getElementsByTagName("content");
NodeList textNodes = (itemElement).getElementsByTagName("content:encoded");
NodeList dateNodes = (itemElement).getElementsByTagName("pubDate");
// Convert a Node into an Element.
@@ -5,6 +5,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class RSSParserProgram implements IRSSParser {
private static final long serialVersionUID = 3364287016121595334L;
private final DataHandler dh;
public RSSParserProgram() {
@@ -13,14 +13,18 @@ import android.widget.TextView;
import com.studentersamfundet.app.FeedFetcher;
import com.studentersamfundet.app.R;
import com.studentersamfundet.app.RSSParserNews;
import com.studentersamfundet.app.RSSParserProgram;
import com.studentersamfundet.app.ui.lists.EventListActivity;
import com.studentersamfundet.app.ui.lists.EventListTicketsActivity;
import com.studentersamfundet.app.ui.lists.NewsListActivity;
public class DnsActivity extends BaseDnsActivity {
public static final String feedURL = "http://studentersamfundet.no/rss/lars_program_feed.php";
public static final String eventFeedURL = "http://studentersamfundet.no/rss/lars_program_feed.php";
public static final String newsFeedURL = "http://studentersamfundet.no/rss/nyheter_feed.php";
private FeedFetcher feedFetcher;
private FeedFetcher eventFeedFetcher;
private FeedFetcher newsFeedFetcher;
private String[] openingHoursHouse = {
"10.00 - 01.00",
@@ -56,7 +60,8 @@ public class DnsActivity extends BaseDnsActivity {
setContentView(R.layout.main);
/* Initialize necessary variables: */
feedFetcher = new FeedFetcher(feedURL, "local_events");
eventFeedFetcher = new FeedFetcher(eventFeedURL, "local_events");
newsFeedFetcher = new FeedFetcher(newsFeedURL, "local_news");
/* Set opening hours: */
TextView tvNeuf = (TextView)findViewById(R.id.main_menu_hours_neuf);
@@ -149,29 +154,27 @@ public class DnsActivity extends BaseDnsActivity {
public void programButton(View v) {
Intent intent = setupNewIntent(EventListActivity.class);
intent.putExtra("feed", eventFeedFetcher);
intent.putExtra("parser", new RSSParserProgram());
startActivity(intent);
}
public void ticketButton(View v) {
Intent intent = setupNewIntent(EventListTicketsActivity.class);
intent.putExtra("feed", eventFeedFetcher);
intent.putExtra("parser", new RSSParserProgram());
startActivity(intent);
}
public void newsButton(View v) {
Intent intent = setupNewIntent(NewsListActivity.class);
intent.putExtra("feed", newsFeedFetcher);
intent.putExtra("parser", new RSSParserNews());
startActivity(intent);
}
public void joinButton(View v) {
Intent intent = setupNewIntent(JoinUsActivity.class);
startActivity(intent);
}
protected Intent setupNewIntent(Class<?> cl) {
Intent intent = super.setupNewIntent(cl);
intent.putExtra("feed", feedFetcher);
return intent;
}
}
@@ -9,7 +9,6 @@ import com.studentersamfundet.app.Event;
import com.studentersamfundet.app.FeedFetcher;
import com.studentersamfundet.app.IRSSParser;
import com.studentersamfundet.app.R;
import com.studentersamfundet.app.RSSParserProgram;
import com.studentersamfundet.app.ui.BaseDnsActivity;
import android.content.Context;
@@ -41,7 +40,9 @@ public abstract class BaseListActivity extends BaseDnsActivity {
throw new RuntimeException("This activity must be fed a feed feeder.");
/* Create the parser: */
this.parser = new RSSParserProgram();
this.parser = (IRSSParser)i.getExtras().get("parser");
if (this.parser == null)
throw new RuntimeException("This activity requires feed parser");
/* DataHandler will be set later. */
}
@@ -31,14 +31,14 @@ public class NewsListActivity extends BaseListActivity {
@Override
protected <T> ListAdapter createAdapter(T[] objects) {
final News[] news = (News[])objects;
ListAdapter adapter = new ArrayAdapter<News>(this, 0, 0, news) {
ListAdapter adapter = new ArrayAdapter<News>(this, R.layout.news_list_row, R.id.news_list_row_desc, news) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewGroup row;
if (null == convertView) {
LayoutInflater inflater = getLayoutInflater();
row = (ViewGroup)inflater.inflate(0, null);
row = (ViewGroup)inflater.inflate(R.layout.news_list_row, null);
} else {
row = (ViewGroup)convertView;
}