|
7 | 7 | import static org.schabi.newpipe.ktx.ViewUtils.animateRotation; |
8 | 8 | import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked; |
9 | 9 | 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; |
11 | 11 | import static org.schabi.newpipe.util.ExtractorHelper.showMetaInfoInTextView; |
12 | 12 | import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams; |
13 | 13 | import static org.schabi.newpipe.util.NavigationHelper.openPlayQueue; |
@@ -1448,8 +1448,8 @@ public void showLoading() { |
1448 | 1448 |
|
1449 | 1449 | animate(binding.detailThumbnailPlayButton, false, 50); |
1450 | 1450 | animate(binding.detailDurationView, false, 100); |
1451 | | - animate(binding.detailPositionView, false, 100); |
1452 | | - animate(binding.positionView, false, 50); |
| 1451 | + binding.detailPositionView.setVisibility(View.GONE); |
| 1452 | + binding.positionView.setVisibility(View.GONE); |
1453 | 1453 |
|
1454 | 1454 | binding.detailVideoTitleView.setText(title); |
1455 | 1455 | binding.detailVideoTitleView.setMaxLines(1); |
@@ -1566,7 +1566,7 @@ public void handleResult(@NonNull final StreamInfo info) { |
1566 | 1566 | binding.detailToggleSecondaryControlsView.setVisibility(View.VISIBLE); |
1567 | 1567 | binding.detailSecondaryControlPanel.setVisibility(View.GONE); |
1568 | 1568 |
|
1569 | | - updateProgressInfo(info); |
| 1569 | + checkUpdateProgressInfo(info); |
1570 | 1570 | initThumbnailViews(info); |
1571 | 1571 | showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView, |
1572 | 1572 | binding.detailMetaInfoSeparator, disposables); |
@@ -1665,67 +1665,43 @@ public void openDownloadDialog() { |
1665 | 1665 | // Stream Results |
1666 | 1666 | //////////////////////////////////////////////////////////////////////////*/ |
1667 | 1667 |
|
1668 | | - private void updateProgressInfo(@NonNull final StreamInfo info) { |
| 1668 | + private void checkUpdateProgressInfo(@NonNull final StreamInfo info) { |
1669 | 1669 | if (positionSubscriber != null) { |
1670 | 1670 | positionSubscriber.dispose(); |
1671 | 1671 | } |
1672 | | - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); |
1673 | | - final boolean playbackResumeEnabled = prefs |
1674 | | - .getBoolean(activity.getString(R.string.enable_watch_history_key), true) |
1675 | | - && prefs.getBoolean(activity.getString(R.string.enable_playback_resume_key), true); |
1676 | | - final boolean showPlaybackPosition = prefs.getBoolean( |
1677 | | - activity.getString(R.string.enable_playback_state_lists_key), true); |
1678 | | - if (!playbackResumeEnabled) { |
1679 | | - if (playQueue == null || playQueue.getStreams().isEmpty() |
1680 | | - || playQueue.getItem().getRecoveryPosition() == RECOVERY_UNSET |
1681 | | - || !showPlaybackPosition) { |
1682 | | - binding.positionView.setVisibility(View.INVISIBLE); |
1683 | | - binding.detailPositionView.setVisibility(View.GONE); |
1684 | | - // TODO: Remove this check when separation of concerns is done. |
1685 | | - // (live streams weren't getting updated because they are mixed) |
1686 | | - if (!StreamTypeUtil.isLiveStream(info.getStreamType())) { |
1687 | | - return; |
1688 | | - } |
1689 | | - } else { |
1690 | | - // Show saved position from backStack if user allows it |
1691 | | - showPlaybackProgress(playQueue.getItem().getRecoveryPosition(), |
1692 | | - playQueue.getItem().getDuration() * 1000); |
1693 | | - animate(binding.positionView, true, 500); |
1694 | | - animate(binding.detailPositionView, true, 500); |
1695 | | - } |
| 1672 | + if (!getResumePlaybackEnabled(activity)) { |
| 1673 | + binding.positionView.setVisibility(View.GONE); |
| 1674 | + binding.detailPositionView.setVisibility(View.GONE); |
1696 | 1675 | return; |
1697 | 1676 | } |
1698 | 1677 | final HistoryRecordManager recordManager = new HistoryRecordManager(requireContext()); |
1699 | | - |
1700 | | - // TODO: Separate concerns when updating database data. |
1701 | | - // (move the updating part to when the loading happens) |
1702 | 1678 | positionSubscriber = recordManager.loadStreamState(info) |
1703 | 1679 | .subscribeOn(Schedulers.io()) |
1704 | 1680 | .onErrorComplete() |
1705 | 1681 | .observeOn(AndroidSchedulers.mainThread()) |
1706 | 1682 | .subscribe(state -> { |
1707 | | - showPlaybackProgress(state.getProgressMillis(), info.getDuration() * 1000); |
1708 | | - animate(binding.positionView, true, 500); |
1709 | | - animate(binding.detailPositionView, true, 500); |
| 1683 | + updatePlaybackProgress( |
| 1684 | + state.getProgressMillis(), info.getDuration() * 1000); |
1710 | 1685 | }, e -> { |
1711 | | - if (DEBUG) { |
1712 | | - e.printStackTrace(); |
1713 | | - } |
| 1686 | + // impossible since the onErrorComplete() |
1714 | 1687 | }, () -> { |
1715 | 1688 | binding.positionView.setVisibility(View.GONE); |
1716 | 1689 | binding.detailPositionView.setVisibility(View.GONE); |
1717 | 1690 | }); |
1718 | 1691 | } |
1719 | 1692 |
|
1720 | | - private void showPlaybackProgress(final long progress, final long duration) { |
| 1693 | + private void updatePlaybackProgress(final long progress, final long duration) { |
| 1694 | + if (!getResumePlaybackEnabled(activity)) { |
| 1695 | + return; |
| 1696 | + } |
1721 | 1697 | final int progressSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(progress); |
1722 | 1698 | final int durationSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(duration); |
1723 | | - // If the old and the new progress values have a big difference then use |
1724 | | - // animation. Otherwise don't because it affects CPU |
1725 | | - final boolean shouldAnimate = Math.abs(binding.positionView.getProgress() |
1726 | | - - progressSeconds) > 2; |
| 1699 | + // If the old and the new progress values have a big difference then use animation. |
| 1700 | + // Otherwise don't because it affects CPU |
| 1701 | + final int progressDifference = Math.abs(binding.positionView.getProgress() |
| 1702 | + - progressSeconds); |
1727 | 1703 | binding.positionView.setMax(durationSeconds); |
1728 | | - if (shouldAnimate) { |
| 1704 | + if (progressDifference > 2) { |
1729 | 1705 | binding.positionView.setProgressAnimated(progressSeconds); |
1730 | 1706 | } else { |
1731 | 1707 | binding.positionView.setProgress(progressSeconds); |
@@ -1820,7 +1796,7 @@ public void onProgressUpdate(final int currentProgress, |
1820 | 1796 | } |
1821 | 1797 |
|
1822 | 1798 | if (player.getPlayQueue().getItem().getUrl().equals(url)) { |
1823 | | - showPlaybackProgress(currentProgress, duration); |
| 1799 | + updatePlaybackProgress(currentProgress, duration); |
1824 | 1800 | } |
1825 | 1801 | } |
1826 | 1802 |
|
|
0 commit comments