diff --git a/app/src/main/java/com/readrops/app/database/entities/Item.java b/app/src/main/java/com/readrops/app/database/entities/Item.java index 5d44a044..badab19c 100644 --- a/app/src/main/java/com/readrops/app/database/entities/Item.java +++ b/app/src/main/java/com/readrops/app/database/entities/Item.java @@ -3,6 +3,7 @@ package com.readrops.app.database.entities; import android.arch.persistence.room.*; import com.readrops.app.utils.DateUtils; +import com.readrops.app.utils.Utils; import com.readrops.readropslibrary.localfeed.atom.ATOMEntry; import com.readrops.readropslibrary.localfeed.json.JSONItem; import com.readrops.readropslibrary.localfeed.rss.RSSItem; @@ -13,7 +14,7 @@ import org.joda.time.LocalDateTime; import java.text.ParseException; import java.util.ArrayList; import java.util.List; - +import java.util.regex.Pattern; @Entity @@ -170,20 +171,24 @@ public class Item { newItem.setGuid(item.getGuid()); newItem.setTitle(item.getTitle()); - - newItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_DATE_FORMAT)); + if (Pattern.compile(DateUtils.RSS_1_DATE_FORMAT_REGEX).matcher(item.getPubDate()).matches()) + newItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_1_DATE_FORMAT)); + else + newItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_2_DATE_FORMAT)); newItem.setLink(item.getLink()); newItem.setFeedId(feed.getId()); if (item.getMediaContents() != null && item.getMediaContents().size() > 0) { for (RSSMediaContent mediaContent : item.getMediaContents()) { - if (mediaContent.isContentAnImage()) { + if (Utils.isTypeImage(mediaContent.getMedium())) { newItem.setImageLink(mediaContent.getUrl()); break; } } - + } else { + if (item.getEnclosure() != null && Utils.isTypeImage(item.getEnclosure().getType())) + newItem.setImageLink(item.getEnclosure().getUrl()); } dbItems.add(newItem); diff --git a/app/src/main/java/com/readrops/app/utils/DateUtils.java b/app/src/main/java/com/readrops/app/utils/DateUtils.java index 680f9f74..bb9ee327 100644 --- a/app/src/main/java/com/readrops/app/utils/DateUtils.java +++ b/app/src/main/java/com/readrops/app/utils/DateUtils.java @@ -9,7 +9,10 @@ import org.joda.time.LocalDateTime; public final class DateUtils { - public static final String RSS_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss Z"; + public static final String RSS_1_DATE_FORMAT_REGEX = "^[a-zA-Z]{3}, [0-9]{2} [a-zA-Z]{3} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} Z$"; + + public static final String RSS_2_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss Z"; + public static final String RSS_1_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss 'Z'"; public static final String ATOM_JSON_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX"; diff --git a/app/src/main/java/com/readrops/app/utils/Utils.java b/app/src/main/java/com/readrops/app/utils/Utils.java index b28ff57c..2ed0e27f 100644 --- a/app/src/main/java/com/readrops/app/utils/Utils.java +++ b/app/src/main/java/com/readrops/app/utils/Utils.java @@ -9,6 +9,7 @@ import android.graphics.Color; import android.os.Handler; import android.os.Looper; import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; import android.util.DisplayMetrics; import android.widget.Toast; @@ -75,4 +76,9 @@ public final class Utils { Color.alpha(color) / 255.0); } + public static boolean isTypeImage(@NonNull String type) { + return type.equals("image") || type.equals("image/jpeg") || type.equals("image/jpg") + || type.equals("image/png"); + } + } diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSEnclosure.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSEnclosure.java new file mode 100644 index 00000000..7503af15 --- /dev/null +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSEnclosure.java @@ -0,0 +1,30 @@ +package com.readrops.readropslibrary.localfeed.rss; + +import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Root; + +@Root(name = "enclosure", strict = false) +public class RSSEnclosure { + + @Attribute + private String type; + + @Attribute + private String url; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSItem.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSItem.java index 46118ca1..9fecb2ef 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSItem.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSItem.java @@ -28,6 +28,9 @@ public class RSSItem extends AItem { @Namespace(prefix = "media") private List mediaContents; + @Element(required = false) + private RSSEnclosure enclosure; + @Element(name = "creator", required = false) @Namespace(prefix = "dc", reference = "http://purl.org/dc/elements/1.1/") private String author; @@ -113,4 +116,12 @@ public class RSSItem extends AItem { public void setMediaContents(List mediaContents) { this.mediaContents = mediaContents; } + + public RSSEnclosure getEnclosure() { + return enclosure; + } + + public void setEnclosure(RSSEnclosure enclosure) { + this.enclosure = enclosure; + } } diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSMediaContent.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSMediaContent.java index e01a8319..1936212c 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSMediaContent.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/rss/RSSMediaContent.java @@ -27,8 +27,4 @@ public class RSSMediaContent { public void setMedium(String medium) { this.medium = medium; } - - public boolean isContentAnImage() { - return medium.equals("image") || medium.equals("image/jpeg") || medium.equals("image/png"); - } }