mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-01 11:39:14 +01:00
#2685: add "12 hours after finishing" option for auto download episodes cleanup
This commit is contained in:
parent
8252f6a41d
commit
5bc497009a
@ -67,6 +67,7 @@ import de.danoeh.antennapod.core.export.opml.OpmlWriter;
|
||||
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.GpodnetSyncService;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.flattr.FlattrUtils;
|
||||
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
|
||||
import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
||||
@ -839,15 +840,19 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||
R.array.episode_cleanup_values);
|
||||
String[] entries = new String[values.length];
|
||||
for (int x = 0; x < values.length; x++) {
|
||||
int v = Integer.parseInt(values[x]);
|
||||
float v = Float.parseFloat(values[x]);
|
||||
if (v == UserPreferences.EPISODE_CLEANUP_QUEUE) {
|
||||
entries[x] = res.getString(R.string.episode_cleanup_queue_removal);
|
||||
} else if (v == UserPreferences.EPISODE_CLEANUP_NULL){
|
||||
entries[x] = res.getString(R.string.episode_cleanup_never);
|
||||
} else if (v == 0) {
|
||||
entries[x] = res.getString(R.string.episode_cleanup_after_listening);
|
||||
} else if (v > 0 && v < 1) {
|
||||
int numHours = Converter.numberOfDaysFloatToNumberOfHours(v);
|
||||
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_hours_after_listening, numHours, numHours);
|
||||
} else {
|
||||
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, v, v);
|
||||
int vInt = (int)v;
|
||||
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, vInt, vInt);
|
||||
}
|
||||
}
|
||||
pref.setEntries(entries);
|
||||
|
@ -674,7 +674,7 @@ public class UserPreferences {
|
||||
}
|
||||
|
||||
public static EpisodeCleanupAlgorithm getEpisodeCleanupAlgorithm() {
|
||||
int cleanupValue = Integer.parseInt(prefs.getString(PREF_EPISODE_CLEANUP, "-1"));
|
||||
float cleanupValue = Float.parseFloat(prefs.getString(PREF_EPISODE_CLEANUP, "-1"));
|
||||
if (cleanupValue == EPISODE_CLEANUP_QUEUE) {
|
||||
return new APQueueCleanupAlgorithm();
|
||||
} else if (cleanupValue == EPISODE_CLEANUP_NULL) {
|
||||
|
@ -13,6 +13,7 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
|
||||
/**
|
||||
* Implementation of the EpisodeCleanupAlgorithm interface used by AntennaPod.
|
||||
@ -20,10 +21,11 @@ import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm {
|
||||
|
||||
private static final String TAG = "APCleanupAlgorithm";
|
||||
/** the number of days after playback to wait before an item is eligible to be cleaned up */
|
||||
private final int numberOfDaysAfterPlayback;
|
||||
/** the number of days after playback to wait before an item is eligible to be cleaned up.
|
||||
Fractional for number of hours, e.g., 0.5 = 12 hours, 0.0416 = 1 hour. */
|
||||
private final float numberOfDaysAfterPlayback;
|
||||
|
||||
public APCleanupAlgorithm(int numberOfDaysAfterPlayback) {
|
||||
public APCleanupAlgorithm(float numberOfDaysAfterPlayback) {
|
||||
this.numberOfDaysAfterPlayback = numberOfDaysAfterPlayback;
|
||||
}
|
||||
|
||||
@ -81,9 +83,8 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm {
|
||||
private List<FeedItem> getCandidates() {
|
||||
List<FeedItem> candidates = new ArrayList<>();
|
||||
List<FeedItem> downloadedItems = DBReader.getDownloadedItems();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1 * numberOfDaysAfterPlayback);
|
||||
Date mostRecentDateForDeletion = cal.getTime();
|
||||
|
||||
Date mostRecentDateForDeletion = minusDays(new Date(), numberOfDaysAfterPlayback);
|
||||
for (FeedItem item : downloadedItems) {
|
||||
if (item.hasMedia()
|
||||
&& item.getMedia().isDownloaded()
|
||||
@ -108,5 +109,19 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm {
|
||||
return getNumEpisodesToCleanup(0);
|
||||
}
|
||||
|
||||
public int getNumberOfDaysAfterPlayback() { return numberOfDaysAfterPlayback; }
|
||||
public float getNumberOfDaysAfterPlayback() { return numberOfDaysAfterPlayback; }
|
||||
|
||||
private static Date minusDays(Date baseDate, float numberOfDays) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(baseDate);
|
||||
|
||||
int integral = (int)numberOfDays;
|
||||
float fraction = numberOfDays - integral;
|
||||
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1 * integral);
|
||||
cal.add(Calendar.HOUR_OF_DAY, -1 * Converter.numberOfDaysFloatToNumberOfHours(fraction));
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,6 +130,11 @@ public final class Converter {
|
||||
return String.format(Locale.getDefault(), "%.1f ", hours) + context.getString(R.string.time_hours);
|
||||
}
|
||||
|
||||
|
||||
public static int numberOfDaysFloatToNumberOfHours(float numberOfDays) {
|
||||
return (int)Math.ceil(numberOfDays * 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the volume as read as the progress from a SeekBar scaled to 100 and as saved in
|
||||
* UserPreferences to the format taken by setVolume methods.
|
||||
|
@ -68,6 +68,7 @@
|
||||
<string-array name="episode_cleanup_values">
|
||||
<item>-1</item>
|
||||
<item>0</item>
|
||||
<item>0.5</item> <!-- 12 hours -->
|
||||
<item>1</item>
|
||||
<item>3</item>
|
||||
<item>5</item>
|
||||
|
@ -105,6 +105,10 @@
|
||||
<string name="episode_cleanup_never">Never</string>
|
||||
<string name="episode_cleanup_queue_removal">When not in queue</string>
|
||||
<string name="episode_cleanup_after_listening">After finishing</string>
|
||||
<plurals name="episode_cleanup_hours_after_listening">
|
||||
<item quantity="one">1 hour after finishing</item>
|
||||
<item quantity="other">%d hours after finishing</item>
|
||||
</plurals>
|
||||
<plurals name="episode_cleanup_days_after_listening">
|
||||
<item quantity="one">1 day after finishing</item>
|
||||
<item quantity="other">%d days after finishing</item>
|
||||
|
Loading…
Reference in New Issue
Block a user