Merge pull request #1816 from mfietz/issue/1529-delayed-part2

Reset episode to new if episode file is added later
This commit is contained in:
Tom Hennen 2016-03-24 15:52:29 -04:00
commit d249d0f228
3 changed files with 30 additions and 5 deletions

View File

@ -5,12 +5,14 @@ import android.test.FlakyTest;
import android.test.InstrumentationTestCase;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
@ -120,6 +122,32 @@ public class DBTasksTest extends InstrumentationTestCase {
updatedFeedTest(feedFromDB, feedID, itemIDs, NUM_ITEMS_OLD, NUM_ITEMS_NEW);
}
public void testUpdateFeedMediaUrlResetState() {
final Feed feed = new Feed("url", null, "title");
FeedItem item = new FeedItem(0, "item", "id", "link", new Date(), FeedItem.PLAYED, feed);
feed.setItems(Arrays.asList(item));
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
// ensure that objects have been saved in db, then reset
assertTrue(feed.getId() != 0);
assertTrue(item.getId() != 0);
FeedMedia media = new FeedMedia(item, "url", 1024, "mime/type");
item.setMedia(media);
feed.setItems(Arrays.asList(item));
final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
assertTrue(feed != newFeed);
final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
assertTrue("state: " + feedItemFromDB.getState(), feedItemFromDB.isNew());
}
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, final int NUM_ITEMS_OLD, final int NUM_ITEMS_NEW) {
assertTrue(newFeed.getId() == feedID);
assertTrue(newFeed.getItems().size() == NUM_ITEMS_NEW + NUM_ITEMS_OLD);

View File

@ -195,6 +195,8 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
if (other.media != null) {
if (media == null) {
setMedia(other.media);
// reset to new if feed item did link to a file before
setNew();
} else if (media.compareWithOther(other.media)) {
media.updateFromOther(other.media);
}

View File

@ -8,7 +8,6 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import java.util.Date;
import java.util.List;
@ -168,10 +167,6 @@ public class FeedMedia extends FeedFile implements Playable {
}
public void updateFromOther(FeedMedia other) {
// reset to new if feed item did link to a file before
if(TextUtils.isEmpty(download_url) && !TextUtils.isEmpty(other.download_url)) {
item.setNew();
}
super.updateFromOther(other);
if (other.size > 0) {
size = other.size;