mirror of https://github.com/readrops/Readrops.git
Add support for another RSS 2.0 date format (really close to the main one) and media enclosure tag
This commit is contained in:
parent
518cada73f
commit
9bf6e2613f
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@ public class RSSItem extends AItem {
|
|||
@Namespace(prefix = "media")
|
||||
private List<RSSMediaContent> 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<RSSMediaContent> mediaContents) {
|
||||
this.mediaContents = mediaContents;
|
||||
}
|
||||
|
||||
public RSSEnclosure getEnclosure() {
|
||||
return enclosure;
|
||||
}
|
||||
|
||||
public void setEnclosure(RSSEnclosure enclosure) {
|
||||
this.enclosure = enclosure;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue