Skip to content

Commit

Permalink
feat: previous button replays option
Browse files Browse the repository at this point in the history
closes #112
  • Loading branch information
MSOB7YY committed Jan 30, 2024
1 parent 8cf0ed6 commit b67fa6f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,8 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
@override
Duration get defaultVolume0ResumeThreshold => Duration(minutes: settings.volume0ResumeThresholdMin.value);

bool get previousButtonReplays => settings.previousButtonReplays.value;

// ------------------------------------------------------------

Future<void> togglePlayPause() async {
Expand Down Expand Up @@ -1214,7 +1216,24 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
Future<void> skipToNext([bool? andPlay]) async => await onSkipToNext(andPlay);

@override
Future<void> skipToPrevious() async => await onSkipToPrevious();
Future<void> skipToPrevious() async {
if (previousButtonReplays) {
final int secondsToReplay;
if (settings.isSeekDurationPercentage.value) {
final sFromP = (currentItemDuration?.inSeconds ?? 0) * (settings.seekDurationInPercentage.value / 100);
secondsToReplay = sFromP.toInt();
} else {
secondsToReplay = settings.seekDurationInSeconds.value;
}

if (secondsToReplay > 0 && currentPositionMS > secondsToReplay * 1000) {
await seek(Duration.zero);
return;
}
}

await onSkipToPrevious();
}

@override
Future<void> skipToQueueItem(int index, [bool? andPlay]) async => await onSkipToQueueItem(index, andPlay);
Expand Down
7 changes: 7 additions & 0 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class SettingsController {
final RxBool ytTopComments = true.obs;
final RxBool artworkGestureScale = false.obs;
final RxBool artworkGestureDoubleTapLRC = true.obs;
final RxBool previousButtonReplays = false.obs;
final RxList<TagField> tagFieldsToEdit = <TagField>[
TagField.trackNumber,
TagField.year,
Expand Down Expand Up @@ -465,6 +466,7 @@ class SettingsController {
ytTopComments.value = json['ytTopComments'] ?? ytTopComments.value;
artworkGestureScale.value = json['artworkGestureScale'] ?? artworkGestureScale.value;
artworkGestureDoubleTapLRC.value = json['artworkGestureDoubleTapLRC'] ?? artworkGestureDoubleTapLRC.value;
previousButtonReplays.value = json['previousButtonReplays'] ?? previousButtonReplays.value;

final listFromStorage = List<String>.from(json['tagFieldsToEdit'] ?? []);
tagFieldsToEdit.value = listFromStorage.isNotEmpty ? List<TagField>.from(listFromStorage.map((e) => TagField.values.getEnum(e))) : tagFieldsToEdit;
Expand Down Expand Up @@ -697,6 +699,7 @@ class SettingsController {
'ytTopComments': ytTopComments.value,
'artworkGestureScale': artworkGestureScale.value,
'artworkGestureDoubleTapLRC': artworkGestureDoubleTapLRC.value,
'previousButtonReplays': previousButtonReplays.value,
'tagFieldsToEdit': tagFieldsToEdit.mapped((element) => element.convertToString),
'wakelockMode': wakelockMode.value.convertToString,
'localVideoMatchingType': localVideoMatchingType.value.convertToString,
Expand Down Expand Up @@ -893,6 +896,7 @@ class SettingsController {
bool? ytTopComments,
bool? artworkGestureScale,
bool? artworkGestureDoubleTapLRC,
bool? previousButtonReplays,
List<TagField>? tagFieldsToEdit,
WakelockMode? wakelockMode,
LocalVideoMatchingType? localVideoMatchingType,
Expand Down Expand Up @@ -1389,6 +1393,9 @@ class SettingsController {
if (artworkGestureDoubleTapLRC != null) {
this.artworkGestureDoubleTapLRC.value = artworkGestureDoubleTapLRC;
}
if (previousButtonReplays != null) {
this.previousButtonReplays.value = previousButtonReplays;
}
if (tagFieldsToEdit != null) {
tagFieldsToEdit.loop((d, index) {
if (!this.tagFieldsToEdit.contains(d)) {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ abstract class LanguageKeys {
String get PREVENT_DUPLICATED_TRACKS_SUBTITLE => _getKey('PREVENT_DUPLICATED_TRACKS_SUBTITLE');
String get PREVENT_DUPLICATED_TRACKS => _getKey('PREVENT_DUPLICATED_TRACKS');
String get PREVIEW => _getKey('PREVIEW');
String get PREVIOUS_BUTTON_REPLAYS => _getKey('PREVIOUS_BUTTON_REPLAYS');
String get PREVIOUS_BUTTON_REPLAYS_SUBTITLE => _getKey('PREVIOUS_BUTTON_REPLAYS_SUBTITLE');
String get PRIORITIZE_EMBEDDED_LYRICS => _getKey('PRIORITIZE_EMBEDDED_LYRICS');
String get PROGRESS => _getKey('PROGRESS');
String get PROMPT_INDEXING_REFRESH => _getKey('PROMPT_INDEXING_REFRESH');
Expand Down
19 changes: 19 additions & 0 deletions lib/ui/widgets/settings/playback_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum _PlaybackSettingsKeys {
onVolume0,
onInterruption,
jumpToFirstTrackAfterFinishing,
previousButtonReplays,
seekDuration,
minimumTrackDurToRestoreLastPosition,
countListenAfter,
Expand Down Expand Up @@ -65,6 +66,7 @@ class PlaybackSettings extends SettingSubpageProvider {
_PlaybackSettingsKeys.onVolume0: [lang.ON_VOLUME_ZERO],
_PlaybackSettingsKeys.onInterruption: [lang.ON_INTERRUPTION],
_PlaybackSettingsKeys.jumpToFirstTrackAfterFinishing: [lang.JUMP_TO_FIRST_TRACK_AFTER_QUEUE_FINISH],
_PlaybackSettingsKeys.previousButtonReplays: [lang.PREVIOUS_BUTTON_REPLAYS, lang.PREVIOUS_BUTTON_REPLAYS_SUBTITLE],
_PlaybackSettingsKeys.seekDuration: [lang.SEEK_DURATION, lang.SEEK_DURATION_INFO],
_PlaybackSettingsKeys.minimumTrackDurToRestoreLastPosition: [lang.MIN_TRACK_DURATION_TO_RESTORE_LAST_POSITION],
_PlaybackSettingsKeys.countListenAfter: [lang.MIN_VALUE_TO_COUNT_TRACK_LISTEN],
Expand Down Expand Up @@ -667,6 +669,23 @@ class PlaybackSettings extends SettingSubpageProvider {
),
),
),
getItemWrapper(
key: _PlaybackSettingsKeys.previousButtonReplays,
child: Obx(
() => CustomSwitchListTile(
bgColor: getBgColor(_PlaybackSettingsKeys.previousButtonReplays),
leading: const StackedIcon(
baseIcon: Broken.previous,
secondaryIcon: Broken.rotate_left,
secondaryIconSize: 12.0,
),
title: lang.PREVIOUS_BUTTON_REPLAYS,
subtitle: lang.PREVIOUS_BUTTON_REPLAYS_SUBTITLE,
onChanged: (value) => settings.save(previousButtonReplays: !value),
value: settings.previousButtonReplays.value,
),
),
),
getItemWrapper(
key: _PlaybackSettingsKeys.seekDuration,
child: Obx(
Expand Down

0 comments on commit b67fa6f

Please sign in to comment.