From 5053d470f61163d54f2d0cb6ccf8eed5dc5a7f2d Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 13 Aug 2019 14:39:46 +0200 Subject: [PATCH] Do not save playback position when watch history is disabled --- .../org/schabi/newpipe/player/BasePlayer.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 62be71995..e256070ca 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -1049,27 +1049,33 @@ public abstract class BasePlayer implements private void savePlaybackState(final StreamInfo info, final long progress) { if (info == null) return; if (DEBUG) Log.d(TAG, "savePlaybackState() called"); - final Disposable stateSaver = recordManager.saveStreamState(info, progress) - .observeOn(AndroidSchedulers.mainThread()) - .doOnError((e) -> { - if (DEBUG) e.printStackTrace(); - }) - .onErrorComplete() - .subscribe(); - databaseUpdateReactor.add(stateSaver); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)) { + final Disposable stateSaver = recordManager.saveStreamState(info, progress) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError((e) -> { + if (DEBUG) e.printStackTrace(); + }) + .onErrorComplete() + .subscribe(); + databaseUpdateReactor.add(stateSaver); + } } private void resetPlaybackState(final PlayQueueItem queueItem) { if (queueItem == null) return; - final Disposable stateSaver = queueItem.getStream() - .flatMapCompletable(info -> recordManager.saveStreamState(info, 0)) - .observeOn(AndroidSchedulers.mainThread()) - .doOnError((e) -> { - if (DEBUG) e.printStackTrace(); - }) - .onErrorComplete() - .subscribe(); - databaseUpdateReactor.add(stateSaver); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)) { + final Disposable stateSaver = queueItem.getStream() + .flatMapCompletable(info -> recordManager.saveStreamState(info, 0)) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError((e) -> { + if (DEBUG) e.printStackTrace(); + }) + .onErrorComplete() + .subscribe(); + databaseUpdateReactor.add(stateSaver); + } } public void resetPlaybackState(final StreamInfo info) {