Skip to content

Commit

Permalink
feat: add elapsed in bottom player time if activated in the settings
Browse files Browse the repository at this point in the history
Fixes #753
  • Loading branch information
Feichtmeier committed Nov 16, 2024
1 parent 284fd66 commit 11073a6
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const kAscendingFeeds = 'ascendingfeed:::';
const kPatchNotesDisposed = 'kPatchNotesDisposed';
const kCloseBtnAction = 'closeBtnAction';
const kUseMoreAnimations = 'useMoreAnimations';
const kShowPositionDuration = 'showPositionDuration';

const shops = <String, String>{
'https://us.7digital.com/': '7digital',
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
"theme": "Thema",
"useMoreAnimationsTitle": "Nutze mehr Animationen",
"useMoreAnimationsDescription": "Dies wird die CPU-Nutzung erhöhen, was auf älteren System unerwünscht sein könnte.",
"showPositionDurationTitle": "Zeige Position / Dauer im unteren Player",
"showPositionDurationDescription": "Dies wird andernfalls trotzdem beim Track-Hover oder Vollansicht-Player angezeigt.",
"license": "Lizenz",
"dependencies": "Abhängigkeiten",
"light": "Hell",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
"theme": "Theme",
"useMoreAnimationsTitle": "Use more animations",
"useMoreAnimationsDescription": "This will slightly increase the CPU usage, which might be undesired on older hardware.",
"showPositionDurationTitle": "Show position / duration in bottom player",
"showPositionDurationDescription": "It is otherwise always shown on track hover and in the full screen player.",
"license": "License",
"dependencies": "Dependencies",
"light": "Light",
Expand Down
11 changes: 11 additions & 0 deletions lib/player/view/player_title_and_artist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import '../../local_audio/view/album_page.dart';
import '../../local_audio/view/artist_page.dart';
import '../../podcasts/podcast_model.dart';
import '../../radio/view/station_page.dart';
import '../../settings/settings_model.dart';
import '../player_model.dart';
import 'player_track.dart';
import 'player_view.dart';

class PlayerTitleAndArtist extends StatelessWidget with WatchItMixin {
Expand All @@ -32,6 +34,8 @@ class PlayerTitleAndArtist extends StatelessWidget with WatchItMixin {

final icyTitle =
watchPropertyValue((PlayerModel m) => m.mpvMetaData?.icyTitle);
final showPositionDuration =
watchPropertyValue((SettingsModel m) => m.showPositionDuration);

final appModel = di<AppModel>();
final libraryModel = di<LibraryModel>();
Expand Down Expand Up @@ -113,6 +117,13 @@ class PlayerTitleAndArtist extends StatelessWidget with WatchItMixin {
),
),
),
if (playerPosition == PlayerPosition.bottom &&
audio?.audioType != AudioType.radio &&
showPositionDuration)
const Padding(
padding: EdgeInsets.only(top: 2, bottom: 5),
child: PlayerSimpleTrack(),
),
],
);
}
Expand Down
62 changes: 62 additions & 0 deletions lib/player/view/player_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,65 @@ class PlayerTrack extends StatelessWidget with WatchItMixin {
);
}
}

