Skip to content

Commit e947e86

Browse files
Trust04zhStypox
authored andcommitted
Make positions in list depend on watch history, remove confusing animations
The following is the list of all commits squashed together: Regain function for option `Positions in lists` use option `Resume playback` to control display of progress info in VideoDetailFragment, remove this (extra) function from option `Positions in lists`. remove extra check for live streams, live streams updates just as non-live streams. fix #8176 by eliminating exit delay Regain function for option `Positions in lists` update code with developer's comments apply static import to methods in util class DependentPreferenceHelper Regain function for option `Positions in lists` use option `Resume playback` to control display of progress info in VideoDetailFragment, remove this (extra) function from option `Positions in lists`. remove extra check for live streams, live streams updates just as non-live streams. fix behavior for displaying progress bar when autoplay off but video resume on not to retrieve unnecessary states when position in lists disabled fix mistake in code simplify conditional logic update doc comment and remove unused method Fix not showing duration if position indicators disabled Positions in lists only depends on watch history
1 parent ca421c2 commit e947e86

8 files changed

Lines changed: 98 additions & 63 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import static org.schabi.newpipe.ktx.ViewUtils.animateRotation;
88
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
99
import static org.schabi.newpipe.player.helper.PlayerHelper.isClearingQueueConfirmationRequired;
10-
import static org.schabi.newpipe.player.playqueue.PlayQueueItem.RECOVERY_UNSET;
10+
import static org.schabi.newpipe.util.DependentPreferenceHelper.getResumePlaybackEnabled;
1111
import static org.schabi.newpipe.util.ExtractorHelper.showMetaInfoInTextView;
1212
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
1313
import static org.schabi.newpipe.util.NavigationHelper.openPlayQueue;
@@ -1456,8 +1456,8 @@ public void showLoading() {
14561456

14571457
animate(binding.detailThumbnailPlayButton, false, 50);
14581458
animate(binding.detailDurationView, false, 100);
1459-
animate(binding.detailPositionView, false, 100);
1460-
animate(binding.positionView, false, 50);
1459+
binding.detailPositionView.setVisibility(View.GONE);
1460+
binding.positionView.setVisibility(View.GONE);
14611461

14621462
binding.detailVideoTitleView.setText(title);
14631463
binding.detailVideoTitleView.setMaxLines(1);
@@ -1574,7 +1574,7 @@ public void handleResult(@NonNull final StreamInfo info) {
15741574
binding.detailToggleSecondaryControlsView.setVisibility(View.VISIBLE);
15751575
binding.detailSecondaryControlPanel.setVisibility(View.GONE);
15761576

1577-
updateProgressInfo(info);
1577+
checkUpdateProgressInfo(info);
15781578
initThumbnailViews(info);
15791579
showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView,
15801580
binding.detailMetaInfoSeparator, disposables);
@@ -1673,67 +1673,43 @@ public void openDownloadDialog() {
16731673
// Stream Results
16741674
//////////////////////////////////////////////////////////////////////////*/
16751675

1676-
private void updateProgressInfo(@NonNull final StreamInfo info) {
1676+
private void checkUpdateProgressInfo(@NonNull final StreamInfo info) {
16771677
if (positionSubscriber != null) {
16781678
positionSubscriber.dispose();
16791679
}
1680-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
1681-
final boolean playbackResumeEnabled = prefs
1682-
.getBoolean(activity.getString(R.string.enable_watch_history_key), true)
1683-
&& prefs.getBoolean(activity.getString(R.string.enable_playback_resume_key), true);
1684-
final boolean showPlaybackPosition = prefs.getBoolean(
1685-
activity.getString(R.string.enable_playback_state_lists_key), true);
1686-
if (!playbackResumeEnabled) {
1687-
if (playQueue == null || playQueue.getStreams().isEmpty()
1688-
|| playQueue.getItem().getRecoveryPosition() == RECOVERY_UNSET
1689-
|| !showPlaybackPosition) {
1690-
binding.positionView.setVisibility(View.INVISIBLE);
1691-
binding.detailPositionView.setVisibility(View.GONE);
1692-
// TODO: Remove this check when separation of concerns is done.
1693-
// (live streams weren't getting updated because they are mixed)
1694-
if (!StreamTypeUtil.isLiveStream(info.getStreamType())) {
1695-
return;
1696-
}
1697-
} else {
1698-
// Show saved position from backStack if user allows it
1699-
showPlaybackProgress(playQueue.getItem().getRecoveryPosition(),
1700-
playQueue.getItem().getDuration() * 1000);
1701-
animate(binding.positionView, true, 500);
1702-
animate(binding.detailPositionView, true, 500);
1703-
}
1680+
if (!getResumePlaybackEnabled(activity)) {
1681+
binding.positionView.setVisibility(View.GONE);
1682+
binding.detailPositionView.setVisibility(View.GONE);
17041683
return;
17051684
}
17061685
final HistoryRecordManager recordManager = new HistoryRecordManager(requireContext());
1707-
1708-
// TODO: Separate concerns when updating database data.
1709-
// (move the updating part to when the loading happens)
17101686
positionSubscriber = recordManager.loadStreamState(info)
17111687
.subscribeOn(Schedulers.io())
17121688
.onErrorComplete()
17131689
.observeOn(AndroidSchedulers.mainThread())
17141690
.subscribe(state -> {
1715-
showPlaybackProgress(state.getProgressMillis(), info.getDuration() * 1000);
1716-
animate(binding.positionView, true, 500);
1717-
animate(binding.detailPositionView, true, 500);
1691+
updatePlaybackProgress(
1692+
state.getProgressMillis(), info.getDuration() * 1000);
17181693
}, e -> {
1719-
if (DEBUG) {
1720-
e.printStackTrace();
1721-
}
1694+
// impossible since the onErrorComplete()
17221695
}, () -> {
17231696
binding.positionView.setVisibility(View.GONE);
17241697
binding.detailPositionView.setVisibility(View.GONE);
17251698
});
17261699
}
17271700

1728-
private void showPlaybackProgress(final long progress, final long duration) {
1701+
private void updatePlaybackProgress(final long progress, final long duration) {
1702+
if (!getResumePlaybackEnabled(activity)) {
1703+
return;
1704+
}
17291705
final int progressSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(progress);
17301706
final int durationSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(duration);
1731-
// If the old and the new progress values have a big difference then use
1732-
// animation. Otherwise don't because it affects CPU
1733-
final boolean shouldAnimate = Math.abs(binding.positionView.getProgress()
1734-
- progressSeconds) > 2;
1707+
// If the old and the new progress values have a big difference then use animation.
1708+
// Otherwise don't because it affects CPU
1709+
final int progressDifference = Math.abs(binding.positionView.getProgress()
1710+
- progressSeconds);
17351711
binding.positionView.setMax(durationSeconds);
1736-
if (shouldAnimate) {
1712+
if (progressDifference > 2) {
17371713
binding.positionView.setProgressAnimated(progressSeconds);
17381714
} else {
17391715
binding.positionView.setProgress(progressSeconds);
@@ -1828,7 +1804,7 @@ public void onProgressUpdate(final int currentProgress,
18281804
}
18291805

18301806
if (player.getPlayQueue().getItem().getUrl().equals(url)) {
1831-
showPlaybackProgress(currentProgress, duration);
1807+
updatePlaybackProgress(currentProgress, duration);
18321808
}
18331809
}
18341810

app/src/main/java/org/schabi/newpipe/info_list/holder/StreamMiniInfoItemHolder.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.schabi.newpipe.info_list.InfoItemBuilder;
1515
import org.schabi.newpipe.ktx.ViewUtils;
1616
import org.schabi.newpipe.local.history.HistoryRecordManager;
17+
import org.schabi.newpipe.util.DependentPreferenceHelper;
1718
import org.schabi.newpipe.util.Localization;
1819
import org.schabi.newpipe.util.PicassoHelper;
1920
import org.schabi.newpipe.util.StreamTypeUtil;
@@ -60,8 +61,12 @@ public void updateFromItem(final InfoItem infoItem,
6061
R.color.duration_background_color));
6162
itemDurationView.setVisibility(View.VISIBLE);
6263

63-
final StreamStateEntity state2 = historyRecordManager.loadStreamState(infoItem)
64-
.blockingGet()[0];
64+
StreamStateEntity state2 = null;
65+
if (DependentPreferenceHelper
66+
.getPositionsInListsEnabled(itemProgressView.getContext())) {
67+
state2 = historyRecordManager.loadStreamState(infoItem)
68+
.blockingGet()[0];
69+
}
6570
if (state2 != null) {
6671
itemProgressView.setVisibility(View.VISIBLE);
6772
itemProgressView.setMax((int) item.getDuration());
@@ -111,9 +116,12 @@ public void updateState(final InfoItem infoItem,
111116
final HistoryRecordManager historyRecordManager) {
112117
final StreamInfoItem item = (StreamInfoItem) infoItem;
113118

114-
final StreamStateEntity state = historyRecordManager
115-
.loadStreamState(infoItem)
116-
.blockingGet()[0];
119+
StreamStateEntity state = null;
120+
if (DependentPreferenceHelper.getPositionsInListsEnabled(itemProgressView.getContext())) {
121+
state = historyRecordManager
122+
.loadStreamState(infoItem)
123+
.blockingGet()[0];
124+
}
117125
if (state != null && item.getDuration() > 0
118126
&& !StreamTypeUtil.isLiveStream(item.getStreamType())) {
119127
itemProgressView.setMax((int) item.getDuration());

app/src/main/java/org/schabi/newpipe/local/holder/LocalPlaylistStreamItemHolder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.schabi.newpipe.ktx.ViewUtils;
1515
import org.schabi.newpipe.local.LocalItemBuilder;
1616
import org.schabi.newpipe.local.history.HistoryRecordManager;
17+
import org.schabi.newpipe.util.DependentPreferenceHelper;
1718
import org.schabi.newpipe.util.Localization;
1819
import org.schabi.newpipe.util.PicassoHelper;
1920
import org.schabi.newpipe.util.ServiceHelper;
@@ -68,7 +69,8 @@ public void updateFromItem(final LocalItem localItem,
6869
R.color.duration_background_color));
6970
itemDurationView.setVisibility(View.VISIBLE);
7071

71-
if (item.getProgressMillis() > 0) {
72+
if (DependentPreferenceHelper.getPositionsInListsEnabled(itemProgressView.getContext())
73+
&& item.getProgressMillis() > 0) {
7274
itemProgressView.setVisibility(View.VISIBLE);
7375
itemProgressView.setMax((int) item.getStreamEntity().getDuration());
7476
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS
@@ -109,7 +111,8 @@ public void updateState(final LocalItem localItem,
109111
}
110112
final PlaylistStreamEntry item = (PlaylistStreamEntry) localItem;
111113

112-
if (item.getProgressMillis() > 0 && item.getStreamEntity().getDuration() > 0) {
114+
if (DependentPreferenceHelper.getPositionsInListsEnabled(itemProgressView.getContext())
115+
&& item.getProgressMillis() > 0 && item.getStreamEntity().getDuration() > 0) {
113116
itemProgressView.setMax((int) item.getStreamEntity().getDuration());
114117
if (itemProgressView.getVisibility() == View.VISIBLE) {
115118
itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS

app/src/main/java/org/schabi/newpipe/local/holder/LocalStatisticStreamItemHolder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.schabi.newpipe.ktx.ViewUtils;
1515
import org.schabi.newpipe.local.LocalItemBuilder;
1616
import org.schabi.newpipe.local.history.HistoryRecordManager;
17+
import org.schabi.newpipe.util.DependentPreferenceHelper;
1718
import org.schabi.newpipe.util.Localization;
1819
import org.schabi.newpipe.util.PicassoHelper;
1920
import org.schabi.newpipe.util.ServiceHelper;
@@ -97,7 +98,8 @@ public void updateFromItem(final LocalItem localItem,
9798
R.color.duration_background_color));
9899
itemDurationView.setVisibility(View.VISIBLE);
99100

100-
if (item.getProgressMillis() > 0) {
101+
if (DependentPreferenceHelper.getPositionsInListsEnabled(itemProgressView.getContext())
102+
&& item.getProgressMillis() > 0) {
101103
itemProgressView.setVisibility(View.VISIBLE);
102104
itemProgressView.setMax((int) item.getStreamEntity().getDuration());
103105
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS
@@ -141,7 +143,8 @@ public void updateState(final LocalItem localItem,
141143
}
142144
final StreamStatisticsEntry item = (StreamStatisticsEntry) localItem;
143145

144-
if (item.getProgressMillis() > 0 && item.getStreamEntity().getDuration() > 0) {
146+
if (DependentPreferenceHelper.getPositionsInListsEnabled(itemProgressView.getContext())
147+
&& item.getProgressMillis() > 0 && item.getStreamEntity().getDuration() > 0) {
145148
itemProgressView.setMax((int) item.getStreamEntity().getDuration());
146149
if (itemProgressView.getVisibility() == View.VISIBLE) {
147150
itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import static com.google.android.exoplayer2.Player.RepeatMode;
3030
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
3131
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
32-
import static org.schabi.newpipe.player.helper.PlayerHelper.isPlaybackResumeEnabled;
3332
import static org.schabi.newpipe.player.helper.PlayerHelper.nextRepeatMode;
3433
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePlaybackParametersFromPrefs;
3534
import static org.schabi.newpipe.player.helper.PlayerHelper.retrieveSeekDurationFromPreferences;
@@ -115,6 +114,7 @@
115114
import org.schabi.newpipe.player.ui.PlayerUiList;
116115
import org.schabi.newpipe.player.ui.PopupPlayerUi;
117116
import org.schabi.newpipe.player.ui.VideoPlayerUi;
117+
import org.schabi.newpipe.util.DependentPreferenceHelper;
118118
import org.schabi.newpipe.util.DeviceUtils;
119119
import org.schabi.newpipe.util.ListHelper;
120120
import org.schabi.newpipe.util.NavigationHelper;
@@ -391,7 +391,7 @@ public void handleIntent(@NonNull final Intent intent) {
391391
simpleExoPlayer.setPlayWhenReady(playWhenReady);
392392

393393
} else if (intent.getBooleanExtra(RESUME_PLAYBACK, false)
394-
&& isPlaybackResumeEnabled(this)
394+
&& DependentPreferenceHelper.getResumePlaybackEnabled(context)
395395
&& !samePlayQueue
396396
&& !newQueue.isEmpty()
397397
&& newQueue.getItem() != null

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,6 @@ private static SinglePlayQueue getAutoQueuedSinglePlayQueue(
425425
// Utils used by player
426426
////////////////////////////////////////////////////////////////////////////
427427

428-
public static boolean isPlaybackResumeEnabled(final Player player) {
429-
return player.getPrefs().getBoolean(
430-
player.getContext().getString(R.string.enable_watch_history_key), true)
431-
&& player.getPrefs().getBoolean(
432-
player.getContext().getString(R.string.enable_playback_resume_key), true);
433-
}
434-
435428
@RepeatMode
436429
public static int nextRepeatMode(@RepeatMode final int repeatMode) {
437430
switch (repeatMode) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.schabi.newpipe.util;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
import androidx.preference.PreferenceManager;
7+
8+
import org.schabi.newpipe.R;
9+
10+
/**
11+
* For preferences with dependencies and multiple use case,
12+
* this class can be used to reduce the lines of code.
13+
*/
14+
public final class DependentPreferenceHelper {
15+
16+
private DependentPreferenceHelper() {
17+
// no instance
18+
}
19+
20+
/**
21+
* Option `Resume playback` depends on `Watch history`, this method can be used to retrieve if
22+
* `Resume playback` and its dependencies are all enabled.
23+
*
24+
* @param context the Android context
25+
* @return returns true if `Resume playback` and `Watch history` are both enabled
26+
*/
27+
public static boolean getResumePlaybackEnabled(final Context context) {
28+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
29+
30+
return prefs.getBoolean(context.getString(
31+
R.string.enable_watch_history_key), true)
32+
&& prefs.getBoolean(context.getString(
33+
R.string.enable_playback_resume_key), true);
34+
}
35+
36+
/**
37+
* Option `Position in lists` depends on `Watch history`, this method can be used to retrieve if
38+
* `Position in lists` and its dependencies are all enabled.
39+
*
40+
* @param context the Android context
41+
* @return returns true if `Positions in lists` and `Watch history` are both enabled
42+
*/
43+
public static boolean getPositionsInListsEnabled(final Context context) {
44+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
45+
46+
return prefs.getBoolean(context.getString(
47+
R.string.enable_watch_history_key), true)
48+
&& prefs.getBoolean(context.getString(
49+
R.string.enable_playback_state_lists_key), true);
50+
}
51+
}

app/src/main/res/xml/history_settings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
<SwitchPreferenceCompat
2525
android:defaultValue="true"
26+
android:dependency="@string/enable_watch_history_key"
2627
android:key="@string/enable_playback_state_lists_key"
2728
android:summary="@string/enable_playback_state_lists_summary"
2829
android:title="@string/enable_playback_state_lists_title"

0 commit comments

Comments
 (0)