Remove unnecessary autodownload code (#6832)
This should not change any behavior. The retry count and timing are managed by WorkManager, so this code is irrelevant.
This commit is contained in:
parent
7508e15ab1
commit
9db26b7bab
@ -69,7 +69,9 @@ public class AutomaticDownloadAlgorithm {
|
||||
Iterator<FeedItem> it = candidates.iterator();
|
||||
while (it.hasNext()) {
|
||||
FeedItem item = it.next();
|
||||
if (!item.isAutoDownloadable(System.currentTimeMillis())
|
||||
if (!item.isAutoDownloadEnabled()
|
||||
|| item.isDownloaded()
|
||||
|| !item.hasMedia()
|
||||
|| PlaybackStatus.isPlaying(item.getMedia())
|
||||
|| item.getFeed().isLocalFeed()) {
|
||||
it.remove();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.model.feed.FeedMedia;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -11,13 +10,11 @@ import java.util.Date;
|
||||
import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FeedItemTest {
|
||||
|
||||
private static final String TEXT_LONG = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
||||
private static final String TEXT_SHORT = "Lorem ipsum";
|
||||
private static final long ONE_HOUR = 1000L * 3600L;
|
||||
|
||||
private FeedItem original;
|
||||
private FeedItem changedFeedItem;
|
||||
@ -139,36 +136,4 @@ public class FeedItemTest {
|
||||
item.setDescriptionIfLonger(contentEncoded);
|
||||
assertEquals(TEXT_LONG, item.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoDownloadBackoff() {
|
||||
FeedItem item = new FeedItem();
|
||||
item.setMedia(new FeedMedia(item, "https://example.com/file.mp3", 0, "audio/mpeg"));
|
||||
|
||||
long now = ONE_HOUR; // In reality, this is System.currentTimeMillis()
|
||||
assertTrue(item.isAutoDownloadable(now));
|
||||
item.increaseFailedAutoDownloadAttempts(now);
|
||||
assertFalse(item.isAutoDownloadable(now));
|
||||
|
||||
now += ONE_HOUR;
|
||||
assertTrue(item.isAutoDownloadable(now));
|
||||
item.increaseFailedAutoDownloadAttempts(now);
|
||||
assertFalse(item.isAutoDownloadable(now));
|
||||
|
||||
now += ONE_HOUR;
|
||||
assertFalse(item.isAutoDownloadable(now)); // Should backoff, so more than 1 hour needed
|
||||
|
||||
now += ONE_HOUR;
|
||||
assertTrue(item.isAutoDownloadable(now)); // Now it's enough
|
||||
item.increaseFailedAutoDownloadAttempts(now);
|
||||
item.increaseFailedAutoDownloadAttempts(now);
|
||||
item.increaseFailedAutoDownloadAttempts(now);
|
||||
|
||||
now += 1000L * ONE_HOUR;
|
||||
assertFalse(item.isAutoDownloadable(now)); // Should have given up
|
||||
item.increaseFailedAutoDownloadAttempts(now);
|
||||
|
||||
now += 1000L * ONE_HOUR;
|
||||
assertFalse(item.isAutoDownloadable(now)); // Still given up
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Item (episode) within a feed.
|
||||
@ -65,7 +64,7 @@ public class FeedItem extends FeedComponent implements Serializable {
|
||||
private transient List<Chapter> chapters;
|
||||
private String imageUrl;
|
||||
|
||||
private long autoDownload = 1;
|
||||
private boolean autoDownloadEnabled = true;
|
||||
|
||||
/**
|
||||
* Any tags assigned to this item
|
||||
@ -82,7 +81,7 @@ public class FeedItem extends FeedComponent implements Serializable {
|
||||
* */
|
||||
public FeedItem(long id, String title, String link, Date pubDate, String paymentLink, long feedId,
|
||||
boolean hasChapters, String imageUrl, int state,
|
||||
String itemIdentifier, long autoDownload, String podcastIndexChapterUrl) {
|
||||
String itemIdentifier, boolean autoDownloadEnabled, String podcastIndexChapterUrl) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.link = link;
|
||||
@ -93,7 +92,7 @@ public class FeedItem extends FeedComponent implements Serializable {
|
||||
this.imageUrl = imageUrl;
|
||||
this.state = state;
|
||||
this.itemIdentifier = itemIdentifier;
|
||||
this.autoDownload = autoDownload;
|
||||
this.autoDownloadEnabled = autoDownloadEnabled;
|
||||
this.podcastIndexChapterUrl = podcastIndexChapterUrl;
|
||||
}
|
||||
|
||||
@ -361,50 +360,11 @@ public class FeedItem extends FeedComponent implements Serializable {
|
||||
}
|
||||
|
||||
public void disableAutoDownload() {
|
||||
this.autoDownload = 0;
|
||||
this.autoDownloadEnabled = false;
|
||||
}
|
||||
|
||||
public long getAutoDownloadAttemptsAndTime() {
|
||||
return autoDownload;
|
||||
}
|
||||
|
||||
public int getFailedAutoDownloadAttempts() {
|
||||
// 0: auto download disabled
|
||||
// 1: auto download enabled (default)
|
||||
// > 1: auto download enabled, timestamp of last failed attempt, last digit denotes number of failed attempts
|
||||
if (autoDownload <= 1) {
|
||||
return 0;
|
||||
}
|
||||
int failedAttempts = (int)(autoDownload % 10);
|
||||
if (failedAttempts == 0) {
|
||||
failedAttempts = 10;
|
||||
}
|
||||
return failedAttempts;
|
||||
}
|
||||
|
||||
public void increaseFailedAutoDownloadAttempts(long now) {
|
||||
if (autoDownload == 0) {
|
||||
return; // Don't re-enable
|
||||
}
|
||||
int failedAttempts = getFailedAutoDownloadAttempts() + 1;
|
||||
if (failedAttempts >= 5) {
|
||||
disableAutoDownload(); // giving up
|
||||
} else {
|
||||
autoDownload = (now / 10) * 10 + failedAttempts;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAutoDownloadable(long now) {
|
||||
if (media == null || media.isDownloaded() || autoDownload == 0) {
|
||||
return false;
|
||||
}
|
||||
if (autoDownload == 1) {
|
||||
return true; // Never failed
|
||||
}
|
||||
int failedAttempts = getFailedAutoDownloadAttempts();
|
||||
long waitingTime = TimeUnit.HOURS.toMillis((long) Math.pow(2, failedAttempts - 1));
|
||||
long lastAttempt = (autoDownload / 10) * 10;
|
||||
return now >= (lastAttempt + waitingTime);
|
||||
public boolean isAutoDownloadEnabled() {
|
||||
return this.autoDownloadEnabled;
|
||||
}
|
||||
|
||||
public boolean isDownloaded() {
|
||||
|
@ -121,9 +121,9 @@ class DBUpgrader {
|
||||
}
|
||||
if (oldVersion <= 14) {
|
||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_AUTO_DOWNLOAD_ATTEMPTS + " INTEGER");
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_AUTO_DOWNLOAD_ENABLED + " INTEGER");
|
||||
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
|
||||
+ " SET " + PodDBAdapter.KEY_AUTO_DOWNLOAD_ATTEMPTS + " = "
|
||||
+ " SET " + PodDBAdapter.KEY_AUTO_DOWNLOAD_ENABLED + " = "
|
||||
+ "(SELECT " + PodDBAdapter.KEY_AUTO_DOWNLOAD_ENABLED
|
||||
+ " FROM " + PodDBAdapter.TABLE_NAME_FEEDS
|
||||
+ " WHERE " + PodDBAdapter.TABLE_NAME_FEEDS + "." + PodDBAdapter.KEY_ID
|
||||
|
@ -95,7 +95,6 @@ public class PodDBAdapter {
|
||||
public static final String KEY_REASON_DETAILED = "reason_detailed";
|
||||
public static final String KEY_DOWNLOADSTATUS_TITLE = "title";
|
||||
public static final String KEY_PLAYBACK_COMPLETION_DATE = "playback_completion_date";
|
||||
public static final String KEY_AUTO_DOWNLOAD_ATTEMPTS = "auto_download";
|
||||
public static final String KEY_AUTO_DOWNLOAD_ENABLED = "auto_download"; // Both tables use the same key
|
||||
public static final String KEY_KEEP_UPDATED = "keep_updated";
|
||||
public static final String KEY_AUTO_DELETE_ACTION = "auto_delete_action";
|
||||
@ -171,7 +170,7 @@ public class PodDBAdapter {
|
||||
+ KEY_MEDIA + " INTEGER," + KEY_FEED + " INTEGER,"
|
||||
+ KEY_HAS_CHAPTERS + " INTEGER," + KEY_ITEM_IDENTIFIER + " TEXT,"
|
||||
+ KEY_IMAGE_URL + " TEXT,"
|
||||
+ KEY_AUTO_DOWNLOAD_ATTEMPTS + " INTEGER,"
|
||||
+ KEY_AUTO_DOWNLOAD_ENABLED + " INTEGER,"
|
||||
+ KEY_PODCASTINDEX_CHAPTER_URL + " TEXT)";
|
||||
|
||||
private static final String CREATE_TABLE_FEED_MEDIA = "CREATE TABLE "
|
||||
@ -259,7 +258,7 @@ public class PodDBAdapter {
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_HAS_CHAPTERS + ", "
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_ITEM_IDENTIFIER + ", "
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_IMAGE_URL + ", "
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_AUTO_DOWNLOAD_ATTEMPTS + ", "
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_AUTO_DOWNLOAD_ENABLED + ", "
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_PODCASTINDEX_CHAPTER_URL;
|
||||
|
||||
private static final String KEYS_FEED_MEDIA =
|
||||
@ -652,7 +651,7 @@ public class PodDBAdapter {
|
||||
}
|
||||
values.put(KEY_HAS_CHAPTERS, item.getChapters() != null || item.hasChapters());
|
||||
values.put(KEY_ITEM_IDENTIFIER, item.getItemIdentifier());
|
||||
values.put(KEY_AUTO_DOWNLOAD_ATTEMPTS, item.getAutoDownloadAttemptsAndTime());
|
||||
values.put(KEY_AUTO_DOWNLOAD_ENABLED, item.isAutoDownloadEnabled());
|
||||
values.put(KEY_IMAGE_URL, item.getImageUrl());
|
||||
values.put(KEY_PODCASTINDEX_CHAPTER_URL, item.getPodcastIndexChapterUrl());
|
||||
|
||||
|
@ -25,7 +25,7 @@ public abstract class FeedItemCursorMapper {
|
||||
int indexHasChapters = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_HAS_CHAPTERS);
|
||||
int indexRead = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_READ);
|
||||
int indexItemIdentifier = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_ITEM_IDENTIFIER);
|
||||
int indexAutoDownload = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_AUTO_DOWNLOAD_ATTEMPTS);
|
||||
int indexAutoDownload = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_AUTO_DOWNLOAD_ENABLED);
|
||||
int indexImageUrl = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_IMAGE_URL);
|
||||
int indexPodcastIndexChapterUrl = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_PODCASTINDEX_CHAPTER_URL);
|
||||
|
||||
@ -38,11 +38,11 @@ public abstract class FeedItemCursorMapper {
|
||||
boolean hasChapters = cursor.getInt(indexHasChapters) > 0;
|
||||
int state = cursor.getInt(indexRead);
|
||||
String itemIdentifier = cursor.getString(indexItemIdentifier);
|
||||
long autoDownload = cursor.getLong(indexAutoDownload);
|
||||
boolean autoDownloadEnabled = cursor.getLong(indexAutoDownload) > 0;
|
||||
String imageUrl = cursor.getString(indexImageUrl);
|
||||
String podcastIndexChapterUrl = cursor.getString(indexPodcastIndexChapterUrl);
|
||||
|
||||
return new FeedItem(id, title, link, pubDate, paymentLink, feedId,
|
||||
hasChapters, imageUrl, state, itemIdentifier, autoDownload, podcastIndexChapterUrl);
|
||||
hasChapters, imageUrl, state, itemIdentifier, autoDownloadEnabled, podcastIndexChapterUrl);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user