Changed type of pubDate in FeedItem to Date

This commit is contained in:
daniel oeh 2012-06-13 23:47:55 +02:00
parent 85a1dd7006
commit db238af642
8 changed files with 36 additions and 18 deletions

View File

@ -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());

View File

@ -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;
}

View File

@ -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));

View File

@ -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());

View File

@ -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));

View File

@ -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);
}

View File

@ -50,6 +50,11 @@ public class SyndDateUtils {
SimpleDateFormat format = null;
if (date.endsWith("Z")) {
format = new SimpleDateFormat(RFC3339UTC);
try {
result = format.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
} else {
format = new SimpleDateFormat(RFC3339LOCAL);
// remove last colon
@ -59,12 +64,14 @@ public class SyndDateUtils {
if (x != colonIdx) buf.append(date.charAt(x));
}
String bufStr = buf.toString();
try {
result = format.parse(bufStr);
} catch (ParseException e) {
e.printStackTrace();
}
}
try {
result = format.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}

View File

@ -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;
}
}