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)); segmentAdapter.selectSegmentAt(getNearestStreamSegmentPosition(currentProgress));
} }
if (isQueueVisible) {
updateQueueTime(currentProgress);
}
final boolean showThumbnail = prefs.getBoolean( final boolean showThumbnail = prefs.getBoolean(
context.getString(R.string.show_thumbnail_key), true); context.getString(R.string.show_thumbnail_key), true);
// setMetadata only updates the metadata when any of the metadata keys are null // setMetadata only updates the metadata when any of the metadata keys are null
@ -2964,6 +2968,7 @@ public final class Player implements
buildQueue(); buildQueue();
binding.itemsListHeaderTitle.setVisibility(View.GONE); binding.itemsListHeaderTitle.setVisibility(View.GONE);
binding.itemsListHeaderDuration.setVisibility(View.VISIBLE);
binding.shuffleButton.setVisibility(View.VISIBLE); binding.shuffleButton.setVisibility(View.VISIBLE);
binding.repeatButton.setVisibility(View.VISIBLE); binding.repeatButton.setVisibility(View.VISIBLE);
@ -2973,6 +2978,8 @@ public final class Player implements
AnimationType.SLIDE_AND_ALPHA); AnimationType.SLIDE_AND_ALPHA);
binding.itemsList.scrollToPosition(playQueue.getIndex()); binding.itemsList.scrollToPosition(playQueue.getIndex());
updateQueueTime((int) simpleExoPlayer.getCurrentPosition());
} }
private void buildQueue() { private void buildQueue() {
@ -3195,6 +3202,32 @@ public final class Player implements
buildPlaybackSpeedMenu(); buildPlaybackSpeedMenu();
binding.playbackSpeed.setVisibility(View.VISIBLE); 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 //endregion

View file

@ -559,6 +559,17 @@
android:tint="?attr/colorAccent" android:tint="?attr/colorAccent"
app:srcCompat="@drawable/ic_shuffle" app:srcCompat="@drawable/ic_shuffle"
tools:ignore="ContentDescription,RtlHardcoded" /> 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> </RelativeLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView