Skip to content

Commit

Permalink
♻️ Fix: using saved download quality
Browse files Browse the repository at this point in the history
  • Loading branch information
devaryakjha committed Oct 22, 2023
1 parent f9d42a2 commit f01af59
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
6 changes: 5 additions & 1 deletion lib/cubits/download/download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ class DownloadCubit extends AppCubit<DownloadState> {

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,
);
Expand Down
31 changes: 12 additions & 19 deletions lib/features/settings/ui/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions lib/models/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
7 changes: 5 additions & 2 deletions lib/models/download_url.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/dialogs/app_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f01af59

Please sign in to comment.