feat(downloader): replace /skip all choice for downloaded tracks

This commit is contained in:
Kingkor Roy Tirtho 2022-10-13 19:21:12 +06:00
parent cb4bd25df1
commit 88d7ce55a5
2 changed files with 42 additions and 4 deletions

View File

@ -1,17 +1,52 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotify/spotify.dart'; import 'package:spotify/spotify.dart';
class ReplaceDownloadedFileDialog extends StatelessWidget { final replaceDownloadedFileState = StateProvider<bool?>((ref) => null);
class ReplaceDownloadedFileDialog extends ConsumerWidget {
final Track track; final Track track;
const ReplaceDownloadedFileDialog({required this.track, Key? key}) const ReplaceDownloadedFileDialog({required this.track, Key? key})
: super(key: key); : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, ref) {
final groupValue = ref.watch(replaceDownloadedFileState);
return AlertDialog( return AlertDialog(
title: Text("Track ${track.name} Already Exists"), 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?"), 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: [ actions: [
TextButton( TextButton(
child: const Text("No"), child: const Text("No"),

View File

@ -8,6 +8,7 @@ import 'package:metadata_god/metadata_god.dart';
import 'package:queue/queue.dart'; import 'package:queue/queue.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:spotify/spotify.dart' hide Image; import 'package:spotify/spotify.dart' hide Image;
import 'package:spotube/components/Shared/ReplaceDownloadedFileDialog.dart';
import 'package:spotube/models/Logger.dart'; import 'package:spotube/models/Logger.dart';
import 'package:spotube/models/SpotubeTrack.dart'; import 'package:spotube/models/SpotubeTrack.dart';
import 'package:spotube/provider/Playback.dart'; import 'package:spotube/provider/Playback.dart';
@ -63,8 +64,10 @@ class Downloader with ChangeNotifier {
final filename = '$cleanTitle.m4a'; final filename = '$cleanTitle.m4a';
final file = File(path.join(downloadPath, filename)); final file = File(path.join(downloadPath, filename));
try { try {
final replaceFileGlobal = ref.read(replaceDownloadedFileState);
logger.v("[addToQueue] Download starting for ${file.path}"); 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; return;
} }
file.createSync(recursive: true); file.createSync(recursive: true);