Remove check for updated attributes, just update them (#7018)
This commit is contained in:
parent
f6b45e7162
commit
a065d3fc33
|
@ -216,18 +216,12 @@ public final class DBTasks {
|
||||||
Collections.sort(newFeed.getItems(), new FeedItemPubdateComparator());
|
Collections.sort(newFeed.getItems(), new FeedItemPubdateComparator());
|
||||||
|
|
||||||
if (newFeed.getPageNr() == savedFeed.getPageNr()) {
|
if (newFeed.getPageNr() == savedFeed.getPageNr()) {
|
||||||
if (savedFeed.compareWithOther(newFeed)) {
|
|
||||||
Log.d(TAG, "Feed has updated attribute values. Updating old feed's attributes");
|
|
||||||
savedFeed.updateFromOther(newFeed);
|
savedFeed.updateFromOther(newFeed);
|
||||||
}
|
savedFeed.getPreferences().updateFromOther(newFeed.getPreferences());
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "New feed has a higher page number.");
|
Log.d(TAG, "New feed has a higher page number.");
|
||||||
savedFeed.setNextPageLink(newFeed.getNextPageLink());
|
savedFeed.setNextPageLink(newFeed.getNextPageLink());
|
||||||
}
|
}
|
||||||
if (savedFeed.getPreferences().compareWithOther(newFeed.getPreferences())) {
|
|
||||||
Log.d(TAG, "Feed has updated preferences. Updating old feed's preferences");
|
|
||||||
savedFeed.getPreferences().updateFromOther(newFeed.getPreferences());
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the most recent date now, before we start changing the list
|
// get the most recent date now, before we start changing the list
|
||||||
FeedItem priorMostRecent = savedFeed.getMostRecentItem();
|
FeedItem priorMostRecent = savedFeed.getMostRecentItem();
|
||||||
|
|
|
@ -8,9 +8,7 @@ import de.danoeh.antennapod.model.feed.SortOrder;
|
||||||
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed;
|
import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
public class FeedTest {
|
public class FeedTest {
|
||||||
|
|
||||||
|
@ -24,92 +22,40 @@ public class FeedTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompareWithOther_feedImageDownloadUrlChanged() throws Exception {
|
public void testUpdateFromOther_feedImageDownloadUrlChanged() {
|
||||||
setNewFeedImageDownloadUrl();
|
changedFeed.setImageUrl("http://example.com/new_picture");
|
||||||
feedHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompareWithOther_sameFeedImage() throws Exception {
|
|
||||||
changedFeed.setImageUrl(FeedMother.IMAGE_URL);
|
|
||||||
feedHasNotChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompareWithOther_feedImageRemoved() throws Exception {
|
|
||||||
feedImageRemoved();
|
|
||||||
feedHasNotChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedImageDownloadUrlChanged() throws Exception {
|
|
||||||
setNewFeedImageDownloadUrl();
|
|
||||||
original.updateFromOther(changedFeed);
|
original.updateFromOther(changedFeed);
|
||||||
feedImageWasUpdated();
|
assertEquals(original.getImageUrl(), changedFeed.getImageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateFromOther_feedImageRemoved() throws Exception {
|
public void testUpdateFromOther_feedImageRemoved() {
|
||||||
feedImageRemoved();
|
changedFeed.setImageUrl(null);
|
||||||
original.updateFromOther(changedFeed);
|
original.updateFromOther(changedFeed);
|
||||||
feedImageWasNotUpdated();
|
assertEquals(anyFeed().getImageUrl(), original.getImageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateFromOther_feedImageAdded() throws Exception {
|
public void testUpdateFromOther_feedImageAdded() {
|
||||||
feedHadNoImage();
|
original.setImageUrl(null);
|
||||||
setNewFeedImageDownloadUrl();
|
changedFeed.setImageUrl("http://example.com/new_picture");
|
||||||
original.updateFromOther(changedFeed);
|
original.updateFromOther(changedFeed);
|
||||||
feedImageWasUpdated();
|
assertEquals(original.getImageUrl(), changedFeed.getImageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetSortOrder_OnlyIntraFeedSortAllowed() throws Exception {
|
public void testSetSortOrder_OnlyIntraFeedSortAllowed() {
|
||||||
for (SortOrder sortOrder : SortOrder.values()) {
|
for (SortOrder sortOrder : SortOrder.values()) {
|
||||||
if (sortOrder.scope == SortOrder.Scope.INTRA_FEED) {
|
if (sortOrder.scope == SortOrder.Scope.INTRA_FEED) {
|
||||||
original.setSortOrder(sortOrder); // should be okay
|
original.setSortOrder(sortOrder); // should be okay
|
||||||
} else {
|
} else {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> original.setSortOrder(sortOrder));
|
||||||
original.setSortOrder(sortOrder);
|
|
||||||
fail("SortOrder " + sortOrder + " should not be allowed on a feed");
|
|
||||||
} catch (IllegalArgumentException iae) {
|
|
||||||
// expected exception
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetSortOrder_NullAllowed() throws Exception {
|
public void testSetSortOrder_NullAllowed() {
|
||||||
original.setSortOrder(null); // should be okay
|
original.setSortOrder(null); // should be okay
|
||||||
}
|
}
|
||||||
|
|
||||||
private void feedHasNotChanged() {
|
|
||||||
assertFalse(original.compareWithOther(changedFeed));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedHadNoImage() {
|
|
||||||
original.setImageUrl(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setNewFeedImageDownloadUrl() {
|
|
||||||
changedFeed.setImageUrl("http://example.com/new_picture");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedHasChanged() {
|
|
||||||
assertTrue(original.compareWithOther(changedFeed));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedImageRemoved() {
|
|
||||||
changedFeed.setImageUrl(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedImageWasUpdated() {
|
|
||||||
assertEquals(original.getImageUrl(), changedFeed.getImageUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedImageWasNotUpdated() {
|
|
||||||
assertEquals(anyFeed().getImageUrl(), original.getImageUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -94,7 +94,7 @@ public class FeedItemUtilTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FeedItem createFeedItem(String feedLink, String itemLink) {
|
private static FeedItem createFeedItem(String feedLink, String itemLink) {
|
||||||
Feed feed = new Feed();
|
Feed feed = new Feed("http://example.com/feed", null);
|
||||||
feed.setLink(feedLink);
|
feed.setLink(feedLink);
|
||||||
FeedItem feedItem = new FeedItem();
|
FeedItem feedItem = new FeedItem();
|
||||||
feedItem.setLink(itemLink);
|
feedItem.setLink(itemLink);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package de.danoeh.antennapod.model.feed;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -149,13 +148,6 @@ public class Feed {
|
||||||
imageUrl, fileUrl, downloadUrl, downloaded, false, null, null, null, false);
|
imageUrl, fileUrl, downloadUrl, downloaded, false, null, null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This constructor can be used when parsing feed data. Only the 'lastUpdate' and 'items' field are initialized.
|
|
||||||
*/
|
|
||||||
public Feed() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is used for requesting a feed download (it must not be used for anything else!). It should NOT be
|
* This constructor is used for requesting a feed download (it must not be used for anything else!). It should NOT be
|
||||||
* used if the title of the feed is already known.
|
* used if the title of the feed is already known.
|
||||||
|
@ -257,64 +249,6 @@ public class Feed {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Compare's this FeedFile's attribute values with another FeedFile's
|
|
||||||
* attribute values. This method will only compare attributes which were
|
|
||||||
* read from the feed.
|
|
||||||
*
|
|
||||||
* @return true if attribute values are different, false otherwise
|
|
||||||
*/
|
|
||||||
public boolean compareWithOther(Feed other) {
|
|
||||||
if (!StringUtils.equals(downloadUrl, other.downloadUrl)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (other.imageUrl != null) {
|
|
||||||
if (imageUrl == null || !TextUtils.equals(imageUrl, other.imageUrl)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!TextUtils.equals(feedTitle, other.feedTitle)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (other.feedIdentifier != null) {
|
|
||||||
if (feedIdentifier == null || !feedIdentifier.equals(other.feedIdentifier)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.link != null) {
|
|
||||||
if (link == null || !link.equals(other.link)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.description != null) {
|
|
||||||
if (description == null || !description.equals(other.description)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.language != null) {
|
|
||||||
if (language == null || !language.equals(other.language)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.author != null) {
|
|
||||||
if (author == null || !author.equals(other.author)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.fundingList != null) {
|
|
||||||
if (fundingList == null || !fundingList.equals(other.fundingList)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.isPaged() && !this.isPaged()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!TextUtils.equals(other.getNextPageLink(), this.getNextPageLink())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FeedItem getMostRecentItem() {
|
public FeedItem getMostRecentItem() {
|
||||||
// we could sort, but we don't need to, a simple search is fine...
|
// we could sort, but we don't need to, a simple search is fine...
|
||||||
Date mostRecentDate = new Date(0);
|
Date mostRecentDate = new Date(0);
|
||||||
|
|
|
@ -149,25 +149,6 @@ public class FeedPreferences implements Serializable {
|
||||||
this.keepUpdated = keepUpdated;
|
this.keepUpdated = keepUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Compare another FeedPreferences with this one. The feedID, autoDownload and AutoDeleteAction attribute are excluded from the
|
|
||||||
* comparison.
|
|
||||||
*
|
|
||||||
* @return True if the two objects are different.
|
|
||||||
*/
|
|
||||||
public boolean compareWithOther(FeedPreferences other) {
|
|
||||||
if (other == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!TextUtils.equals(username, other.username)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!TextUtils.equals(password, other.password)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update this FeedPreferences object from another one. The feedID, autoDownload and AutoDeleteAction attributes are excluded
|
* Update this FeedPreferences object from another one. The feedID, autoDownload and AutoDeleteAction attributes are excluded
|
||||||
* from the update.
|
* from the update.
|
||||||
|
|
Loading…
Reference in New Issue