class PlayerSimpleTrack extends StatelessWidget with WatchItMixin {
const PlayerSimpleTrack({
super.key,
this.active = true,
});

final bool active;

@override
Widget build(BuildContext context) {
final theme = context.theme;
final position = watchPropertyValue((PlayerModel m) => m.position);
final duration = watchPropertyValue((PlayerModel m) => m.duration);
final textStyle =
TextStyle(fontSize: 10, color: !active ? theme.disabledColor : null);

final positionWidth =
(position?.inHours != null && position!.inHours > 0) ? 48.0 : 35.0;
final durationWidth =
(duration?.inHours != null && duration!.inHours > 0) ? 48.0 : 35.0;

const slashWidth = 5.0;

const height = 13.0;

return SizedBox(
width: positionWidth + durationWidth + slashWidth,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
RepaintBoundary(
child: SizedBox(
width: positionWidth,
height: height,
child: Text(
(position ?? Duration.zero).formattedTime,
style: textStyle,
),
),
),
SizedBox(
height: height,
width: slashWidth,
child: Text('/', style: textStyle)),
RepaintBoundary(
child: SizedBox(
width: durationWidth,
height: height,
child: Text(
(duration ?? Duration.zero).formattedTime,
style: textStyle,
textAlign: TextAlign.end,
),
),
),
],
),
);
}
}
4 changes: 4 additions & 0 deletions lib/settings/settings_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class SettingsModel extends SafeChangeNotifier {
void setCloseBtnActionIndex(CloseBtnAction value) =>
_service.setCloseBtnActionIndex(value);

bool get showPositionDuration => _service.showPositionDuration;
Future<void> setShowPositionDuration(bool value) async =>
_service.setShowPositionDuration(value);

void init() => _propertiesChangedSub ??=
_service.propertiesChanged.listen((_) => notifyListeners());

Expand Down
5 changes: 5 additions & 0 deletions lib/settings/settings_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class SettingsService {
Future<void> setDownloadsCustomDir(String directory) async =>
_preferences.setString(kDownloadsCustomDir, directory).then(notify);

bool get showPositionDuration =>
_preferences.getBool(kShowPositionDuration) ?? false;
Future<void> setShowPositionDuration(bool value) async =>
_preferences.setBool(kShowPositionDuration, value).then(notify);

CloseBtnAction get closeBtnActionIndex =>
_preferences.getString(kCloseBtnAction) == null
? CloseBtnAction.alwaysAsk
Expand Down
10 changes: 10 additions & 0 deletions lib/settings/view/theme_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ThemeSection extends StatelessWidget with WatchItMixin {
final model = di<SettingsModel>();
final l10n = context.l10n;
final themeIndex = watchPropertyValue((SettingsModel m) => m.themeIndex);

return YaruSection(
margin: const EdgeInsets.only(
left: kYaruPagePadding,
Expand Down Expand Up @@ -65,6 +66,15 @@ class ThemeSection extends StatelessWidget with WatchItMixin {
watchPropertyValue((SettingsModel m) => m.useMoreAnimations),
),
),
YaruTile(
title: Text(l10n.showPositionDurationTitle),
subtitle: Text(l10n.showPositionDurationDescription),
trailing: CommonSwitch(
onChanged: di<SettingsModel>().setShowPositionDuration,
value: watchPropertyValue(
(SettingsModel m) => m.showPositionDuration),
),
),
],
),
);
Expand Down
34 changes: 34 additions & 0 deletions needs_translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"radioTagDisclaimerTitle",
"radioTagDisclaimerSubTitle",
Expand Down Expand Up @@ -302,6 +304,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"duration",
"radioTagDisclaimerTitle",
Expand Down Expand Up @@ -597,6 +601,8 @@

"es": [
"saveAndAuthorize",
"showPositionDurationTitle",
"showPositionDurationDescription",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
Expand All @@ -614,6 +620,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"alwaysAsk",
"hideToTray",
Expand Down Expand Up @@ -890,6 +898,8 @@
],

"it": [
"showPositionDurationTitle",
"showPositionDurationDescription",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
Expand Down Expand Up @@ -995,6 +1005,8 @@
"theme",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"license",
"dependencies",
"light",
Expand Down Expand Up @@ -1438,6 +1450,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"reorder",
"move",
"pinAlbum",
Expand Down Expand Up @@ -1812,6 +1826,8 @@
"theme",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"license",
"dependencies",
"light",
Expand Down Expand Up @@ -2296,6 +2312,8 @@
"theme",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"license",
"dependencies",
"light",
Expand Down Expand Up @@ -2725,6 +2743,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"language",
"duration",
Expand Down Expand Up @@ -3019,6 +3039,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
Expand Down Expand Up @@ -3059,6 +3081,8 @@
"stations",
"copyToClipBoard",
"insertedIntoQueue",
"showPositionDurationTitle",
"showPositionDurationDescription",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
Expand All @@ -3076,6 +3100,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"radioTagDisclaimerTitle",
"radioTagDisclaimerSubTitle",
Expand Down Expand Up @@ -3364,6 +3390,8 @@
"saveAndAuthorize",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
Expand All @@ -3376,6 +3404,8 @@
"saveAndAuthorize",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
Expand All @@ -3393,6 +3423,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"schedulePlaybackStopTimer",
"alwaysAsk",
Expand Down Expand Up @@ -3678,6 +3710,8 @@
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"schedulePlaybackStopTimer",
"alwaysAsk",
Expand Down

0 comments on commit 11073a6

Please sign in to comment.