diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-16 13:27:30 -0500 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-16 13:27:30 -0500 |
commit | b9c16f3198152a988973475ca06e6f2d5260e63e (patch) | |
tree | ddfc431fbf62a7cd14f0ad01fb8f73acfdeedd62 | |
parent | 6e40aa33ab3a77c122096a4bbd18a3d2fcb91a0d (diff) | |
parent | 308a26b14b3afdb6a0ea6ee14da44983b2813554 (diff) | |
download | AntennaPod-b9c16f3198152a988973475ca06e6f2d5260e63e.zip |
Merge pull request #1534 from mfietz/issue/1488-update-interval-feedback
Give feedback about current update setting
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java | 43 | ||||
-rw-r--r-- | core/src/main/res/values/strings.xml | 3 |
2 files changed, 45 insertions, 1 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 7afa38f36..1cfe37073 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -30,10 +30,15 @@ import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; +import org.apache.commons.lang3.ArrayUtils; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.List; +import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.CrashReportWriter; import de.danoeh.antennapod.R; @@ -411,6 +416,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc public void onResume() { checkItemVisibility(); + setUpdateIntervalText(); setParallelDownloadsText(UserPreferences.getParallelDownloads()); setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); setDataFolderText(); @@ -557,6 +563,32 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } } + private void setUpdateIntervalText() { + Context context = ui.getActivity().getApplicationContext(); + String val; + long interval = UserPreferences.getUpdateInterval(); + if(interval > 0) { + int hours = (int) TimeUnit.MILLISECONDS.toHours(interval); + String hoursStr = context.getResources().getQuantityString(R.plurals.time_hours_quantified, hours, hours); + val = String.format(context.getString(R.string.pref_autoUpdateIntervallOrTime_every), hoursStr); + } else { + int[] timeOfDay = UserPreferences.getUpdateTimeOfDay(); + if(timeOfDay.length == 2) { + Calendar cal = new GregorianCalendar(); + cal.set(Calendar.HOUR_OF_DAY, timeOfDay[0]); + cal.set(Calendar.MINUTE, timeOfDay[1]); + String timeOfDayStr = DateFormat.getTimeFormat(context).format(cal.getTime()); + val = String.format(context.getString(R.string.pref_autoUpdateIntervallOrTime_at), + timeOfDayStr); + } else { + val = context.getString(R.string.pref_smart_mark_as_played_disabled); + } + } + String summary = context.getString(R.string.pref_autoUpdateIntervallOrTime_sum) + "\n" + + String.format(context.getString(R.string.pref_current_value), val); + ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL).setSummary(summary); + } + private void setParallelDownloadsText(int downloads) { final Resources res = ui.getActivity().getResources(); @@ -776,10 +808,17 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc builder.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_Interval)); final String[] values = context.getResources().getStringArray(R.array.update_intervall_values); final String[] entries = getUpdateIntervalEntries(values); - builder.setSingleChoiceItems(entries, -1, (dialog1, which) -> { + long currInterval = UserPreferences.getUpdateInterval(); + int checkedItem = -1; + if(currInterval > 0) { + String currIntervalStr = String.valueOf(TimeUnit.MILLISECONDS.toHours(currInterval)); + checkedItem = ArrayUtils.indexOf(values, currIntervalStr); + } + builder.setSingleChoiceItems(entries, checkedItem, (dialog1, which) -> { int hours = Integer.valueOf(values[which]); UserPreferences.setUpdateInterval(hours); dialog1.dismiss(); + setUpdateIntervalText(); }); builder.setNegativeButton(context.getString(R.string.cancel_label), null); builder.show(); @@ -798,6 +837,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc if (view.getTag() == null) { // onTimeSet() may get called twice! view.setTag("TAGGED"); UserPreferences.setUpdateTimeOfDay(selectedHourOfDay, selectedMinute); + setUpdateIntervalText(); } }, hourOfDay, minute, DateFormat.is24HourFormat(context)); timePickerDialog.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay)); @@ -807,6 +847,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc @Override public void onNeutral(MaterialDialog dialog) { UserPreferences.setUpdateInterval(0); + setUpdateIntervalText(); } }); builder.forceStacking(true); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 69acdcc4a..d34d9da61 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -299,6 +299,8 @@ <string name="pref_autoUpdateIntervallOrTime_Disable">Disable</string> <string name="pref_autoUpdateIntervallOrTime_Interval">Set Interval</string> <string name="pref_autoUpdateIntervallOrTime_TimeOfDay">Set Time of Day</string> + <string name="pref_autoUpdateIntervallOrTime_every">every %1$s</string> + <string name="pref_autoUpdateIntervallOrTime_at">at %1$s</string> <string name="pref_downloadMediaOnWifiOnly_sum">Download media files only over WiFi</string> <string name="pref_followQueue_title">Continuous Playback</string> <string name="pref_downloadMediaOnWifiOnly_title">WiFi media download</string> @@ -374,6 +376,7 @@ <string name="experimental_pref">Experimental</string> <string name="pref_sonic_title">Sonic media player</string> <string name="pref_sonic_message">Use built-in sonic media player as a replacement for Prestissimo</string> + <string name="pref_current_value">Current value: %1$s</string> <!-- Auto-Flattr dialog --> <string name="auto_flattr_enable">Enable automatic flattring</string> |