Add queue time (#6023)

* Add queue time
This commit is contained in:
Tom 2021-04-08 08:41:41 +00:00 committed by GitHub
parent cf3cc2e984
commit 3fcd580491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -1596,6 +1596,10 @@ public final class Player implements
segmentAdapter.selectSegmentAt(getNearestStreamSegmentPosition(currentProgress));
}
if (isQueueVisible) {
updateQueueTime(currentProgress);
}
final boolean showThumbnail = prefs.getBoolean(
context.getString(R.string.show_thumbnail_key), true);
// setMetadata only updates the metadata when any of the metadata keys are null
@ -2964,6 +2968,7 @@ public final class Player implements
buildQueue();
binding.itemsListHeaderTitle.setVisibility(View.GONE);
binding.itemsListHeaderDuration.setVisibility(View.VISIBLE);
binding.shuffleButton.setVisibility(View.VISIBLE);
binding.repeatButton.setVisibility(View.VISIBLE);
@ -2973,6 +2978,8 @@ public final class Player implements
AnimationType.SLIDE_AND_ALPHA);
binding.itemsList.scrollToPosition(playQueue.getIndex());
updateQueueTime((int) simpleExoPlayer.getCurrentPosition());
}
private void buildQueue() {
@ -3195,6 +3202,32 @@ public final class Player implements
buildPlaybackSpeedMenu();
binding.playbackSpeed.setVisibility(View.VISIBLE);
}
private void updateQueueTime(final int currentTime) {
final int currentStream = playQueue.getIndex();
int before = 0;
int after = 0;
final List<PlayQueueItem> streams = playQueue.getStreams();
final int nStreams = streams.size();
for (int i = 0; i < nStreams; i++) {
if (i < currentStream) {
before += streams.get(i).getDuration();
} else {
after += streams.get(i).getDuration();
}
}
before *= 1000;
after *= 1000;
binding.itemsListHeaderDuration.setText(
String.format("%s/%s",
getTimeString(currentTime + before),
getTimeString(before + after)
));
}
//endregion

View File

@ -559,6 +559,17 @@
android:tint="?attr/colorAccent"
app:srcCompat="@drawable/ic_shuffle"
tools:ignore="ContentDescription,RtlHardcoded" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/itemsListHeaderDuration"
style="@style/TextAppearance.AppCompat.Medium"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/shuffleButton"
android:layout_toLeftOf="@id/itemsListClose"
android:textColor="@android:color/white" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView