-
Notifications
You must be signed in to change notification settings - Fork 35
/
settings_screen.dart
357 lines (349 loc) · 14.3 KB
/
settings_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import '/services/music_service.dart';
import '/ui/player/player_controller.dart';
import '/ui/utils/theme_controller.dart';
import 'settings_screen_controller.dart';
class SettingsScreen extends StatelessWidget {
const SettingsScreen({super.key});
@override
Widget build(BuildContext context) {
final settingsController = Get.find<SettingsScreenController>();
return Padding(
padding: const EdgeInsets.only(top: 90.0, left: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Settings",
style: Theme.of(context).textTheme.titleLarge,
),
),
Expanded(
child: ListView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.only(bottom: 90),
children: [
Obx(
() => settingsController.isNewVersionAvailable.value
? Padding(
padding: const EdgeInsets.only(top: 8.0, right: 10),
child: Material(
type: MaterialType.transparency,
child: ListTile(
onTap: () {
launchUrl(
Uri.parse(
'https://github.com/anandnet/Harmony-Music/releases/latest',
),
mode: LaunchMode.externalApplication,
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
tileColor: Theme.of(context).colorScheme.secondary,
contentPadding:
const EdgeInsets.only(left: 8, right: 10),
leading: const CircleAvatar(
child: Icon(Icons.download_rounded)),
title: const Text("New Version available!"),
visualDensity: const VisualDensity(horizontal: -2),
subtitle: Text(
"Click here to go to download page",
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
color: Colors.white70, fontSize: 13),
),
),
),
)
: const SizedBox.shrink(),
),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10),
title: const Text("Theme mode"),
subtitle: Obx(
() => Text(
settingsController.themeModetype.value ==
ThemeType.dynamic
? "dynamic"
: settingsController.themeModetype.value ==
ThemeType.system
? "system default"
: settingsController.themeModetype.value ==
ThemeType.dark
? "dark"
: "light",
style: Theme.of(context).textTheme.bodyMedium),
),
onTap: () => showDialog(
context: context,
builder: (context) => const ThemeSelectorDialog(),
),
),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10),
title: const Text("Set Discover content"),
subtitle: Obx(() => Text(
settingsController.discoverContentType.value == "QP"
? "Quick Picks"
: settingsController.discoverContentType.value == "TMV"
? "Top Music Videos"
: settingsController.discoverContentType.value ==
"TR"
? "Trending"
: "Based on last interaction",
style: Theme.of(context).textTheme.bodyMedium)),
onTap: () => showDialog(
context: context,
builder: (context) => const DiscoverContentSelectorDialog(),
),
),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10),
title: const Text("Cache songs"),
subtitle: Text(
"Caching songs while playing for future/offline playback, it will take additional space on your device",
style: Theme.of(context).textTheme.bodyMedium),
trailing: Obx(
() => Switch(
value: settingsController.cacheSongs.value,
onChanged: settingsController.toggleCachingSongsValue),
)),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10),
title: const Text("Skip Silence"),
subtitle: Text("Silence will be skipped in music playback.",
style: Theme.of(context).textTheme.bodyMedium),
trailing: Obx(
() => Switch(
value: settingsController.skipSilenceEnabled.value,
onChanged: settingsController.toggleSkipSilence),
)),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10),
title: const Text("Streaming Quality"),
subtitle: Text("Quality of music stream",
style: Theme.of(context).textTheme.bodyMedium),
trailing: Obx(
() => DropdownButton(
dropdownColor: Theme.of(context).cardColor,
underline: const SizedBox.shrink(),
value: settingsController.streamingQuality.value,
items: const [
DropdownMenuItem(
value: AudioQuality.Low, child: Text("Low")),
DropdownMenuItem(
value: AudioQuality.High,
child: Text("High"),
),
],
onChanged: settingsController.setStreamingQuality,
),
),
),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10,top: 0),
title: const Text("Equalizer"),
subtitle: Text("Open system euqalizer",
style: Theme.of(context).textTheme.bodyMedium),
onTap: () async {
await Get.find<PlayerController>().openEqualizer();
},
),
GetPlatform.isAndroid
? Obx(
() => ListTile(
contentPadding:
const EdgeInsets.only(left: 5, right: 10),
title: const Text("Ignore battery optimization"),
onTap: settingsController
.isIgnoringBatteryOptimizations.isFalse
? settingsController
.enableIgnoringBatteryOptimizations
: null,
subtitle: Obx(() => RichText(
text: TextSpan(
text:
"Status: ${settingsController.isIgnoringBatteryOptimizations.isTrue ? "Enabled" : "Disblaled"}\n",
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontWeight: FontWeight.bold),
children: <TextSpan>[
TextSpan(
text:
"If you are facing notification issues or playback stopped by system optimization, please enable this option",
style: Theme.of(context)
.textTheme
.bodyMedium),
],
),
)),
),
)
: const SizedBox.shrink(),
ListTile(
contentPadding: const EdgeInsets.only(left: 5, right: 10),
title: const Text("Github"),
subtitle: Text(
"View Github source code \nif you like this project, don't forget to give a ⭐${((Get.find<PlayerController>().playerPanelMinHeight.value) == 0) ? "" : "\n\n${settingsController.currentVersion} by anandnet"}",
style: Theme.of(context).textTheme.bodyMedium,
),
isThreeLine: true,
onTap: () {
launchUrl(
Uri.parse(
'https://github.com/anandnet/Harmony-Music',
),
mode: LaunchMode.externalApplication,
);
},
)
],
)),
Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: Text(
"${settingsController.currentVersion} by anandnet",
style: Theme.of(context).textTheme.bodySmall,
),
),
],
),
);
}
}
class ThemeSelectorDialog extends StatelessWidget {
const ThemeSelectorDialog({super.key});
@override
Widget build(BuildContext context) {
final settingsController = Get.find<SettingsScreenController>();
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Container(
height: 280,
//color: Theme.of(context).cardColor,
padding: const EdgeInsets.only(top: 30, left: 5, right: 30, bottom: 10),
child: Column(children: [
Padding(
padding: const EdgeInsets.only(left: 20.0, bottom: 5),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Theme Mode",
style: Theme.of(context).textTheme.titleLarge,
),
),
),
radioWidget(
label: "Dynamic",
controller: settingsController,
value: ThemeType.dynamic,
),
radioWidget(
label: "System default",
controller: settingsController,
value: ThemeType.system),
radioWidget(
label: "Dark",
controller: settingsController,
value: ThemeType.dark),
radioWidget(
label: "Light",
controller: settingsController,
value: ThemeType.light),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text("Cancel"),
),
onTap: () => Navigator.of(context).pop(),
))
]),
),
);
}
}
class DiscoverContentSelectorDialog extends StatelessWidget {
const DiscoverContentSelectorDialog({super.key});
@override
Widget build(BuildContext context) {
final settingsController = Get.find<SettingsScreenController>();
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Container(
height: 280,
//color: Theme.of(context).cardColor,
padding: const EdgeInsets.only(top: 30, left: 5, right: 30, bottom: 10),
child: Column(children: [
Padding(
padding: const EdgeInsets.only(left: 20.0, bottom: 5),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Set Discover content",
style: Theme.of(context).textTheme.titleLarge,
),
),
),
radioWidget(
label: "Quick Picks",
controller: settingsController,
value: "QP"),
radioWidget(
label: "Top Music Videos",
controller: settingsController,
value: "TMV"),
radioWidget(
label: "Trending", controller: settingsController, value: "TR"),
radioWidget(
label: "Based on last interaction",
controller: settingsController,
value: "BOLI"),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text("Cancel"),
),
onTap: () => Navigator.of(context).pop(),
))
]),
),
);
}
}
Widget radioWidget(
{required String label,
required SettingsScreenController controller,
required value}) {
return Obx(() => ListTile(
visualDensity: const VisualDensity(vertical: -4),
onTap: () {
if (value.runtimeType == ThemeType) {
controller.onThemeChange(value);
} else {
controller.onContentChange(value);
Navigator.of(Get.context!).pop();
}
},
leading: Radio(
value: value,
groupValue: value.runtimeType == ThemeType
? controller.themeModetype.value
: controller.discoverContentType.value,
onChanged: value.runtimeType == ThemeType
? controller.onThemeChange
: controller.onContentChange),
title: Text(label),
));
}