Skip to content

Commit

Permalink
feat(local_tracks): delete local track (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingkor Roy Tirtho committed Apr 27, 2023
1 parent fd1846e commit 52835b2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
21 changes: 21 additions & 0 deletions lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ class UserLocalTracks extends HookConsumerWidget {
currentTrack: track,
);
},
actions: [
PopupMenuButton(
icon: const Icon(SpotubeIcons.moreHorizontal),
itemBuilder: (context) {
return [
PopupMenuItem(
value: "delete",
onTap: () async {
await File(track.path).delete();
ref.refresh(localTracksProvider);
},
padding: EdgeInsets.zero,
child: const ListTile(
leading: Icon(SpotubeIcons.trash),
title: Text("Delete"),
),
),
];
},
),
],
);
},
),
Expand Down
4 changes: 4 additions & 0 deletions lib/components/shared/track_table/track_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class TrackTile extends HookConsumerWidget {
final bool isLocal;
final void Function(bool?)? onCheckChange;

final List<Widget>? actions;

TrackTile(
this.playlist, {
required this.track,
Expand All @@ -54,6 +56,7 @@ class TrackTile extends HookConsumerWidget {
this.showCheck = false,
this.isLocal = false,
this.onCheckChange,
this.actions,
Key? key,
}) : super(key: key);

Expand Down Expand Up @@ -396,6 +399,7 @@ class TrackTile extends HookConsumerWidget {
)
],
),
...?actions,
],
),
),
Expand Down
25 changes: 17 additions & 8 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:spotube/components/shared/adaptive/adaptive_list_tile.dart';
import 'package:spotube/components/shared/page_window_title_bar.dart';
import 'package:spotube/collections/spotify_markets.dart';
import 'package:spotube/provider/authentication_provider.dart';
import 'package:spotube/provider/downloader_provider.dart';
import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:url_launcher/url_launcher_string.dart';

Expand All @@ -23,6 +24,8 @@ class SettingsPage extends HookConsumerWidget {
Widget build(BuildContext context, ref) {
final UserPreferences preferences = ref.watch(userPreferencesProvider);
final auth = ref.watch(AuthenticationNotifier.provider);
final isDownloading =
ref.watch(downloaderProvider.select((s) => s.currentlyRunning > 0));
final theme = Theme.of(context);

final pickColorScheme = useCallback(() {
Expand Down Expand Up @@ -297,15 +300,21 @@ class SettingsPage extends HookConsumerWidget {
style: theme.textTheme.headlineSmall
?.copyWith(fontWeight: FontWeight.bold),
),
ListTile(
leading: const Icon(SpotubeIcons.download),
title: const Text("Download Location"),
subtitle: Text(preferences.downloadLocation),
trailing: FilledButton(
onPressed: pickDownloadLocation,
child: const Icon(SpotubeIcons.folder),
Tooltip(
message: isDownloading
? "Please wait for the current download to finish"
: null,
child: ListTile(
leading: const Icon(SpotubeIcons.download),
title: const Text("Download Location"),
subtitle: Text(preferences.downloadLocation),
trailing: FilledButton(
onPressed:
isDownloading ? null : pickDownloadLocation,
child: const Icon(SpotubeIcons.folder),
),
onTap: isDownloading ? null : pickDownloadLocation,
),
onTap: pickDownloadLocation,
),
SwitchListTile(
secondary: const Icon(SpotubeIcons.lyrics),
Expand Down
4 changes: 0 additions & 4 deletions lib/provider/downloader_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Downloader with ChangeNotifier {
notifyListeners();

// Using android Audio Focus to keep the app run in background
// _playback.mobileAudioService?.session?.setActive(true);
grabberQueue.add(() async {
final track = await SpotubeTrack.fetchFromTrack(
baseTrack,
Expand Down Expand Up @@ -139,9 +138,6 @@ class Downloader with ChangeNotifier {
} finally {
currentlyRunning--;
inQueue.removeWhere((t) => t.id == track.id);
// if (currentlyRunning == 0 && !PlaylistProvider.isPlaying) {
// _playback.mobileAudioService?.session?.setActive(false);
// }
notifyListeners();
}
});
Expand Down

0 comments on commit 52835b2

Please sign in to comment.