Skip to content

Commit

Permalink
added conditional playback speed feature chip
Browse files Browse the repository at this point in the history
- will be shown whenever the playback speed isn't x1.0
  • Loading branch information
Chaphasilor committed May 3, 2024
1 parent 4c3683c commit da023c5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/components/AlbumScreen/preset_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _PresetChipsState extends State<PresetChips> {
height: widget.chipHeight,
onTap: () {
setState(() {});
_queueService.setPlaybackSpeed(value);
_queueService.playbackSpeed = value;
widget.onPresetSelected?.call();
},
);
Expand Down
10 changes: 5 additions & 5 deletions lib/components/AlbumScreen/speed_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _SpeedMenuState extends State<SpeedMenu> {
void saveSpeedInput(double value) {
final valueDouble = (min(max(value, 0), 5) * 100).roundToDouble() / 100;

_queueService.setPlaybackSpeed(valueDouble);
_queueService.playbackSpeed = valueDouble;
setState(() {});

refreshInputText();
Expand Down Expand Up @@ -202,10 +202,10 @@ class _SpeedMenuState extends State<SpeedMenu> {
.finampSettings.playbackSpeed;

if (currentSpeed > speedSliderMin) {
_queueService.setPlaybackSpeed(max(
_queueService.playbackSpeed = max(
speedSliderMin,
double.parse((currentSpeed - speedButtonStep)
.toStringAsFixed(2))));
.toStringAsFixed(2)));
Vibrate.feedback(FeedbackType.success);
} else {
Vibrate.feedback(FeedbackType.error);
Expand All @@ -231,10 +231,10 @@ class _SpeedMenuState extends State<SpeedMenu> {
.finampSettings.playbackSpeed;

if (currentSpeed < speedSliderMax) {
_queueService.setPlaybackSpeed(min(
_queueService.playbackSpeed = min(
speedSliderMax,
double.parse((currentSpeed + speedButtonStep)
.toStringAsFixed(2))));
.toStringAsFixed(2)));
Vibrate.feedback(FeedbackType.success);
} else {
Vibrate.feedback(FeedbackType.error);
Expand Down
26 changes: 18 additions & 8 deletions lib/components/PlayerScreen/feature_chips.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ class FeatureState {
int? get sampleRate => audioStream?.sampleRate;
int? get bitDepth => audioStream?.bitDepth;

get features {
final features = [];
List<FeatureProperties> get features {
final queueService = GetIt.instance<QueueService>();

final List<FeatureProperties> features = [];

if (queueService.playbackSpeed != 1.0) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!.playbackSpeedFeatureText(queueService.playbackSpeed),
),
);
}

// TODO this will likely be extremely outdated if offline, hide?
if (currentTrack?.baseItem?.userData?.playCount != null) {
Expand Down Expand Up @@ -149,8 +159,8 @@ class FeatureProperties {

class FeatureChips extends ConsumerWidget {
const FeatureChips({
Key? key,
}) : super(key: key);
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -194,11 +204,11 @@ class FeatureChips extends ConsumerWidget {

class Features extends StatelessWidget {
const Features({
Key? key,
super.key,
required this.features,
this.backgroundColor,
this.color,
}) : super(key: key);
});

final FeatureState features;
final Color? backgroundColor;
Expand All @@ -225,11 +235,11 @@ class Features extends StatelessWidget {

class _FeatureContent extends StatelessWidget {
const _FeatureContent({
Key? key,
super.key,
required this.feature,
required this.backgroundColor,
this.color,
}) : super(key: key);
});

final FeatureProperties feature;
final Color? backgroundColor;
Expand Down
9 changes: 9 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,15 @@
}
}
},
"playbackSpeedFeatureText": "x{speed} speed",
"@playbackSpeedFeatureText": {
"description": "Label for the feature chip that is shown if the playback speed is different from x1, {speed} is the current playback speed.",
"placeholders": {
"speed": {
"type": "double"
}
}
},
"playbackSpeedDecreaseLabel": "Decrease playback speed",
"@playbackSpeedDecreaseLabel": {
"description": "Label for the button in the speed menu that decreases the playback speed."
Expand Down
6 changes: 1 addition & 5 deletions lib/services/queue_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,6 @@ class QueueService {
}
}

void setPlaybackSpeed(double speed) {
playbackSpeed = speed;
}

Logger get queueServiceLogger => _queueServiceLogger;

int getActualIndexByLinearIndex(int linearIndex) {
Expand Down Expand Up @@ -1159,4 +1155,4 @@ class NextUpShuffleOrder extends ShuffleOrder {
void clear() {
indices.clear();
}
}
}

0 comments on commit da023c5

Please sign in to comment.