mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
feat(downloader): replace /skip all choice for downloaded tracks
This commit is contained in:
parent
cb4bd25df1
commit
88d7ce55a5
@ -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"),
|
||||
|
@ -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';
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user