Skip to content

Commit

Permalink
feat: undo player queue track dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jun 6, 2024
1 parent 9e3a937 commit 06be631
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 19 deletions.
10 changes: 8 additions & 2 deletions lib/controller/backup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class BackupController {
}

Future<void> createBackupFile(List<String> backupItemsPaths, {String fileSuffix = ''}) async {
if (isCreatingBackup.value) return snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
if (isCreatingBackup.value) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}

if (!await requestManageStoragePermission()) return;

Expand Down Expand Up @@ -209,7 +212,10 @@ class BackupController {
}

Future<void> restoreBackupOnTap(bool auto) async {
if (isRestoringBackup.value) return snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
if (isRestoringBackup.value) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}

File? backupzip;
if (auto) {
Expand Down
5 changes: 4 additions & 1 deletion lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ class Indexer {
bool allowDeletion = true,
bool showFinishedSnackbar = true,
}) async {
if (isIndexing.value) return snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
if (isIndexing.value) {
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}

isIndexing.value = true;
useMediaStore ??= _defaultUseMediaStore;
Expand Down
12 changes: 9 additions & 3 deletions lib/controller/navigator_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class NamidaNavigator {
}
}

void snackyy({
SnackbarController? snackyy({
IconData? icon,
String title = '',
required String message,
Expand Down Expand Up @@ -533,6 +533,9 @@ void snackyy({
} else {
paddingInsets = const EdgeInsets.symmetric(horizontal: 12.0, vertical: 16.0);
}

bool alreadyTappedButton = false;

final content = Padding(
padding: paddingInsets,
child: SizedBox(
Expand All @@ -552,11 +555,11 @@ void snackyy({
if (title != '')
Text(
title,
style: getTextStyle(FontWeight.w700, 17.0),
style: getTextStyle(FontWeight.w700, 16),
),
Text(
message,
style: title != '' ? getTextStyle(FontWeight.w400, 14.0) : getTextStyle(FontWeight.w600, 15.0),
style: title != '' ? getTextStyle(FontWeight.w400, 13.0) : getTextStyle(FontWeight.w600, 14.0),
maxLines: maxLinesMessage,
overflow: maxLinesMessage == null ? null : TextOverflow.ellipsis,
),
Expand All @@ -567,6 +570,8 @@ void snackyy({
TextButton(
style: const ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap),
onPressed: () {
if (alreadyTappedButton) return;
alreadyTappedButton = true;
button.$2();
snackbarController?.close();
},
Expand Down Expand Up @@ -623,4 +628,5 @@ void snackyy({

snackbarController = SnackbarController(snackbar);
snackbarController.show();
return snackbarController;
}
7 changes: 3 additions & 4 deletions lib/controller/queue_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,13 @@ class QueueController {
String type = '';
final queue = <Object>[];
switch (items.firstOrNull.runtimeType) {
case const (Selectable):
case const (Track):
type = LibraryCategory.localTracks;
(items.cast<Track>()).loop((e) => queue.add(e.path));
break;
case const (TrackWithDate):
type = LibraryCategory.localTracks;
(items.cast<TrackWithDate>()).loop((e) => queue.add(e.track.path));
items.loop((e) => queue.add((e as Selectable).track.path));
break;

case const (YoutubeID):
type = LibraryCategory.youtube;
(items.cast<YoutubeID>()).loop((e) => queue.add(e.toJson()));
Expand Down
10 changes: 8 additions & 2 deletions lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,15 @@ extension OnYoutubeLinkOpenActionUtils on OnYoutubeLinkOpenAction {

Future<void> executePlaylist(String playlistUrl, {YoutubePlaylist? playlist, required BuildContext? context}) async {
final plInfo = playlist ?? await YoutubeController.inst.getPlaylistInfo(playlistUrl);
if (plInfo == null) return snackyy(title: lang.ERROR, message: 'error retrieving playlist info, check your connection?');
if (plInfo == null) {
snackyy(title: lang.ERROR, message: 'error retrieving playlist info, check your connection?');
return;
}
final didFetch = await plInfo.fetchAllPlaylistStreams(context: context?.mounted == true ? context : null);
if (!didFetch) return snackyy(title: lang.ERROR, message: 'error fetching playlist videos');
if (!didFetch) {
snackyy(title: lang.ERROR, message: 'error fetching playlist videos');
return;
}

final streams = plInfo.streams;

Expand Down
20 changes: 19 additions & 1 deletion lib/packages/miniplayer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ class _NamidaMiniPlayerBaseState<E> extends State<NamidaMiniPlayerBase<E>> {
}
}

SnackbarController? _latestSnacky;
void _onRemoveFromQueue(int index) {
_latestSnacky?.close();
final item = Player.inst.currentQueue.value[index];
Player.inst.removeFromQueue(index);
_latestSnacky = snackyy(
icon: Broken.rotate_left,
title: lang.UNDO_CHANGES,
message: lang.UNDO_CHANGES_DELETED_TRACK,
displaySeconds: 2,
top: false,
button: (
lang.UNDO,
() => Player.inst.insertInQueue([item], index),
),
);
}

@override
Widget build(BuildContext context) {
final onSecondary = context.theme.colorScheme.onSecondaryContainer;
Expand Down Expand Up @@ -337,7 +355,7 @@ class _NamidaMiniPlayerBaseState<E> extends State<NamidaMiniPlayerBase<E>> {
return FadeDismissible(
key: Key("Diss_${i}_${childWK.$2}_${queue.length}"), // queue length only for when removing current item and next is the same.
onDismissed: (direction) {
Player.inst.removeFromQueue(i);
_onRemoveFromQueue(i);
MiniPlayerController.inst.invokeDoneReordering();
},
onDismissStart: (_) => MiniPlayerController.inst.invokeStartReordering(),
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/pages/onboarding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ class _FirstRunConfigureScreenState extends State<FirstRunConfigureScreen> {
onTap: () async {
await _requestPermission();
if (BackupController.inst.isRestoringBackup.value) {
return snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}
_navigateToNamida();
},
Expand Down
6 changes: 4 additions & 2 deletions lib/ui/widgets/settings/backup_restore_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class BackupAndRestore extends SettingSubpageProvider {
),
onTap: () async {
if (BackupController.inst.isRestoringBackup.value) {
return snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}

NamidaNavigator.inst.navigateDialog(
Expand Down Expand Up @@ -164,7 +165,8 @@ class BackupAndRestore extends SettingSubpageProvider {
),
onTap: () {
if (BackupController.inst.isCreatingBackup.value) {
return snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
snackyy(title: lang.NOTE, message: lang.ANOTHER_PROCESS_IS_RUNNING);
return;
}

bool isActive(List<String> items) => items.every((element) => settings.backupItemslist.contains(element));
Expand Down
5 changes: 4 additions & 1 deletion lib/ui/widgets/video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,10 @@ class __SpeedsEditorDialogState extends State<_SpeedsEditorDialog> {
),
child: InkWell(
onTap: () {
if (e == 1.0) return snackyy(message: lang.ERROR);
if (e == 1.0) {
snackyy(message: lang.ERROR); // we already ignore tap but uh
return;
}
if (settings.player.speeds.length <= 4) return showMinimumItemsSnack(4);

settings.player.speeds
Expand Down
5 changes: 4 additions & 1 deletion lib/youtube/functions/yt_playlist_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ extension YoutubePlaylistHostedUtils on yt.YoutubePlaylist {
onTap: () async {
final playlist = this;
final didFetch = await playlist.fetchAllPlaylistStreams(context: context);
if (!didFetch) return snackyy(title: lang.ERROR, message: 'error fetching playlist videos');
if (!didFetch) {
snackyy(title: lang.ERROR, message: 'error fetching playlist videos');
return;
}

final ids = <String>[];
final info = <String, String?>{};
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 2.6.1-beta+240606012
version: 2.6.2-beta+240606016

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 06be631

Please sign in to comment.