From d9c1a30847e738e12dd7709ada646f83c91bae75 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Tue, 12 Dec 2023 03:33:23 +0200 Subject: [PATCH] fix: folder changing not being synced in playlist download page (top widget and the one in config dialog) --- .../functions/video_download_options.dart | 43 ++++++++++++------- .../pages/yt_playlist_download_subpage.dart | 31 ++++++++----- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/lib/youtube/functions/video_download_options.dart b/lib/youtube/functions/video_download_options.dart index 28618bd9..e5e765b3 100644 --- a/lib/youtube/functions/video_download_options.dart +++ b/lib/youtube/functions/video_download_options.dart @@ -20,7 +20,7 @@ Future showVideoDownloadOptionsSheet({ required String? videoUploader, required Map tagMaps, required bool supportTagging, - required void Function(String newFolderPath) onDownloadGroupNameChanged, + required void Function(String newGroupName) onDownloadGroupNameChanged, required bool showSpecificFileOptions, }) async { final controllersMap = {for (final t in FFMPEGTagField.values) t: TextEditingController(text: tagMaps[t])}; @@ -218,8 +218,10 @@ Future showVideoDownloadOptionsSheet({ } class YTDownloadOptionFolderListTile extends StatefulWidget { - final void Function(String newFolderPath) onDownloadGroupNameChanged; + final void Function(String newGroupName) onDownloadGroupNameChanged; + final void Function(String newFolderName)? onDownloadFolderAdded; final String initialFolder; + final String playlistName; final String Function(String value)? subtitle; final double trailingPadding; final VisualDensity? visualDensity; @@ -228,7 +230,9 @@ class YTDownloadOptionFolderListTile extends StatefulWidget { const YTDownloadOptionFolderListTile({ super.key, required this.onDownloadGroupNameChanged, + this.onDownloadFolderAdded, this.initialFolder = '', + this.playlistName = '', this.subtitle, this.trailingPadding = 0, this.visualDensity, @@ -236,17 +240,19 @@ class YTDownloadOptionFolderListTile extends StatefulWidget { }); @override - State createState() => _YTDownloadOptionFolderListTileState(); + State createState() => YTDownloadOptionFolderListTileState(); } -class _YTDownloadOptionFolderListTileState extends State { +class YTDownloadOptionFolderListTileState extends State { final groupName = ''.obs; final availableDirectoriesNames = {}; @override void initState() { - availableDirectoriesNames[widget.initialFolder] = 0; // to put at first - availableDirectoriesNames[''] = 0; // to put at first + // -- to put at first + availableDirectoriesNames[widget.playlistName] = 0; + availableDirectoriesNames[widget.initialFolder] = 0; + availableDirectoriesNames[''] = 0; int rootFiles = 0; for (final d in Directory(AppDirs.YOUTUBE_DOWNLOADS).listSync()) { if (d is Directory) { @@ -271,7 +277,15 @@ class _YTDownloadOptionFolderListTileState extends State(); await NamidaNavigator.inst.navigateDialog( @@ -286,8 +300,7 @@ class _YTDownloadOptionFolderListTileState extends State { final _configMap = {}.obs; final _groupName = ''.obs; + final _folderController = GlobalKey(); + bool useCachedVersionsIfAvailable = true; bool autoExtractTitleAndArtist = settings.ytAutoExtractVideoTagsFromInfo.value; bool keepCachedVersionsIfDownloaded = false; @@ -153,9 +155,14 @@ class _YTPlaylistDownloadPageState extends State { YTDownloadOptionFolderListTile( maxTrailingWidth: context.width * 0.2, visualDensity: visualDensity, + playlistName: widget.playlistName, initialFolder: _groupName.value, - onDownloadGroupNameChanged: (newFolderPath) { - _groupName.value = newFolderPath; + onDownloadGroupNameChanged: (newGroupName) { + _groupName.value = newGroupName; + _folderController.currentState?.onGroupNameChanged(newGroupName); + }, + onDownloadFolderAdded: (newFolderName) { + _folderController.currentState?.onFolderAdd(newFolderName); }, ), CustomSwitchListTile( @@ -303,14 +310,18 @@ class _YTPlaylistDownloadPageState extends State { ), ), ), - YTDownloadOptionFolderListTile( - visualDensity: VisualDensity.compact, - trailingPadding: 12.0, - initialFolder: _groupName.value, - subtitle: (value) => "${AppDirs.YOUTUBE_DOWNLOADS}$value", - onDownloadGroupNameChanged: (newFolderPath) { - _groupName.value = newFolderPath; - }, + Obx( + () => YTDownloadOptionFolderListTile( + key: _folderController, + visualDensity: VisualDensity.compact, + trailingPadding: 12.0, + playlistName: widget.playlistName, + initialFolder: _groupName.value, + subtitle: (value) => "${AppDirs.YOUTUBE_DOWNLOADS}$value", + onDownloadGroupNameChanged: (newGroupName) { + _groupName.value = newGroupName; + }, + ), ), Expanded( child: NamidaScrollbar(