From db238af64235aa4ca23ce733de5b6de0a5fdc2e3 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 13 Jun 2012 23:47:55 +0200 Subject: [PATCH] Changed type of pubDate in FeedItem to Date --- .../podfetcher/activity/ItemviewActivity.java | 2 +- src/de/podfetcher/feed/FeedItem.java | 10 +++++---- src/de/podfetcher/feed/FeedManager.java | 5 +++-- src/de/podfetcher/storage/PodDBAdapter.java | 4 ++-- .../syndication/namespace/atom/NSAtom.java | 3 ++- .../syndication/namespace/rss20/NSRSS20.java | 2 +- .../syndication/util/SyndDateUtils.java | 21 ++++++++++++------- src/de/podfetcher/util/Converter.java | 7 +++++++ 8 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/de/podfetcher/activity/ItemviewActivity.java b/src/de/podfetcher/activity/ItemviewActivity.java index 84b70a67f..72f037c1c 100644 --- a/src/de/podfetcher/activity/ItemviewActivity.java +++ b/src/de/podfetcher/activity/ItemviewActivity.java @@ -101,7 +101,7 @@ public class ItemviewActivity extends SherlockActivity { setTitle(item.getFeed().getTitle()); - txtvPublished.setText(item.getPubDate()); + //txtvPublished.setText(item.getPubDate()); TODO fix txtvTitle.setText(item.getTitle()); if(item.getFeed().getImage() != null) { imgvImage.setImageBitmap(item.getFeed().getImage().getImageBitmap()); diff --git a/src/de/podfetcher/feed/FeedItem.java b/src/de/podfetcher/feed/FeedItem.java index 714a5bf9a..972195eb7 100644 --- a/src/de/podfetcher/feed/FeedItem.java +++ b/src/de/podfetcher/feed/FeedItem.java @@ -1,5 +1,7 @@ package de.podfetcher.feed; +import java.util.Date; + /** * Data Object for a XML message @@ -10,7 +12,7 @@ public class FeedItem extends FeedComponent{ private String title; private String description; private String link; - private String pubDate; + private Date pubDate; private FeedMedia media; private Feed feed; private boolean read; @@ -20,7 +22,7 @@ public class FeedItem extends FeedComponent{ } public FeedItem(String title, String description, String link, - String pubDate, FeedMedia media, Feed feed) { + Date pubDate, FeedMedia media, Feed feed) { super(); this.title = title; this.description = description; @@ -55,11 +57,11 @@ public class FeedItem extends FeedComponent{ this.link = link; } - public String getPubDate() { + public Date getPubDate() { return pubDate; } - public void setPubDate(String pubDate) { + public void setPubDate(Date pubDate) { this.pubDate = pubDate; } diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index 1d448e8b8..c6913493b 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -1,6 +1,7 @@ package de.podfetcher.feed; import java.util.ArrayList; +import java.util.Date; import de.podfetcher.storage.*; import android.content.Context; @@ -251,8 +252,8 @@ public class FeedManager { .getColumnIndex(PodDBAdapter.KEY_LINK))); item.setDescription(itemlistCursor.getString(itemlistCursor .getColumnIndex(PodDBAdapter.KEY_DESCRIPTION))); - item.setPubDate(itemlistCursor.getString(itemlistCursor - .getColumnIndex(PodDBAdapter.KEY_PUBDATE))); + item.setPubDate(new Date(itemlistCursor.getLong(itemlistCursor + .getColumnIndex(PodDBAdapter.KEY_PUBDATE)))); item.setMedia(adapter.getFeedMedia(itemlistCursor .getLong(itemlistCursor .getColumnIndex(PodDBAdapter.KEY_MEDIA)), item)); diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java index b2cdfb6a6..3548368df 100644 --- a/src/de/podfetcher/storage/PodDBAdapter.java +++ b/src/de/podfetcher/storage/PodDBAdapter.java @@ -62,7 +62,7 @@ public class PodDBAdapter { private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE " + TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE + " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION - + " TEXT," + KEY_PUBDATE + " TEXT," + KEY_MEDIA + + " TEXT," + KEY_PUBDATE + " INTEGER," + KEY_MEDIA + " INTEGER," + KEY_FEED + " INTEGER," + KEY_READ + " INTEGER)"; @@ -216,7 +216,7 @@ public class PodDBAdapter { values.put(KEY_TITLE, item.getTitle()); values.put(KEY_LINK, item.getLink()); values.put(KEY_DESCRIPTION, item.getDescription()); - values.put(KEY_PUBDATE, item.getPubDate()); + values.put(KEY_PUBDATE, item.getPubDate().getTime()); if (item.getMedia() != null) { if(item.getMedia().getId() == 0) { setMedia(item.getMedia()); diff --git a/src/de/podfetcher/syndication/namespace/atom/NSAtom.java b/src/de/podfetcher/syndication/namespace/atom/NSAtom.java index 36cad19cf..ece9f8674 100644 --- a/src/de/podfetcher/syndication/namespace/atom/NSAtom.java +++ b/src/de/podfetcher/syndication/namespace/atom/NSAtom.java @@ -9,6 +9,7 @@ import de.podfetcher.feed.FeedMedia; import de.podfetcher.syndication.handler.HandlerState; import de.podfetcher.syndication.namespace.Namespace; import de.podfetcher.syndication.namespace.SyndElement; +import de.podfetcher.syndication.util.SyndDateUtils; public class NSAtom extends Namespace { public static final String NSTAG = "atom"; @@ -109,7 +110,7 @@ public class NSAtom extends Namespace { } } else if (top.equals(PUBLISHED)) { if (second.equals(ENTRY)) { - state.getCurrentItem().setPubDate(content); + state.getCurrentItem().setPubDate(SyndDateUtils.parseRFC3339Date(content)); } } else if (top.equals(IMAGE)) { state.getFeed().setImage(new FeedImage(content, null)); diff --git a/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java b/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java index aee611db0..573b46501 100644 --- a/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java +++ b/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java @@ -90,7 +90,7 @@ public class NSRSS20 extends Namespace { state.getCurrentItem().setLink(content); } } else if (top.equals(PUBDATE) && second.equals(ITEM)) { - state.getCurrentItem().setPubDate(content); + state.getCurrentItem().setPubDate(SyndDateUtils.parseRFC822Date(content)); } else if (top.equals(URL) && second.equals(IMAGE)) { state.getFeed().getImage().setDownload_url(content); } diff --git a/src/de/podfetcher/syndication/util/SyndDateUtils.java b/src/de/podfetcher/syndication/util/SyndDateUtils.java index 457a1fb81..cfc9a01a7 100644 --- a/src/de/podfetcher/syndication/util/SyndDateUtils.java +++ b/src/de/podfetcher/syndication/util/SyndDateUtils.java @@ -49,7 +49,12 @@ public class SyndDateUtils { Date result = null; SimpleDateFormat format = null; if (date.endsWith("Z")) { - format = new SimpleDateFormat(RFC3339UTC); + format = new SimpleDateFormat(RFC3339UTC); + try { + result = format.parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } } else { format = new SimpleDateFormat(RFC3339LOCAL); // remove last colon @@ -58,13 +63,15 @@ public class SyndDateUtils { for (int x = 0; x < date.length(); x++) { if (x != colonIdx) buf.append(date.charAt(x)); } - String bufStr = buf.toString(); - } - try { - result = format.parse(date); - } catch (ParseException e) { - e.printStackTrace(); + String bufStr = buf.toString(); + try { + result = format.parse(bufStr); + } catch (ParseException e) { + e.printStackTrace(); + } + } + return result; } diff --git a/src/de/podfetcher/util/Converter.java b/src/de/podfetcher/util/Converter.java index 46fddb152..948007b6c 100644 --- a/src/de/podfetcher/util/Converter.java +++ b/src/de/podfetcher/util/Converter.java @@ -1,5 +1,7 @@ package de.podfetcher.util; +import java.util.Date; + import android.util.Log; /** Provides methods for converting various units. */ @@ -78,4 +80,9 @@ public final class Converter { return String.format("%02d:%02d", h, m); } + + /** Returns string that is supposed to be shown in the GUI. */ + public static String getDateString(Date date) { + return null; + } }