mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
patch: Addressing some UI/UX quirks (#413)
* beautify lyrics display * use dialog to select playback speed to prevent accidental clicks
This commit is contained in:
parent
eaac728a26
commit
54612c6b74
5 changed files with 71 additions and 10 deletions
|
|
@ -0,0 +1,57 @@
|
|||
package com.cappielloantonio.tempo.ui.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.cappielloantonio.tempo.R;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
public class PlaybackSpeedDialog extends DialogFragment {
|
||||
private static final String TAG = "PlaybackSpeedDialog";
|
||||
|
||||
public interface PlaybackSpeedListener {
|
||||
void onSpeedSelected(float speed);
|
||||
}
|
||||
|
||||
private PlaybackSpeedListener listener;
|
||||
|
||||
private static final float[] SPEED_VALUES = {0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f};
|
||||
private static final String[] SPEED_LABELS = {"0.5x", "0.75x", "1.0x", "1.25x", "1.5x", "1.75x", "2.0x"};
|
||||
|
||||
public void setPlaybackSpeedListener(PlaybackSpeedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
float currentSpeed = Preferences.getPlaybackSpeed();
|
||||
int selectedIndex = getSelectedIndex(currentSpeed);
|
||||
|
||||
return new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setTitle(R.string.playback_speed_dialog_title)
|
||||
.setSingleChoiceItems(SPEED_LABELS, selectedIndex, (dialog, which) -> {
|
||||
float selectedSpeed = SPEED_VALUES[which];
|
||||
Preferences.setPlaybackSpeed(selectedSpeed);
|
||||
if (listener != null) {
|
||||
listener.onSpeedSelected(selectedSpeed);
|
||||
}
|
||||
dialog.dismiss();
|
||||
})
|
||||
.setNegativeButton(R.string.playback_speed_dialog_negative_button, (dialog, id) -> dialog.cancel())
|
||||
.create();
|
||||
}
|
||||
|
||||
private int getSelectedIndex(float currentSpeed) {
|
||||
for (int i = 0; i < SPEED_VALUES.length; i++) {
|
||||
if (Math.abs(SPEED_VALUES[i] - currentSpeed) < 0.01f) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 2; // Default to 1.0x
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ import com.cappielloantonio.tempo.databinding.InnerFragmentPlayerControllerBindi
|
|||
import com.cappielloantonio.tempo.service.EqualizerManager;
|
||||
import com.cappielloantonio.tempo.service.MediaService;
|
||||
import com.cappielloantonio.tempo.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.tempo.ui.dialog.PlaybackSpeedDialog;
|
||||
import com.cappielloantonio.tempo.ui.dialog.RatingDialog;
|
||||
import com.cappielloantonio.tempo.ui.dialog.TrackInfoDialog;
|
||||
import com.cappielloantonio.tempo.ui.fragment.pager.PlayerControllerHorizontalPager;
|
||||
|
|
@ -522,13 +523,12 @@ public class PlayerControllerFragment extends Fragment {
|
|||
|
||||
private void initPlaybackSpeedButton(MediaBrowser mediaBrowser) {
|
||||
playbackSpeedButton.setOnClickListener(view -> {
|
||||
float currentSpeed = Preferences.getPlaybackSpeed();
|
||||
|
||||
currentSpeed += 0.25f;
|
||||
if (currentSpeed > 2.0f) currentSpeed = 0.5f;
|
||||
mediaBrowser.setPlaybackParameters(new PlaybackParameters(currentSpeed));
|
||||
playbackSpeedButton.setText(getString(R.string.player_playback_speed, currentSpeed));
|
||||
Preferences.setPlaybackSpeed(currentSpeed);
|
||||
PlaybackSpeedDialog dialog = new PlaybackSpeedDialog();
|
||||
dialog.setPlaybackSpeedListener(speed -> {
|
||||
mediaBrowser.setPlaybackParameters(new PlaybackParameters(speed));
|
||||
playbackSpeedButton.setText(getString(R.string.player_playback_speed, speed));
|
||||
});
|
||||
dialog.show(requireActivity().getSupportFragmentManager(), null);
|
||||
});
|
||||
|
||||
skipSilenceToggleButton.setOnClickListener(view -> {
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ public class PlayerLyricsFragment extends Fragment {
|
|||
|
||||
if (lines != null) {
|
||||
for (Line line : lines) {
|
||||
lyricsBuilder.append(line.getValue().trim()).append("\n");
|
||||
lyricsBuilder.append(line.getValue().trim()).append("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -316,7 +316,7 @@ public class PlayerLyricsFragment extends Fragment {
|
|||
|
||||
StringBuilder lyricsBuilder = new StringBuilder();
|
||||
for (Line line : lines) {
|
||||
lyricsBuilder.append(line.getValue().trim()).append("\n");
|
||||
lyricsBuilder.append(line.getValue().trim()).append("\n\n");
|
||||
}
|
||||
String lyrics = lyricsBuilder.toString();
|
||||
Spannable spannableString = new SpannableString(lyrics);
|
||||
|
|
@ -328,7 +328,7 @@ public class PlayerLyricsFragment extends Fragment {
|
|||
boolean highlight = i == curIdx;
|
||||
if (highlight) highlightStart = offset;
|
||||
|
||||
int len = lines.get(i).getValue().length() + 1;
|
||||
int len = lines.get(i).getValue().length() + 2;
|
||||
final int lineStart = lines.get(i).getStart();
|
||||
spannableString.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@
|
|||
style="@style/BodyLarge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:lineSpacingExtra="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -217,6 +217,8 @@
|
|||
<string name="menu_unpin_button">Remove from home screen</string>
|
||||
<string name="menu_sort_year">Year</string>
|
||||
<string name="player_playback_speed">%1$.2fx</string>
|
||||
<string name="playback_speed_dialog_title">Playback Speed</string>
|
||||
<string name="playback_speed_dialog_negative_button">Cancel</string>
|
||||
<string name="player_queue_clean_all_button">Clean play queue</string>
|
||||
<string name="player_queue_save_queue_success">Saved play queue</string>
|
||||
<string name="player_queue_save_to_playlist">Save Queue to Playlist</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue