From 9e5ab1b191f9602312a5f275884e631fd1ba374b Mon Sep 17 00:00:00 2001 From: jprocter Date: Sun, 25 Sep 2011 15:02:31 +0100 Subject: [PATCH] fix logic to ensure first check for news is correct and records last modified for next check (JAL-943) --- src/jalview/gui/BlogReader.java | 52 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/jalview/gui/BlogReader.java b/src/jalview/gui/BlogReader.java index 2759eff..989d6c9 100644 --- a/src/jalview/gui/BlogReader.java +++ b/src/jalview/gui/BlogReader.java @@ -16,6 +16,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeListener; import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -67,8 +68,6 @@ import org.robsite.jswingreader.ui.util.ContextMenuMouseAdapter; public class BlogReader extends GBlogReader { - private JButton buttonAbout = new JButton(); - private JButton buttonRefresh = new JButton(); private JToolBar toolBar = new JToolBar(); @@ -85,10 +84,6 @@ public class BlogReader extends GBlogReader private JPanel bottomPanel = new JPanel(); - private BorderLayout borderLayout2 = new BorderLayout(); - - private BorderLayout borderLayout3 = new BorderLayout(); - private JSplitPane topBottomSplitPane = new JSplitPane(); private JList listItems = new JList(new DefaultListModel()); @@ -253,18 +248,24 @@ public class BlogReader extends GBlogReader */ private boolean checkForNew(Channel chan, boolean updateItems) { + if (!updating || updateItems) { newsnew = false; } + java.util.Date earliest=null; + try { + earliest = new SimpleDateFormat("YYYY-MM-DD").parse(chan.getHTTPLastModified()); + } catch (Exception x) {}; if (chan != null && chan.getItems() != null) { + Cache.log.debug("Scanning news items: newsnew="+newsnew+" and lastDate is "+lastDate); for (Item i : (List) chan.getItems()) { - boolean isread = (lastDate != null && i.getPublishDate() != null && !lastDate + boolean isread = lastDate==null ? false : (i.getPublishDate() != null && !lastDate .before(i.getPublishDate())); - if (i.getPublishDate() != null && (!updating || updateItems)) + if (!updating || updateItems) { newsnew |= !isread; } @@ -272,8 +273,19 @@ public class BlogReader extends GBlogReader { i.setRead(isread); } + if (i.getPublishDate()!=null && !i.isRead()) + { + if (earliest==null || earliest.after(i.getPublishDate())) + { + earliest=i.getPublishDate(); + } + } } } + if (!updateItems && !updating && lastDate==null) + { + lastDate=earliest; + } return newsnew; } @@ -286,22 +298,28 @@ public class BlogReader extends GBlogReader private void saveLastM(Item item) { - if (item != null && item.getPublishDate() != null - && (lastDate == null || item.getPublishDate().after(lastDate))) + if (item != null) { - lastDate = item.getPublishDate(); - if (lastDate != null) + if (item.getPublishDate() != null) { - jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", - lastDate); - jalview.bin.Cache.log.info("Saved last read date as " - + jalview.bin.Cache.date_format.format(lastDate)); - + if (lastDate==null || item.getPublishDate().after(lastDate)) + { + lastDate = item.getPublishDate(); + } } + if (_channelModel.getElementAt(0) != null) { checkForNew((Channel) _channelModel.getElementAt(0), false); } + if (lastDate != null) + { + jalview.bin.Cache.setDateProperty( + "JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate); + jalview.bin.Cache.log.info("Saved last read date as " + + jalview.bin.Cache.date_format.format(lastDate)); + + } } } -- 1.7.10.2