mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-11-08 23:54:27 +00:00
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.
This commit is contained in:
1 parent
f42fe70d6d
commit
fa2061b82c
2 files changed
+38
-5
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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" />
|
||||
|
||||
|
||||
Reference in new issue
Block a user