diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index ab3963d61..998ea0624 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -89,6 +89,9 @@ public class PlaylistFragment extends BaseListInfoFragment list, + final boolean isDurationComplete) { + if (activity != null && headerBinding != null) { + playlistOverallDurationSeconds += list.stream() + .mapToLong(x -> x.getDuration()) + .sum(); + headerBinding.playlistStreamCount.setText( + Localization.concatenateStrings( + Localization.localizeStreamCount(activity, streamCount), + Localization.getDurationString(playlistOverallDurationSeconds, + isDurationComplete)) + ); + } + } + } diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 51da52ae0..c4fe3b896 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -502,7 +502,7 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) { } final long videoCount = itemListAdapter.getItemsList().size(); - setVideoCount(videoCount); + setStreamCountAndOverallDuration(itemListAdapter.getItemsList()); if (videoCount == 0) { showEmptyState(); } @@ -532,7 +532,7 @@ public void handleResult(@NonNull final List result) { itemsList.getLayoutManager().onRestoreInstanceState(itemsListState); itemsListState = null; } - setVideoCount(itemListAdapter.getItemsList().size()); + setStreamCountAndOverallDuration(itemListAdapter.getItemsList()); PlayButtonHelper.initPlaylistControlClickListener(activity, playlistControlBinding, this); @@ -665,7 +665,7 @@ private void removeDuplicatesInPlaylist() { .subscribe(itemsToKeep -> { itemListAdapter.clearStreamItemList(); itemListAdapter.addItems(itemsToKeep); - setVideoCount(itemListAdapter.getItemsList().size()); + setStreamCountAndOverallDuration(itemListAdapter.getItemsList()); saveChanges(); hideLoading(); @@ -684,7 +684,7 @@ private void deleteItem(final PlaylistStreamEntry item) { updateThumbnailUrl(); } - setVideoCount(itemListAdapter.getItemsList().size()); + setStreamCountAndOverallDuration(itemListAdapter.getItemsList()); saveChanges(); } @@ -855,10 +855,20 @@ private void setInitialData(final long pid, final String title) { this.name = !TextUtils.isEmpty(title) ? title : ""; } - private void setVideoCount(final long count) { + private void setStreamCountAndOverallDuration(final ArrayList itemsList) { if (activity != null && headerBinding != null) { - headerBinding.playlistStreamCount.setText(Localization - .localizeStreamCount(activity, count)); + final long streamCount = itemsList.size(); + final long playlistOverallDurationSeconds = itemsList.stream() + .filter(PlaylistStreamEntry.class::isInstance) + .map(PlaylistStreamEntry.class::cast) + .map(PlaylistStreamEntry::getStreamEntity) + .mapToLong(StreamEntity::getDuration) + .sum(); + headerBinding.playlistStreamCount.setText( + Localization.concatenateStrings( + Localization.localizeStreamCount(activity, streamCount), + Localization.getDurationString(playlistOverallDurationSeconds)) + ); } } diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index 0485413cc..5d73d21f0 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -238,7 +238,25 @@ public static String likeCount(@NonNull final Context context, final int likeCou } } + /** + * Get a readable text for a duration in the format {@code days:hours:minutes:seconds}. + * Prepended zeros are removed. + * @param duration the duration in seconds + * @return a formatted duration String or {@code 0:00} if the duration is zero. + */ public static String getDurationString(final long duration) { + return getDurationString(duration, true); + } + + /** + * Get a readable text for a duration in the format {@code days:hours:minutes:seconds+}. + * Prepended zeros are removed. If the given duration is incomplete, a plus is appended to the + * duration string. + * @param duration the duration in seconds + * @param isDurationComplete whether the given duration is complete or whether info is missing + * @return a formatted duration String or {@code 0:00} if the duration is zero. + */ + public static String getDurationString(final long duration, final boolean isDurationComplete) { final String output; final long days = duration / (24 * 60 * 60L); /* greater than a day */ @@ -256,7 +274,8 @@ public static String getDurationString(final long duration) { } else { output = String.format(Locale.US, "%d:%02d", minutes, seconds); } - return output; + final String durationPostfix = isDurationComplete ? "" : "+"; + return output + durationPostfix; } /**