Skip to content

Commit

Permalink
#2652 (part of): Expose keep in-progress at front as a preference
Browse files Browse the repository at this point in the history
(in Playback > Queue section)
  • Loading branch information
orionlee committed May 19, 2018
1 parent 5dd2318 commit afa89a6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,8 @@
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;

import com.bytehamster.lib.preferencesearch.SearchPreference;
import de.danoeh.antennapod.activity.AboutActivity;
import de.danoeh.antennapod.activity.ImportExportActivity;
import de.danoeh.antennapod.activity.MediaplayerActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.StatisticsActivity;
import de.danoeh.antennapod.core.export.html.HtmlWriter;
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
import de.danoeh.antennapod.core.service.GpodnetSyncService;
import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog;
import de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog;
import de.danoeh.antennapod.dialog.ProxyDialog;
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;

import org.apache.commons.lang3.ArrayUtils;

import java.io.File;
Expand All @@ -66,14 +51,29 @@

import de.danoeh.antennapod.CrashReportWriter;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.AboutActivity;
import de.danoeh.antennapod.activity.DirectoryChooserActivity;
import de.danoeh.antennapod.activity.ImportExportActivity;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.MediaplayerActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.StatisticsActivity;
import de.danoeh.antennapod.asynctask.ExportWorker;
import de.danoeh.antennapod.core.export.ExportWriter;
import de.danoeh.antennapod.core.export.html.HtmlWriter;
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.flattr.FlattrUtils;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog;
import de.danoeh.antennapod.dialog.ChooseDataFolderDialog;
import de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog;
import de.danoeh.antennapod.dialog.ProxyDialog;
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -172,6 +172,7 @@ public void onCreate(int screen) {
break;
case R.xml.preferences_playback:
setupPlaybackScreen();
checkKeepInProgressAtFrontItemVisibility(UserPreferences.enqueueAtFront());
PreferenceControllerFlavorHelper.setupFlavoredUI(ui);
buildSmartMarkAsPlayedPreference();
break;
Expand Down Expand Up @@ -420,6 +421,16 @@ private void setupPlaybackScreen() {
behaviour.setEntries(R.array.video_background_behavior_options_without_pip);
behaviour.setEntryValues(R.array.video_background_behavior_values_without_pip);
}

ui.findPreference(UserPreferences.PREF_QUEUE_ADD_TO_FRONT).setOnPreferenceChangeListener(
(preference, newValue) -> {
if (newValue instanceof Boolean) {
boolean enableKeepInProgressAtFront = ((Boolean) newValue);
checkKeepInProgressAtFrontItemVisibility(enableKeepInProgressAtFront);
}
return true;
});

}

private void setupAutoDownloadScreen() {
Expand Down Expand Up @@ -888,6 +899,10 @@ private void checkAutodownloadItemVisibility(boolean autoDownload) {
setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter());
}

private void checkKeepInProgressAtFrontItemVisibility(boolean enabled) {
ui.findPreference(UserPreferences.PREF_QUEUE_KEEP_IN_PROGESS_AT_FRONT).setEnabled(enabled);
}

private void checkSonicItemVisibility() {
if (Build.VERSION.SDK_INT >= 16) {
ui.findPreference(UserPreferences.PREF_SONIC).setEnabled(true);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences_playback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
android:key="prefQueueAddToFront"
android:summary="@string/pref_queueAddToFront_sum"
android:title="@string/pref_queueAddToFront_title"/>
<SwitchPreference
android:defaultValue="false"
android:enabled="false"
android:key="prefQueueKeepInProgressAtFront"
android:summary="@string/pref_queueKeepInProgressAtFront_sum"
android:title="@string/pref_queueKeepInProgressAtFront_title"/>
<SwitchPreference
android:defaultValue="true"
android:enabled="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public class UserPreferences {
private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";

// Queue
private static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
public static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
public static final String PREF_QUEUE_KEEP_IN_PROGESS_AT_FRONT = "prefQueueKeepInProgressAtFront";


// Playback
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";
Expand Down Expand Up @@ -272,6 +274,16 @@ public static boolean enqueueAtFront() {
return prefs.getBoolean(PREF_QUEUE_ADD_TO_FRONT, false);
}

/**
*
* @return {@code true} if in enqueuing items/podcast episodes, when the existing front item is
* in-progress, i.e., the user has played part of it, such item remains at the front of the
* queue; {@code false} otherwise.
*/
public static boolean keepInProgressAtFront() {
return prefs.getBoolean(PREF_QUEUE_KEEP_IN_PROGESS_AT_FRONT, false);
}

public static boolean isPauseOnHeadsetDisconnect() {
return prefs.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public static Future<?> addQueueItem(final Context context, final boolean perfor
new ItemEnqueuePositionCalculator(
new ItemEnqueuePositionCalculator.Options()
.setEnqueueAtFront(UserPreferences.enqueueAtFront())
.setKeepInProgressAtFront(true) // TODO: to expose with preference
.setKeepInProgressAtFront(UserPreferences.keepInProgressAtFront())
);

for (int i = 0; i < itemIds.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@
<string name="pref_expand_notify_unsupport_toast">Android versions before 4.1 do not support expanded notifications.</string>
<string name="pref_queueAddToFront_sum">Add new episodes to the front of the queue.</string>
<string name="pref_queueAddToFront_title">Enqueue at Front</string>
<string name="pref_queueKeepInProgressAtFront_title">Keep In-progress Episode at Front</string>
<string name="pref_queueKeepInProgressAtFront_sum">If the episode at front is in-progress, i.e., you have listened to part of it, keep it at the front of the queue.</string>
<string name="pref_smart_mark_as_played_disabled">Disabled</string>
<string name="pref_image_cache_size_title">Image Cache Size</string>
<string name="pref_image_cache_size_sum">Size of the disk cache for images.</string>
Expand Down

0 comments on commit afa89a6

Please sign in to comment.