episode cleanup 12 hour option - use hours internally part 2 (persisted shared preference)

requires data migartion: app versionCode increased to 1070196
This commit is contained in:
orionlee 2018-11-14 14:14:15 -08:00
parent 566a682122
commit d1c73dda5b
8 changed files with 31 additions and 23 deletions

View File

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.danoeh.antennapod"
android:installLocation="auto"
android:versionCode="1070195"
android:versionCode="1070196"
android:versionName="1.7.1">
<!--
Version code schema:

View File

@ -67,7 +67,6 @@ 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;
@ -840,19 +839,18 @@ 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++) {
float v = Float.parseFloat(values[x]);
int v = Integer.parseInt(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 if (v > 0 && v < 24) {
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_hours_after_listening, v, v);
} else {
int vInt = (int)v;
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, vInt, vInt);
int numDays = (int)(v / 24); // assume underlying value will be fractions, e.g., 36 (hours)
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, numDays, numDays);
}
}
pref.setEntries(entries);

View File

@ -63,6 +63,14 @@ class UpdateManager {
UserPreferences.enableSonic();
}
}
if(oldVersionCode < 1070196) {
// migrate episode cleanup value (unit changed from days to hours)
int oldValueInDays = UserPreferences.getEpisodeCleanupValue();
if (oldValueInDays > 0) {
UserPreferences.setEpisodeCleanupValue(oldValueInDays * 24);
} // else 0 or special negative values, no change needed
}
}
}

View File

@ -674,7 +674,7 @@ public class UserPreferences {
}
public static EpisodeCleanupAlgorithm getEpisodeCleanupAlgorithm() {
float cleanupValue = Float.parseFloat(prefs.getString(PREF_EPISODE_CLEANUP, "-1"));
int cleanupValue = getEpisodeCleanupValue();
if (cleanupValue == EPISODE_CLEANUP_QUEUE) {
return new APQueueCleanupAlgorithm();
} else if (cleanupValue == EPISODE_CLEANUP_NULL) {
@ -684,6 +684,16 @@ public class UserPreferences {
}
}
public static int getEpisodeCleanupValue() {
return Integer.parseInt(prefs.getString(PREF_EPISODE_CLEANUP, "-1"));
}
public static void setEpisodeCleanupValue(int episodeCleanupValue) {
prefs.edit()
.putString(PREF_EPISODE_CLEANUP, Integer.toString(episodeCleanupValue))
.apply();
}
/**
* Return the folder where the app stores all of its data. This method will
* return the standard data folder if none has been set by the user.

View File

@ -29,10 +29,6 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm {
this.numberOfHoursAfterPlayback = numberOfHoursAfterPlayback;
}
public APCleanupAlgorithm(float numberOfDaysAfterPlayback) { // TODO: temporary, until callers are migrated
this.numberOfHoursAfterPlayback = (int)(24 * numberOfDaysAfterPlayback);
}
/**
* @return the number of episodes that *could* be cleaned up, if needed
*/

View File

@ -131,10 +131,6 @@ public final class Converter {
}
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.

View File

@ -68,11 +68,11 @@
<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>
<item>7</item>
<item>12</item>
<item>24</item>
<item>72</item>
<item>120</item>
<item>168</item>
<item>-2</item>
</string-array>

View File

@ -11,7 +11,7 @@ public class APCleanupAlgorithmTest {
@Test
public void testCalcMostRecentDateForDeletion() throws Exception {
APCleanupAlgorithm algo = new APCleanupAlgorithm(1.0f);
APCleanupAlgorithm algo = new APCleanupAlgorithm(24);
Date curDateForTest = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse("2018-11-13T14:08:56-0800");
Date resExpected = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse("2018-11-12T14:08:56-0800");
Date resActual = algo.calcMostRecentDateForDeletion(curDateForTest);