Skip to content

Commit

Permalink
feat(downloader): replace /skip all choice for downloaded tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Oct 13, 2022
1 parent cb4bd25 commit 88d7ce5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
41 changes: 38 additions & 3 deletions lib/components/Shared/ReplaceDownloadedFileDialog.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotify/spotify.dart';

class ReplaceDownloadedFileDialog extends StatelessWidget {
final replaceDownloadedFileState = StateProvider<bool?>((ref) => null);

class ReplaceDownloadedFileDialog extends ConsumerWidget {
final Track track;
const ReplaceDownloadedFileDialog({required this.track, Key? key})
: super(key: key);

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, ref) {
final groupValue = ref.watch(replaceDownloadedFileState);

return AlertDialog(
title: Text("Track ${track.name} Already Exists"),
content:
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Do you want to replace the already downloaded track?"),
RadioListTile<bool>(
dense: true,
contentPadding: EdgeInsets.zero,
activeColor: Theme.of(context).primaryColor,
value: true,
groupValue: groupValue,
onChanged: (value) {
if (value != null) {
ref.read(replaceDownloadedFileState.state).state = value;
}
},
title: const Text("Replace all downloaded tracks"),
),
RadioListTile<bool>(
dense: true,
contentPadding: EdgeInsets.zero,
activeColor: Theme.of(context).primaryColor,
value: false,
groupValue: groupValue,
onChanged: (value) {
if (value != null) {
ref.read(replaceDownloadedFileState.state).state = value;
}
},
title: const Text("Skip downloading all downloaded tracks"),
),
],
),
actions: [
TextButton(
child: const Text("No"),
Expand Down
5 changes: 4 additions & 1 deletion lib/provider/Downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:metadata_god/metadata_god.dart';
import 'package:queue/queue.dart';
import 'package:path/path.dart' as path;
import 'package:spotify/spotify.dart' hide Image;
import 'package:spotube/components/Shared/ReplaceDownloadedFileDialog.dart';
import 'package:spotube/models/Logger.dart';
import 'package:spotube/models/SpotubeTrack.dart';
import 'package:spotube/provider/Playback.dart';
Expand Down Expand Up @@ -63,8 +64,10 @@ class Downloader with ChangeNotifier {
final filename = '$cleanTitle.m4a';
final file = File(path.join(downloadPath, filename));
try {
final replaceFileGlobal = ref.read(replaceDownloadedFileState);
logger.v("[addToQueue] Download starting for ${file.path}");
if (file.existsSync() && await onFileExists?.call(track) != true) {
if (file.existsSync() &&
(replaceFileGlobal ?? await onFileExists?.call(track)) != true) {
return;
}
file.createSync(recursive: true);
Expand Down

0 comments on commit 88d7ce5

Please sign in to comment.