Bug 1241810 - Review Follow-up: Remove duplicated hasBeenUpdated() / isNewer() methods. r=me draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 23 Mar 2016 14:49:00 +0100
changeset 343943 9e87f1a3ae1dc6ebcdeb6ceab5948901191d0828
parent 343942 aaf1cd7c8adb04defa2e795f258cd721b53d4fe8
child 343944 c5f93e7093027a5ce2c1f8d45c6a351a44a70a90
push id13713
push users.kaspari@gmail.com
push dateWed, 23 Mar 2016 15:10:41 +0000
reviewersme
bugs1241810
milestone48.0a1
Bug 1241810 - Review Follow-up: Remove duplicated hasBeenUpdated() / isNewer() methods. r=me MozReview-Commit-ID: 1Q0IoZ1DqJP
mobile/android/base/java/org/mozilla/gecko/feeds/parser/Feed.java
mobile/android/base/java/org/mozilla/gecko/feeds/subscriptions/FeedSubscription.java
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/parser/Feed.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/parser/Feed.java
@@ -47,44 +47,16 @@ public class Feed {
      */
     /* package-private */ boolean isSufficientlyComplete() {
         return !TextUtils.isEmpty(title) &&
                 lastItem != null &&
                 !TextUtils.isEmpty(lastItem.getURL()) &&
                 !TextUtils.isEmpty(lastItem.getTitle());
     }
 
-    /**
-     * Guesstimate if the given feed is a newer representation of this feed.
-     */
-    public boolean hasBeenUpdated(Feed newFeed) {
-        final Item otherItem = newFeed.getLastItem();
-
-        if (lastItem.getTimestamp() > otherItem.getTimestamp()) {
-            // The timestamp is from a newer date so we expect that this item is a new item. But this
-            // could also mean that the timestamp of an already existing item has been updated. We
-            // accept that and assume that the content will have changed too in this case.
-            return true;
-        }
-
-        if (lastItem.getTimestamp() == otherItem.getTimestamp() && lastItem.getTimestamp() != 0) {
-            // We have a timestamp that is not zero and this item has still the timestamp: It's very
-            // likely that we are looking at the same item. We assume this is not new content.
-            return false;
-        }
-
-        if (!lastItem.getURL().equals(otherItem.getURL())) {
-            // The URL changed: It is very likely that this is a new item. At least it has been updated
-            // in a way that we just treat it as new content here.
-            return true;
-        }
-
-        return false;
-    }
-
     public String getTitle() {
         return title;
     }
 
     public String getWebsiteURL() {
         return websiteURL;
     }
 
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/subscriptions/FeedSubscription.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/subscriptions/FeedSubscription.java
@@ -69,30 +69,36 @@ public class FeedSubscription {
         lastItemTimestamp = response.feed.getLastItem().getTimestamp();
         etag = response.etag;
         lastModified = response.lastModified;
     }
 
     /**
      * Guesstimate if this response is a newer representation of the feed.
      */
-    public boolean isNewer(FeedFetcher.FeedResponse response) {
+    public boolean hasBeenUpdated(FeedFetcher.FeedResponse response) {
         final Item otherItem = response.feed.getLastItem();
+        final Item lastItem = response.feed.getLastItem();
 
-        if (lastItemTimestamp > otherItem.getTimestamp()) {
-            return true; // How to detect if this same item and it only has been updated?
+        if (lastItem.getTimestamp() > otherItem.getTimestamp()) {
+            // The timestamp is from a newer date so we expect that this item is a new item. But this
+            // could also mean that the timestamp of an already existing item has been updated. We
+            // accept that and assume that the content will have changed too in this case.
+            return true;
         }
 
-        if (lastItemTimestamp == otherItem.getTimestamp() &&
-                lastItemTimestamp != 0) {
+        if (lastItem.getTimestamp() == otherItem.getTimestamp() && lastItem.getTimestamp() != 0) {
+            // We have a timestamp that is not zero and this item has still the timestamp: It's very
+            // likely that we are looking at the same item. We assume this is not new content.
             return false;
         }
 
-        if (lastItemUrl == null || !lastItemUrl.equals(otherItem.getURL())) {
-            // URL changed: Probably a different item
+        if (!lastItem.getURL().equals(otherItem.getURL())) {
+            // The URL changed: It is very likely that this is a new item. At least it has been updated
+            // in a way that we just treat it as new content here.
             return true;
         }
 
         return false;
     }
 
     public String getFeedUrl() {
         return feedUrl;