add support for another date format and modify item activity date format
This commit is contained in:
parent
5c722b38c9
commit
3290c55e65
@ -116,7 +116,7 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
this.itemWithFeed = itemWithFeed;
|
this.itemWithFeed = itemWithFeed;
|
||||||
Item item = itemWithFeed.getItem();
|
Item item = itemWithFeed.getItem();
|
||||||
|
|
||||||
date.setText(DateUtils.formatedDateByLocal(item.getPubDate()));
|
date.setText(DateUtils.formatedDateTimeByLocal(item.getPubDate()));
|
||||||
|
|
||||||
if (item.getImageLink() == null)
|
if (item.getImageLink() == null)
|
||||||
toolbar.setTitle(itemWithFeed.getFeedName());
|
toolbar.setTitle(itemWithFeed.getFeedName());
|
||||||
|
@ -166,16 +166,30 @@ public class Item {
|
|||||||
for(RSSItem item : items) {
|
for(RSSItem item : items) {
|
||||||
Item newItem = new Item();
|
Item newItem = new Item();
|
||||||
|
|
||||||
newItem.setAuthor(item.getAuthor());
|
newItem.setAuthor(item.getCreator());
|
||||||
newItem.setContent(item.getContent());
|
newItem.setContent(item.getContent());
|
||||||
newItem.setDescription(item.getDescription());
|
newItem.setDescription(item.getDescription());
|
||||||
newItem.setGuid(item.getGuid());
|
newItem.setGuid(item.getGuid());
|
||||||
newItem.setTitle(item.getTitle());
|
newItem.setTitle(item.getTitle());
|
||||||
|
|
||||||
if (Pattern.compile(DateUtils.RSS_1_DATE_FORMAT_REGEX).matcher(item.getPubDate()).matches())
|
// I wish I hadn't done that...
|
||||||
newItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_1_DATE_FORMAT));
|
if (Pattern.compile(DateUtils.RSS_ALTERNATIVE_DATE_FORMAT_REGEX).matcher(item.getDate()).matches())
|
||||||
else
|
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.RSS_2_DATE_FORMAT_3));
|
||||||
newItem.setPubDate(DateUtils.stringToDateTime(item.getPubDate(), DateUtils.RSS_2_DATE_FORMAT));
|
else {
|
||||||
|
try {
|
||||||
|
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.RSS_2_DATE_FORMAT_2));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.RSS_2_DATE_FORMAT));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newItem.setLink(item.getLink());
|
newItem.setLink(item.getLink());
|
||||||
newItem.setFeedId(feed.getId());
|
newItem.setFeedId(feed.getId());
|
||||||
|
@ -6,13 +6,16 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
|
import org.joda.time.format.DateTimeFormat;
|
||||||
|
import org.joda.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public final class DateUtils {
|
public final class DateUtils {
|
||||||
|
|
||||||
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_ALTERNATIVE_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_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 RSS_2_DATE_FORMAT_2 = "EEE, dd MMM yyyy HH:mm:ss z";
|
||||||
|
public static final String RSS_2_DATE_FORMAT_3 = "EEE, dd MMM yyyy HH:mm:ss 'Z'";
|
||||||
|
|
||||||
public static final String ATOM_JSON_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
|
public static final String ATOM_JSON_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
|
||||||
|
|
||||||
@ -26,4 +29,10 @@ public final class DateUtils {
|
|||||||
|
|
||||||
return df.format(dateTime.toDate());
|
return df.format(dateTime.toDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatedDateTimeByLocal(LocalDateTime dateTime) {
|
||||||
|
return DateTimeFormat.mediumDateTime()
|
||||||
|
.withLocale(Locale.getDefault())
|
||||||
|
.print(dateTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user