diff --git a/src/com/studentersamfundet/app/IRSSParser.java b/src/com/studentersamfundet/app/IRSSParser.java index 72415d8..60223be 100644 --- a/src/com/studentersamfundet/app/IRSSParser.java +++ b/src/com/studentersamfundet/app/IRSSParser.java @@ -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); } diff --git a/src/com/studentersamfundet/app/RSSParserNews.java b/src/com/studentersamfundet/app/RSSParserNews.java index f56a418..52b3cd6 100644 --- a/src/com/studentersamfundet/app/RSSParserNews.java +++ b/src/com/studentersamfundet/app/RSSParserNews.java @@ -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. diff --git a/src/com/studentersamfundet/app/RSSParserProgram.java b/src/com/studentersamfundet/app/RSSParserProgram.java index deee2fa..eaff858 100644 --- a/src/com/studentersamfundet/app/RSSParserProgram.java +++ b/src/com/studentersamfundet/app/RSSParserProgram.java @@ -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() { diff --git a/src/com/studentersamfundet/app/ui/DnsActivity.java b/src/com/studentersamfundet/app/ui/DnsActivity.java index 124a017..6eb7fbc 100644 --- a/src/com/studentersamfundet/app/ui/DnsActivity.java +++ b/src/com/studentersamfundet/app/ui/DnsActivity.java @@ -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; } } \ No newline at end of file diff --git a/src/com/studentersamfundet/app/ui/lists/BaseListActivity.java b/src/com/studentersamfundet/app/ui/lists/BaseListActivity.java index 8930d19..7c6824f 100644 --- a/src/com/studentersamfundet/app/ui/lists/BaseListActivity.java +++ b/src/com/studentersamfundet/app/ui/lists/BaseListActivity.java @@ -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. */ } diff --git a/src/com/studentersamfundet/app/ui/lists/NewsListActivity.java b/src/com/studentersamfundet/app/ui/lists/NewsListActivity.java index adf59b4..01a7bb8 100644 --- a/src/com/studentersamfundet/app/ui/lists/NewsListActivity.java +++ b/src/com/studentersamfundet/app/ui/lists/NewsListActivity.java @@ -31,14 +31,14 @@ public class NewsListActivity extends BaseListActivity { @Override protected ListAdapter createAdapter(T[] objects) { final News[] news = (News[])objects; - ListAdapter adapter = new ArrayAdapter(this, 0, 0, news) { + ListAdapter adapter = new ArrayAdapter(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; }