From 48b5fad7c317f852ba505f00ac4b8694e6fb333d Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Mon, 5 Dec 2011 18:41:32 +0100 Subject: [PATCH] Changed RSS format - added 4 tags: image-url, regular/member ticket price and ticket url. --- .../studentersamfundet/app/DataHandler.java | 16 +++++- src/com/studentersamfundet/app/Event.java | 55 +++++++++++++++---- .../app/RSSParserProgram.java | 52 ++++++++++++++---- .../app/ui/EventViewActivity.java | 12 ++-- .../app/ui/ProgramListActivity.java | 8 +-- 5 files changed, 109 insertions(+), 34 deletions(-) diff --git a/src/com/studentersamfundet/app/DataHandler.java b/src/com/studentersamfundet/app/DataHandler.java index 76d2a40..56ba976 100644 --- a/src/com/studentersamfundet/app/DataHandler.java +++ b/src/com/studentersamfundet/app/DataHandler.java @@ -10,12 +10,22 @@ public class DataHandler { private List news = new LinkedList(); private Set eventCategories = new TreeSet(); - public void insertEvent(String id, String title, String description, String date, String location, String text, String category) { + public void insertEvent(String id, + String title, + String description, + String date, + String location, + String text, + String category, + String imageUri, + String priceReg, + String priceMem, + String ticketUri) { int intId = Integer.parseInt(id); if (getEvent(intId) != null) return; - Event e = new Event(intId, title, description, date, location, text, category); + Event e = new Event(intId, title, description, date, location, text, category, imageUri); events.add(e); eventCategories.add(category); } @@ -41,7 +51,7 @@ public class DataHandler { } for (Event event : events) { - if (category.equals(event.category)) + if (category.equals(event.getCategory())) sorted.add(event); } return sorted.toArray(new Event[sorted.size()]); diff --git a/src/com/studentersamfundet/app/Event.java b/src/com/studentersamfundet/app/Event.java index 031a4d7..72ef618 100644 --- a/src/com/studentersamfundet/app/Event.java +++ b/src/com/studentersamfundet/app/Event.java @@ -13,13 +13,18 @@ public class Event implements Serializable { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - public int id; - public String title; - public String description; - public Date date; - public String location; - public String text; - public String category; + public final int id; + public final String title; + private String description; + private Date date; + private String location; + private String text; + private String category; + private String image; + + private int regularPrice; + private int memberPrice; + private Uri ticketUri; public Event( int id, @@ -28,13 +33,15 @@ public class Event implements Serializable { String date, String location, String text, - String category) { + String category, + String image) { this.id = id; this.title = title.trim(); this.description = (description == null) ? "" : description.trim(); this.location = (location == null) ? "" : location.trim(); this.text = (text == null) ? "" : text.trim(); this.category = (category == null) ? "" : category.trim(); + this.image = image; try { this.date = (date == null) ? null : dateFormat.parse(date.trim()); @@ -47,6 +54,26 @@ public class Event implements Serializable { return this.title; } + public String getDescription() { + return this.description; + } + + public String getContent() { + return this.text; + } + + public String getCategory() { + return this.category; + } + + public Date getDate() { + return this.date; + } + + public String getLocation() { + return this.location; + } + public Uri getUri() { if (this.id <= 0) return null; @@ -59,7 +86,15 @@ public class Event implements Serializable { return null; } - String imageUri = "http://studentersamfundet.no/imageResize.php?pic=bilder/program/{id}.jpg&maxwidth=480"; - return Uri.parse(imageUri.replaceAll("{id}", Integer.toString(this.id))); + String imageUri = "http://studentersamfundet.no/imageResize.php?pic=bilder/program/{image}&maxwidth=480"; + return Uri.parse(imageUri.replaceAll("{image}", this.image)); + } + + public String getPriceString() { + return "" +this.regularPrice +'/' +this.memberPrice; + } + + public Uri getTicketUri() { + return this.ticketUri; } } diff --git a/src/com/studentersamfundet/app/RSSParserProgram.java b/src/com/studentersamfundet/app/RSSParserProgram.java index ed07c83..7accb81 100644 --- a/src/com/studentersamfundet/app/RSSParserProgram.java +++ b/src/com/studentersamfundet/app/RSSParserProgram.java @@ -20,16 +20,19 @@ public class RSSParserProgram { } public DataHandler parse(NodeList itemNodes) { - String id = ""; - String title = ""; - String description = ""; - String date = ""; - String location = ""; - String text = ""; - String category = ""; - // String pictureUrl = ""; Necessary? - - for (int i = 0; i < itemNodes.getLength(); i++) { + for (int i = 0; i < itemNodes.getLength(); i++) { + String id = ""; + String title = ""; + String description = ""; + String date = ""; + String location = ""; + String text = ""; + String category = ""; + String image = ""; + String priceReg = ""; + String priceMem = ""; + String ticketUrl = ""; + Node itemNode = itemNodes.item(i); if (itemNode.getNodeType() == Node.ELEMENT_NODE) { @@ -44,6 +47,10 @@ public class RSSParserProgram { NodeList locationNodes = (itemElement).getElementsByTagName("location"); NodeList textNodes = (itemElement).getElementsByTagName("content"); NodeList categoryNodes = (itemElement).getElementsByTagName("category"); + NodeList imageNodes = (itemElement).getElementsByTagName("image"); + NodeList priceRegNodes = (itemElement).getElementsByTagName("price-regular"); + NodeList priceMemNodes = (itemElement).getElementsByTagName("price-member"); + NodeList ticketUrlNodes = (itemElement).getElementsByTagName("ticket-url"); // Convert a Node into an Element. Node idElement = idNodes.item(0); @@ -53,6 +60,10 @@ public class RSSParserProgram { Node locationElement = locationNodes.item(0); Node textElement = textNodes.item(0); Node categoryElement = categoryNodes.item(0); + Node imageElement = imageNodes.item(0); + Node priceRegElement = priceRegNodes.item(0); + Node priceMemElement = priceMemNodes.item(0); + Node ticketUrlElement = ticketUrlNodes.item(0); // Get all the child nodes. NodeList idTextNodes = idElement.getChildNodes(); @@ -62,6 +73,10 @@ public class RSSParserProgram { NodeList locationTextNodes = locationElement.getChildNodes(); NodeList textTextNodes = textElement.getChildNodes(); NodeList categoryTextNodes = categoryElement.getChildNodes(); + NodeList imageTextNodes = imageElement.getChildNodes(); + NodeList priceRegTextNodes = priceRegElement.getChildNodes(); + NodeList priceMemTextNodes = priceMemElement.getChildNodes(); + NodeList ticketUrlTextNodes = ticketUrlElement.getChildNodes(); // Retrieve the text. id = idTextNodes.item(0).getNodeValue(); // mandatory @@ -71,8 +86,23 @@ public class RSSParserProgram { if (locationTextNodes.getLength() > 0) location = locationTextNodes.item(0).getNodeValue(); if (textTextNodes.getLength() > 0) text = textTextNodes.item(0).getNodeValue(); if (categoryTextNodes.getLength() > 0) category = categoryTextNodes.item(0).getNodeValue(); + if (imageTextNodes.getLength() > 0) image = imageTextNodes.item(0).getNodeValue(); + if (priceRegTextNodes.getLength() > 0) priceReg = priceRegTextNodes.item(0).getNodeValue(); + if (priceMemTextNodes.getLength() > 0) priceMem = priceMemTextNodes.item(0).getNodeValue(); + if (ticketUrlTextNodes.getLength() > 0) ticketUrl = ticketUrlTextNodes.item(0).getNodeValue(); - dh.insertEvent(id, title, description, date, location, text, category); + // This is as ugly as it gets. Refactor? + dh.insertEvent(id, + title, + description, + date, + location, + text, + category, + image, + priceReg, + priceMem, + ticketUrl); } } return dh; diff --git a/src/com/studentersamfundet/app/ui/EventViewActivity.java b/src/com/studentersamfundet/app/ui/EventViewActivity.java index 12a450b..db36e92 100644 --- a/src/com/studentersamfundet/app/ui/EventViewActivity.java +++ b/src/com/studentersamfundet/app/ui/EventViewActivity.java @@ -35,21 +35,21 @@ public class EventViewActivity extends BaseDnsActivity { Button link = (Button) findViewById(R.id.event_view_link); title.setText(Html.fromHtml(e.title)); - location.setText(Html.fromHtml(e.location)); + location.setText(Html.fromHtml(e.getLocation())); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - datetime.setText(e.date != null ? dateFormat.format(e.date) : ""); + datetime.setText(e.getDate() != null ? dateFormat.format(e.getDate()) : ""); StringBuilder sb = new StringBuilder(); - if (e.description.length() > 0) { + if (e.getDescription().length() > 0) { sb.append(""); - sb.append(e.description); + sb.append(e.getDescription()); sb.append("

"); } - if (e.text.length() > 0) { - sb.append(e.text); + if (e.getContent().length() > 0) { + sb.append(e.getContent()); } description.setText(Html.fromHtml(sb.toString())); diff --git a/src/com/studentersamfundet/app/ui/ProgramListActivity.java b/src/com/studentersamfundet/app/ui/ProgramListActivity.java index 4ddf0d9..b375d21 100644 --- a/src/com/studentersamfundet/app/ui/ProgramListActivity.java +++ b/src/com/studentersamfundet/app/ui/ProgramListActivity.java @@ -112,7 +112,7 @@ public class ProgramListActivity extends BaseDnsActivity { SimpleDateFormat dateFormat = new SimpleDateFormat("d. MMMM"); TextView dateView = (TextView) row.findViewById(R.id.event_list_row_date); - dateView.setText(dateFormat.format(e.date)); + dateView.setText(dateFormat.format(e.getDate())); row.setOnClickListener(new OnClickListener() { @@ -127,10 +127,10 @@ public class ProgramListActivity extends BaseDnsActivity { row.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { - if (e.date == null) + if (e.getDate() == null) return false; - long startDate = e.date.getTime(); + long startDate = e.getDate().getTime(); try { Intent intent = new Intent(Intent.ACTION_EDIT); @@ -139,7 +139,7 @@ public class ProgramListActivity extends BaseDnsActivity { intent.putExtra("beginTime", startDate); intent.putExtra("endTime", startDate + (2*60*60*1000)); // Two hours intent.putExtra("allDay", false); - intent.putExtra("eventLocation", e.location); + intent.putExtra("eventLocation", e.getLocation()); intent.putExtra("reminder", false); startActivity(intent);