diff options
6 files changed, 40 insertions, 10 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 31b2cbcb2..7f497c7aa 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -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); diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index c44999c88..a8d0b6ba1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -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) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java index e94874453..c9dd8f374 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java @@ -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(); + } + } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java index 3cb226add..5915d216c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java @@ -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. diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 12961504c..2c2ad0847 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -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> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 9dd928311..e217dda80 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -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> |