mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-24 20:15:16 +01:00
show OverallDuration in Playlist
earlier only overall amount of videos was shown. Now overall duration is shown there too - as formatted by existing Localization.concatenateStrings() and Localization.getDurationString(). show all videos OverallDuration in local Playlist too refactor to make implementation in LocalPlaylistFragment and PlaylistFragment more obviously similar unfortunately could not refactor upto BaseLocalListFragment revert the changes for online Playlists because they are paginated and may be infinite i.e. correct count may come only from the service->extractor chain which unfortunately does not give overall duration yet next try to improve user-experience with online Playlist just show that duration is longer (">") than the calculated value in case there is more page(s) even more improve user-experience for online Playlist by adding the duration of next items as soon as they are made visible make showing of playlists duration configurable, disabled by default adjusted duration to be handled as long because it comes as long from extractor no idea why I handled it as int earlier Revert "make showing of playlists duration configurable, disabled by default", refactor This reverts commit bc1ba17a20d3dd1763210f81d7ca67c5f1734a3d. Fix rebase Apply review Rename video -> stream Remove unused settings keys
This commit is contained in:
parent
f0beb662aa
commit
bef5907ec3
@ -89,6 +89,9 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
|
|||||||
|
|
||||||
private MenuItem playlistBookmarkButton;
|
private MenuItem playlistBookmarkButton;
|
||||||
|
|
||||||
|
private long streamCount;
|
||||||
|
private long playlistOverallDurationSeconds;
|
||||||
|
|
||||||
public static PlaylistFragment getInstance(final int serviceId, final String url,
|
public static PlaylistFragment getInstance(final int serviceId, final String url,
|
||||||
final String name) {
|
final String name) {
|
||||||
final PlaylistFragment instance = new PlaylistFragment();
|
final PlaylistFragment instance = new PlaylistFragment();
|
||||||
@ -277,6 +280,12 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
|
|||||||
animate(headerBinding.uploaderLayout, false, 200);
|
animate(headerBinding.uploaderLayout, false, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleNextItems(final ListExtractor.InfoItemsPage result) {
|
||||||
|
super.handleNextItems(result);
|
||||||
|
setStreamCountAndOverallDuration(result.getItems(), !result.hasNextPage());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResult(@NonNull final PlaylistInfo result) {
|
public void handleResult(@NonNull final PlaylistInfo result) {
|
||||||
super.handleResult(result);
|
super.handleResult(result);
|
||||||
@ -322,8 +331,8 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
|
|||||||
.into(headerBinding.uploaderAvatarView);
|
.into(headerBinding.uploaderAvatarView);
|
||||||
}
|
}
|
||||||
|
|
||||||
headerBinding.playlistStreamCount.setText(Localization
|
streamCount = result.getStreamCount();
|
||||||
.localizeStreamCount(getContext(), result.getStreamCount()));
|
setStreamCountAndOverallDuration(result.getRelatedItems(), !result.hasNextPage());
|
||||||
|
|
||||||
final Description description = result.getDescription();
|
final Description description = result.getDescription();
|
||||||
if (description != null && description != Description.EMPTY_DESCRIPTION
|
if (description != null && description != Description.EMPTY_DESCRIPTION
|
||||||
@ -486,4 +495,20 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
|
|||||||
playlistBookmarkButton.setIcon(drawable);
|
playlistBookmarkButton.setIcon(drawable);
|
||||||
playlistBookmarkButton.setTitle(titleRes);
|
playlistBookmarkButton.setTitle(titleRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStreamCountAndOverallDuration(final List<StreamInfoItem> 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))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -502,7 +502,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long videoCount = itemListAdapter.getItemsList().size();
|
final long videoCount = itemListAdapter.getItemsList().size();
|
||||||
setVideoCount(videoCount);
|
setStreamCountAndOverallDuration(itemListAdapter.getItemsList());
|
||||||
if (videoCount == 0) {
|
if (videoCount == 0) {
|
||||||
showEmptyState();
|
showEmptyState();
|
||||||
}
|
}
|
||||||
@ -532,7 +532,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
itemsList.getLayoutManager().onRestoreInstanceState(itemsListState);
|
itemsList.getLayoutManager().onRestoreInstanceState(itemsListState);
|
||||||
itemsListState = null;
|
itemsListState = null;
|
||||||
}
|
}
|
||||||
setVideoCount(itemListAdapter.getItemsList().size());
|
setStreamCountAndOverallDuration(itemListAdapter.getItemsList());
|
||||||
|
|
||||||
PlayButtonHelper.initPlaylistControlClickListener(activity, playlistControlBinding, this);
|
PlayButtonHelper.initPlaylistControlClickListener(activity, playlistControlBinding, this);
|
||||||
|
|
||||||
@ -665,7 +665,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
.subscribe(itemsToKeep -> {
|
.subscribe(itemsToKeep -> {
|
||||||
itemListAdapter.clearStreamItemList();
|
itemListAdapter.clearStreamItemList();
|
||||||
itemListAdapter.addItems(itemsToKeep);
|
itemListAdapter.addItems(itemsToKeep);
|
||||||
setVideoCount(itemListAdapter.getItemsList().size());
|
setStreamCountAndOverallDuration(itemListAdapter.getItemsList());
|
||||||
saveChanges();
|
saveChanges();
|
||||||
|
|
||||||
hideLoading();
|
hideLoading();
|
||||||
@ -684,7 +684,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
updateThumbnailUrl();
|
updateThumbnailUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
setVideoCount(itemListAdapter.getItemsList().size());
|
setStreamCountAndOverallDuration(itemListAdapter.getItemsList());
|
||||||
saveChanges();
|
saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,10 +855,20 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
this.name = !TextUtils.isEmpty(title) ? title : "";
|
this.name = !TextUtils.isEmpty(title) ? title : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setVideoCount(final long count) {
|
private void setStreamCountAndOverallDuration(final ArrayList<LocalItem> itemsList) {
|
||||||
if (activity != null && headerBinding != null) {
|
if (activity != null && headerBinding != null) {
|
||||||
headerBinding.playlistStreamCount.setText(Localization
|
final long streamCount = itemsList.size();
|
||||||
.localizeStreamCount(activity, count));
|
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))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,25 @@ public final class Localization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
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 String output;
|
||||||
|
|
||||||
final long days = duration / (24 * 60 * 60L); /* greater than a day */
|
final long days = duration / (24 * 60 * 60L); /* greater than a day */
|
||||||
@ -256,7 +274,8 @@ public final class Localization {
|
|||||||
} else {
|
} else {
|
||||||
output = String.format(Locale.US, "%d:%02d", minutes, seconds);
|
output = String.format(Locale.US, "%d:%02d", minutes, seconds);
|
||||||
}
|
}
|
||||||
return output;
|
final String durationPostfix = isDurationComplete ? "" : "+";
|
||||||
|
return output + durationPostfix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user