From fa2061b82c4facad036e078e5d62655bc3da55e3 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Thu, 5 Nov 2026 12:40:16 +0100 Subject: [PATCH] Fix(Queue): Fix author marquee resetting every second when the artist name is too long Calculate the max width for the queue time to prevent resetting the artist marquee's scrolling position when the artist name is longer than the space available. Without a fixed width the scrolling position is reset every second when updating the text and thus the width of queueTotalDuration. --- .../newpipe/player/PlayQueueActivity.java | 42 ++++++++++++++++--- .../layout/activity_player_queue_control.xml | 1 + 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java index 6b5017b5a..3f6e4f0be 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java @@ -17,6 +17,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.SeekBar; +import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -67,6 +68,13 @@ public final class PlayQueueActivity extends AppCompatActivity private boolean seeking; + /** + * The calculated max width for {@code R.id.queue_total_duration} + * used to set a fixed width for the TextView to prevent {@code R.id.artist_name} + * from resetting to left when updating the duration text. + */ + private int queueDurationWidth; + //////////////////////////////////////////////////////////////////////////// // Views //////////////////////////////////////////////////////////////////////////// @@ -390,13 +398,37 @@ public final class PlayQueueActivity extends AppCompatActivity .sum(); final long queueProgress = before + currentProgress / 1000L; + final String totalDuration = Localization.getDurationString(total); - queueControlBinding.queueTotalDuration.setText( - Localization.getDurationString(queueProgress) + " / " - + Localization.getDurationString(total) + // Calculate the max width for the queue time to prevent resetting the artist marquee's + // scrolling position when the artist name is longer than the space available. + // Without a fixed width the scrolling position is reset every second when updating + // the text and thus the width of queueTotalDuration. + + // Use the widest digit for the progress part while preserving its duration format. + final StringBuilder widestProgressDuration = new StringBuilder(totalDuration.length()); + for (int i = 0; i < totalDuration.length(); i++) { + final char character = totalDuration.charAt(i); + widestProgressDuration.append(Character.isDigit(character) ? '8' : character); + } + + final TextView queueDuration = queueControlBinding.queueTotalDuration; + final float progressWidth = queueDuration.getPaint() + .measureText(widestProgressDuration.toString()); + final float totalWidth = queueDuration.getPaint().measureText(totalDuration); + final float separatorWidth = queueDuration.getPaint().measureText(" / "); + + final int durationWidth = Math.round(progressWidth + separatorWidth + totalWidth); + + if (queueDurationWidth != durationWidth) { + queueDuration.setWidth(durationWidth); + queueDurationWidth = durationWidth; + } + + queueDuration.setText( + Localization.getDurationString(queueProgress) + " / " + totalDuration ); - - queueControlBinding.queueTotalDuration.setVisibility(View.VISIBLE); + queueDuration.setVisibility(View.VISIBLE); } //////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/res/layout/activity_player_queue_control.xml b/app/src/main/res/layout/activity_player_queue_control.xml index 6f97baca3..afdf03cef 100644 --- a/app/src/main/res/layout/activity_player_queue_control.xml +++ b/app/src/main/res/layout/activity_player_queue_control.xml @@ -112,6 +112,7 @@ android:textSize="12sp" android:singleLine="true" android:visibility="gone" + android:gravity="end" tools:text="16:20 / 48:30" tools:visibility="visible" />