Skip to content

Commit

Permalink
Improve settings and external path (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Feb 3, 2024
1 parent 35f3e48 commit 6e02cfd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 42 deletions.
7 changes: 5 additions & 2 deletions lib/src/external_path/external_path_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExternalPathService {
Future<void> Function({Audio? newAudio, Duration? newPosition}) play, [
String? path,
]) {
if (path == null || !isValidFile(path)) {
if (path == null) {
return;
}
try {
Expand All @@ -42,7 +42,10 @@ class ExternalPathService {
fileName: File(path).uri.pathSegments.last,
),
);
} catch (_) {}
} catch (_) {
// TODO: instead of disallowing certain file types
// process via error stream if something went wrong
}
}

Future<void> dispose() async {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@
"podcastIndex": "Podcast Index",
"usePodcastIndex": "Benutze Podcast Index anstatt iTunes",
"select": "Auswählen",
"requiresAppRestart": "Benötigt App-Neustart"
"requiresAppRestart": "Benötigt App-Neustart",
"musicCollectionLocation": "Ort der Musiksammlung"
}
3 changes: 2 additions & 1 deletion lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@
"podcastIndex": "Podcast Index",
"usePodcastIndex": "Use Podcast Index instead of iTunes",
"select": "Select",
"requiresAppRestart": "Requires app restart"
"requiresAppRestart": "Requires app restart",
"musicCollectionLocation": "Music collection location"
}
55 changes: 30 additions & 25 deletions lib/src/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,37 @@ class PlayerService {

bool _firstPlay = true;
Future<void> play({Duration? newPosition, Audio? newAudio}) async {
if (newAudio != null) {
_setAudio(newAudio);
}
if (audio == null) return;

Media? media = audio!.path != null
? Media('file://${audio!.path!}')
: (audio!.url != null)
? Media(audio!.url!)
: null;
if (media == null) return;
_player.open(media).then((_) {
_player.state.tracks;
});
if (newPosition != null && _audio!.audioType != AudioType.radio) {
_player.setVolume(0).then(
(_) => Future.delayed(const Duration(seconds: 3)).then(
(_) => _player
.seek(newPosition)
.then((_) => _player.setVolume(100.0)),
),
);
try {
if (newAudio != null) {
_setAudio(newAudio);
}
if (audio == null) return;

Media? media = audio!.path != null
? Media('file://${audio!.path!}')
: (audio!.url != null)
? Media(audio!.url!)
: null;
if (media == null) return;
_player.open(media).then((_) {
_player.state.tracks;
});
if (newPosition != null && _audio!.audioType != AudioType.radio) {
_player.setVolume(0).then(
(_) => Future.delayed(const Duration(seconds: 3)).then(
(_) => _player
.seek(newPosition)
.then((_) => _player.setVolume(100.0)),
),
);
}
_setMediaControlsMetaData(audio!);
_loadColor();
_firstPlay = false;
} on Exception catch (_) {
// TODO: instead of disallowing certain file types
// process via error stream if something went wrong
}
_setMediaControlsMetaData(audio!);
_loadColor();
_firstPlay = false;
}

Future<void> playOrPause() async {
Expand Down
27 changes: 14 additions & 13 deletions lib/src/settings/settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ class AboutSection extends StatelessWidget {
Widget build(BuildContext context) {
final appName = context.select((SettingsModel m) => m.appName);

final text = '${context.l10n.about} ${appName ?? ''}';
return YaruSection(
headline: Text('${context.l10n.about} ${appName ?? ''}'),
headline: Text(text),
margin: const EdgeInsets.all(kYaruPagePadding),
child: const Column(
children: [_AboutTile(), _LicenseTile()],
child: Column(
children: [_AboutTile(text: text), const _LicenseTile()],
),
);
}
Expand Down Expand Up @@ -137,7 +138,8 @@ class LocalAudioSection extends StatelessWidget {
child: Column(
children: [
YaruTile(
leading: Text(directory),
title: Text(context.l10n.musicCollectionLocation),
subtitle: Text(directory),
trailing: ImportantButton(
onPressed: () async {
final directoryPath = await getDirectoryPath();
Expand Down Expand Up @@ -212,18 +214,16 @@ class _ThemeSectionState extends State<ThemeSection> {
}

class _AboutTile extends StatelessWidget {
const _AboutTile();
const _AboutTile({required this.text});

final String text;

@override
Widget build(BuildContext context) {
final model = context.watch<SettingsModel>();

return YaruTile(
title: Text(
'${context.l10n.version}: ${model.version}',
),
title: Text(text),
trailing: OutlinedButton(
onPressed: () => settingsNavigatorKey.currentState!.pushNamed('/about'),
onPressed: () => settingsNavigatorKey.currentState?.pushNamed('/about'),
child: Text(context.l10n.contributors),
),
);
Expand All @@ -236,6 +236,7 @@ class _AboutDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = context.t;
final appName = context.select((SettingsModel m) => m.appName);
final linkStyle = theme.textTheme.bodyLarge
?.copyWith(color: Colors.lightBlue, overflow: TextOverflow.visible);
const maxLines = 3;
Expand All @@ -249,7 +250,7 @@ class _AboutDialog extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
YaruDialogTitleBar(
title: Text(context.l10n.about),
title: Text('${context.l10n.about} ${appName ?? ''}'),
leading: YaruBackButton(
style: YaruBackButtonStyle.rounded,
onPressed: () => Navigator.of(context).pop(),
Expand Down Expand Up @@ -383,7 +384,7 @@ class _LicenseTile extends StatelessWidget {
),
trailing: OutlinedButton(
onPressed: () =>
settingsNavigatorKey.currentState!.pushNamed('/licenses'),
settingsNavigatorKey.currentState?.pushNamed('/licenses'),
child: Text(context.l10n.dependencies),
),
enabled: true,
Expand Down

0 comments on commit 6e02cfd

Please sign in to comment.