Skip to content

Commit d03bbfc

Browse files
committed
fix: use commands for settings, add musicpod locals
1 parent 6861902 commit d03bbfc

62 files changed

Lines changed: 72345 additions & 742 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/app/home.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_it/flutter_it.dart';
33
import 'package:yaru/yaru.dart';
44

5+
import '../common/view/ui_constants.dart';
56
import '../extensions/build_context_x.dart';
67
import '../player/view/player_view.dart';
78
import '../podcasts/download_manager.dart';
89
import '../podcasts/view/podcast_collection_view.dart';
910
import '../podcasts/view/podcast_search_view.dart';
11+
import '../settings/view/settings_dialog.dart';
1012

1113
class Home extends StatelessWidget with WatchItMixin {
1214
const Home({super.key});
@@ -23,14 +25,25 @@ class Home extends StatelessWidget with WatchItMixin {
2325
child: Scaffold(
2426
appBar: YaruWindowTitleBar(
2527
border: BorderSide.none,
26-
2728
titleSpacing: 0,
2829
title: TabBar(
2930
tabs: [
3031
Tab(text: context.l10n.search),
3132
Tab(text: context.l10n.collection),
3233
],
3334
),
35+
actions: [
36+
Padding(
37+
padding: const EdgeInsets.symmetric(horizontal: kSmallPadding),
38+
child: IconButton(
39+
onPressed: () => showDialog(
40+
context: context,
41+
builder: (context) => const SettingsDialog(),
42+
),
43+
icon: const Icon(Icons.settings),
44+
),
45+
),
46+
],
3447
),
3548
body: const TabBarView(
3649
children: [PodcastSearchViewNew(), PodcastCollectionView()],
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import 'package:collection/collection.dart';
2+
import 'package:file_picker/file_picker.dart';
3+
import 'package:file_selector/file_selector.dart';
4+
import 'package:permission_handler/permission_handler.dart';
5+
6+
import 'platforms.dart';
7+
8+
class ExternalPathService {
9+
const ExternalPathService();
10+
11+
Future<String?> getPathOfDirectory() async {
12+
if (Platforms.isMobile && await _androidPermissionsGranted()) {
13+
return FilePicker.platform.getDirectoryPath();
14+
}
15+
16+
if (Platforms.isMacOS || Platforms.isLinux || Platforms.isWindows) {
17+
return getDirectoryPath();
18+
}
19+
return null;
20+
}
21+
22+
Future<String?> getPathOfFile() async {
23+
if (Platforms.isMobile && await _androidPermissionsGranted()) {
24+
return (await FilePicker.platform.pickFiles(
25+
allowMultiple: false,
26+
))?.files.firstOrNull?.path;
27+
}
28+
29+
if (Platforms.isMacOS || Platforms.isLinux || Platforms.isWindows) {
30+
return (await openFile())?.path;
31+
}
32+
return null;
33+
}
34+
35+
Future<List<String>> getPathsOfFiles() async {
36+
if (Platforms.isMobile && await _androidPermissionsGranted()) {
37+
final filePickerResult = await FilePicker.platform.pickFiles(
38+
allowMultiple: true,
39+
);
40+
41+
if (filePickerResult == null) {
42+
return [];
43+
}
44+
45+
return filePickerResult.files
46+
.map((e) => XFile(e.path!))
47+
.map((e) => e.path)
48+
.toList();
49+
} else if (Platforms.isMacOS || Platforms.isLinux || Platforms.isWindows) {
50+
return (await openFiles()).map((e) => e.path).toList();
51+
}
52+
return [];
53+
}
54+
55+
Future<bool> _androidPermissionsGranted() async =>
56+
(await Permission.audio
57+
.onDeniedCallback(() {})
58+
.onGrantedCallback(() {})
59+
.onPermanentlyDeniedCallback(() {})
60+
.onRestrictedCallback(() {})
61+
.onLimitedCallback(() {})
62+
.onProvisionalCallback(() {})
63+
.request())
64+
.isGranted;
65+
}

lib/common/platforms.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import 'dart:io';
22

33
import 'package:flutter/foundation.dart';
4+
import 'package:path/path.dart' as p;
5+
import 'package:path_provider/path_provider.dart';
6+
import 'package:xdg_directories/xdg_directories.dart';
7+
8+
import '../app/app_config.dart';
49

510
class Platforms {
611
static bool get isWeb => kIsWeb;
@@ -13,3 +18,23 @@ class Platforms {
1318
static bool get isDesktop => !kIsWeb && (isLinux || isWindows || isMacOS);
1419
static bool get isMobile => !kIsWeb && (isIOS || isAndroid || isFuchsia);
1520
}
21+
22+
extension PlatformX on Platform {
23+
static Future<String?> getDownloadsDefaultDir() async {
24+
String? path;
25+
if (Platforms.isLinux) {
26+
path = getUserDirectory('DOWNLOAD')?.path;
27+
} else if (Platforms.isMacOS || Platforms.isIOS || Platforms.isWindows) {
28+
path = (await getDownloadsDirectory())?.path;
29+
} else if (Platforms.isAndroid) {
30+
final androidDir = Directory('/storage/emulated/0/Download');
31+
if (androidDir.existsSync()) {
32+
path = androidDir.path;
33+
}
34+
}
35+
if (path != null) {
36+
return p.join(path, AppConfig.appName);
37+
}
38+
return null;
39+
}
40+
}

lib/common/view/confirm.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class _ConfirmationDialogState<T> extends State<ConfirmationDialog<T>> {
113113
Row(
114114
children: space(
115115
expand: true,
116-
widthGap: 16,
116+
widthGap: kBigPadding,
117117
children: _error != null
118118
? [
119119
OutlinedButton(
@@ -122,7 +122,7 @@ class _ConfirmationDialogState<T> extends State<ConfirmationDialog<T>> {
122122
Navigator.of(context).pop();
123123
}
124124
},
125-
child: Text(l10n.confirmOk),
125+
child: Text(l10n.confirm),
126126
),
127127
]
128128
: [
@@ -154,7 +154,7 @@ class _ConfirmationDialogState<T> extends State<ConfirmationDialog<T>> {
154154
}
155155
}
156156
},
157-
child: Text(widget.cancelLabel ?? l10n.confirmCancel),
157+
child: Text(widget.cancelLabel ?? l10n.cancel),
158158
),
159159
...?widget.additionalActions,
160160
ElevatedButton(
@@ -188,7 +188,7 @@ class _ConfirmationDialogState<T> extends State<ConfirmationDialog<T>> {
188188
}
189189
}
190190
: null,
191-
child: Text(widget.confirmLabel ?? l10n.confirmOk),
191+
child: Text(widget.confirmLabel ?? l10n.confirm),
192192
),
193193
],
194194
),

lib/common/view/error_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ErrorPage extends StatelessWidget {
1010
@override
1111
Widget build(BuildContext context) {
1212
return Scaffold(
13-
appBar: AppBar(title: Text(context.l10n.oopsSomethingWentWrong)),
13+
appBar: AppBar(title: Text(context.l10n.genericErrorTitle)),
1414
body: ErrorBody(error: error),
1515
);
1616
}

lib/common/view/ui_constants.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var playerButtonStyle = IconButton.styleFrom(
3434

3535
const kDefaultTileLeadingDimension = 40.0;
3636

37-
const kGridViewPadding = EdgeInsets.symmetric(horizontal: 16);
37+
const kGridViewPadding = EdgeInsets.symmetric(horizontal: kBigPadding);
3838
const kGridViewDelegate = SliverGridDelegateWithMaxCrossAxisExtent(
39-
crossAxisSpacing: 8,
40-
mainAxisSpacing: 8,
39+
crossAxisSpacing: kBigPadding,
40+
mainAxisSpacing: kBigPadding,
4141
maxCrossAxisExtent: 200,
4242
mainAxisExtent: 260,
4343
);

0 commit comments

Comments
 (0)