From f01af590addd30d05d9b462be571bca21592e7a7 Mon Sep 17 00:00:00 2001 From: devaryakjha Date: Mon, 23 Oct 2023 02:35:21 +0530 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Fix:=20using=20saved=20dow?= =?UTF-8?q?nload=20quality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cubits/download/download_cubit.dart | 6 +++- lib/features/settings/ui/settings_page.dart | 31 ++++++++------------- lib/models/app_config.dart | 6 ++++ lib/models/download_url.dart | 7 +++-- lib/utils/dialogs/app_dialog.dart | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/cubits/download/download_cubit.dart b/lib/cubits/download/download_cubit.dart index 8264dc8..d72b93f 100644 --- a/lib/cubits/download/download_cubit.dart +++ b/lib/cubits/download/download_cubit.dart @@ -111,9 +111,13 @@ class DownloadCubit extends AppCubit { DownloadTask _songToTask(Song song) { final fileName = _fileNameFromSong(song); + final dquality = AppConfig.effectiveDlQuality!; + final dlink = song.downloadUrl?.firstWhere( + (e) => e.quality == dquality.quality, + ); return DownloadTask( taskId: song.itemId, - url: song.itemUrl, + url: dlink?.link ?? song.itemUrl, filename: fileName, updates: Updates.statusAndProgress, ); diff --git a/lib/features/settings/ui/settings_page.dart b/lib/features/settings/ui/settings_page.dart index ea6b227..a767f61 100644 --- a/lib/features/settings/ui/settings_page.dart +++ b/lib/features/settings/ui/settings_page.dart @@ -51,37 +51,30 @@ class SettingsPage extends StatelessWidget { value: Text( appConfig.downloadingQuality?.describeQuality ?? "", ), - onPressed: (ctx) { - AppDialog.showOptionsPicker( + onPressed: (ctx) async { + AppConfig.effectiveDlQuality = + await AppDialog.showOptionsPicker( ctx, - appConfig.downloadingQuality, + appConfig.downloadingQuality ?? DownloadQuality.high, DownloadQuality.values, - (e) => e?.describeQuality ?? "", + (e) => e.describeQuality, title: "Select Download Quality", - ).then((value) { - if (value != null) { - AppConfig.effectiveDlQuality = value; - } - }); + ); }, ), SettingsTile.navigation( title: const Text('Streaming quality'), leading: const Icon(Icons.music_note_outlined), value: Text(appConfig.streamingQuality?.describeQuality ?? ""), - onPressed: (ctx) { - AppDialog.showOptionsPicker( + onPressed: (ctx) async { + AppConfig.effectivestreaQuality = + await AppDialog.showOptionsPicker( ctx, - appConfig.streamingQuality, + appConfig.streamingQuality ?? DownloadQuality.high, DownloadQuality.values, - (e) => e?.describeQuality ?? "", + (e) => e.describeQuality, title: "Select Streaming Quality", - ).then((value) { - if (value != null) { - AppConfig.getBox - .put(0, appConfig.copyWith(streamingQuality: value)); - } - }); + ); }, ), SettingsTile.switchTile( diff --git a/lib/models/app_config.dart b/lib/models/app_config.dart index 40c617a..afdf327 100644 --- a/lib/models/app_config.dart +++ b/lib/models/app_config.dart @@ -87,4 +87,10 @@ class AppConfig extends HiveObject with EquatableMixin { getBox.get(0)?.copyWith(downloadingQuality: quality) ?? AppConfig(downloadingQuality: quality), ); + + static set effectivestreaQuality(DownloadQuality? quality) => getBox.put( + 0, + getBox.get(0)?.copyWith(streamingQuality: quality) ?? + AppConfig(streamingQuality: quality), + ); } diff --git a/lib/models/download_url.dart b/lib/models/download_url.dart index e41e540..c812b56 100644 --- a/lib/models/download_url.dart +++ b/lib/models/download_url.dart @@ -1,6 +1,5 @@ import 'package:equatable/equatable.dart'; import 'package:flex_color_scheme/flex_color_scheme.dart'; -import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -32,7 +31,11 @@ enum DownloadQuality { _ => DownloadQuality.low, }; - String get describeQuality => describeEnum(this).capitalize; + String get describeQuality => switch (this) { + DownloadQuality.high => 'Normal', + DownloadQuality.veryHigh => 'Very High', + _ => name.capitalize, + }; } @JsonSerializable() diff --git a/lib/utils/dialogs/app_dialog.dart b/lib/utils/dialogs/app_dialog.dart index 549bf55..7abf283 100644 --- a/lib/utils/dialogs/app_dialog.dart +++ b/lib/utils/dialogs/app_dialog.dart @@ -110,8 +110,8 @@ class AppDialog { context ??= appContext; Widget builder(context) { final viewInsets = MediaQuery.viewInsetsOf(context); + var selectedValue = initialValue; return StatefulBuilder(builder: (context, setState) { - var selectedValue = initialValue; return SizedBox( height: 300, child: Card(