Skip to content

Commit

Permalink
add setting for hiding feature chips
Browse files Browse the repository at this point in the history
- also lays groundwork for planned further customization (including/excluding specific features, reordering)
  • Loading branch information
Chaphasilor committed Oct 9, 2024
1 parent 8740a43 commit aac06b3
Show file tree
Hide file tree
Showing 6 changed files with 475 additions and 83 deletions.
187 changes: 107 additions & 80 deletions lib/components/PlayerScreen/feature_chips.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class FeatureState {
final FinampSettings settings;
final MetadataProvider? metadata;

FinampFeatureChipsConfiguration get configuration =>
settings.featureChipsConfiguration;

bool get isDownloaded => metadata?.isDownloaded ?? false;
bool get isTranscoding =>
!isDownloaded && (currentTrack?.item.extras?["shouldTranscode"] ?? false);
Expand Down Expand Up @@ -63,112 +66,136 @@ class FeatureState {
),
);
}

for (var feature in configuration.features) {

// TODO this will likely be extremely outdated if offline, hide?
if (currentTrack?.baseItem?.userData?.playCount != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!
.playCountValue(currentTrack!.baseItem!.userData?.playCount ?? 0),
),
);
}

if (currentTrack?.baseItem?.people?.isNotEmpty ?? false) {
currentTrack?.baseItem?.people?.forEach((person) {
features.add(
FeatureProperties(
text: "${person.role}: ${person.name}",
),
);
});
}

if (currentTrack?.item.extras?["downloadedSongPath"] != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!.playbackModeLocal,
),
);
} else {
if (isTranscoding) {
// TODO this will likely be extremely outdated if offline, hide?
if (feature == FinampFeatureChipType.playCount &&
currentTrack?.baseItem?.userData?.playCount != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!.playbackModeTranscoding,
),
);
} else {
features.add(
//TODO differentiate between direct streaming and direct playing
// const FeatureProperties(
// text: "Direct Streaming",
// ),
FeatureProperties(
text: AppLocalizations.of(context)!.playbackModeDirectPlaying,
type: feature,
text: AppLocalizations.of(context)!.playCountValue(
currentTrack!.baseItem!.userData?.playCount ?? 0),
),
);
}
}

if (metadata?.mediaSourceInfo != null) {
if (bitrate != null) {
features.add(
FeatureProperties(
text:
"${container.toUpperCase()} @ ${AppLocalizations.of(context)!.kiloBitsPerSecondLabel(bitrate! ~/ 1000)}",
),
);
if (feature == FinampFeatureChipType.additionalPeople &&
(currentTrack?.baseItem?.people?.isNotEmpty ?? false)) {
currentTrack?.baseItem?.people?.forEach((person) {
features.add(
FeatureProperties(
type: feature,
text: "${person.role}: ${person.name}",
),
);
});
}

if (bitDepth != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!.numberAsBit(bitDepth!),
),
);
if (feature == FinampFeatureChipType.playbackMode) {
if (currentTrack?.item.extras?["downloadedSongPath"] != null) {
features.add(
FeatureProperties(
type: feature,
text: AppLocalizations.of(context)!.playbackModeLocal,
),
);
} else {
if (isTranscoding) {
features.add(
FeatureProperties(
type: feature,
text: AppLocalizations.of(context)!.playbackModeTranscoding,
),
);
} else {
features.add(
//TODO differentiate between direct streaming and direct playing
// const FeatureProperties(
// text: "Direct Streaming",
// ),
FeatureProperties(
type: feature,
text: AppLocalizations.of(context)!.playbackModeDirectPlaying,
),
);
}
}
}

if (sampleRate != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!
.numberAsKiloHertz(sampleRate! / 1000.0),
),
);
if (metadata?.mediaSourceInfo != null) {
if (feature == FinampFeatureChipType.codec ||
feature == FinampFeatureChipType.bitRate) {
// only add this feature the first time
if (!features.any((f) => f.type == FinampFeatureChipType.codec)) {
features.add(
FeatureProperties(
type: feature,
text:
"${configuration.features.contains(FinampFeatureChipType.codec) ? container.toUpperCase() : ""}${configuration.features.contains(FinampFeatureChipType.codec) && configuration.features.contains(FinampFeatureChipType.bitRate) ? " @ " : ""}${configuration.features.contains(FinampFeatureChipType.bitRate) && bitrate != null ? AppLocalizations.of(context)!.kiloBitsPerSecondLabel(bitrate! ~/ 1000) : ""}",
),
);
}
}

if (feature == FinampFeatureChipType.bitDepth && bitDepth != null) {
features.add(
FeatureProperties(
type: feature,
text: AppLocalizations.of(context)!.numberAsBit(bitDepth!),
),
);
}

if (feature == FinampFeatureChipType.sampleRate && sampleRate != null) {
features.add(
FeatureProperties(
type: feature,
text: AppLocalizations.of(context)!
.numberAsKiloHertz(sampleRate! / 1000.0),
),
);
}

if (feature == FinampFeatureChipType.size && size != null) {
features.add(
FeatureProperties(
type: feature,
text: FileSize.getSize(size),
),
);
}
}

if (size != null) {
features.add(
FeatureProperties(
text: FileSize.getSize(size),
),
);
if (feature == FinampFeatureChipType.normalizationGain &&
FinampSettingsHelper.finampSettings.volumeNormalizationActive) {
double? effectiveGainChange =
getEffectiveGainChange(currentTrack!.item, currentTrack!.baseItem);
if (effectiveGainChange != null) {
features.add(
FeatureProperties(
type: feature,
text: AppLocalizations.of(context)!.numberAsDecibel(
double.parse(effectiveGainChange.toStringAsFixed(1))),
),
);
}
}
}

if (FinampSettingsHelper.finampSettings.volumeNormalizationActive) {
double? effectiveGainChange =
getEffectiveGainChange(currentTrack!.item, currentTrack!.baseItem);
if (effectiveGainChange != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!.numberAsDecibel(
double.parse(effectiveGainChange.toStringAsFixed(1))),
),
);
}
}

return features;
}
}

class FeatureProperties {
const FeatureProperties({
required this.text,
this.type,
});

final String text;
final FinampFeatureChipType? type;
}

class FeatureChips extends ConsumerWidget {
Expand Down
40 changes: 40 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1728,5 +1728,45 @@
"nowPlayingBarTooltip": "Open Player Screen",
"@nowPlayingBarTooltip": {
"description": "Tooltip for the now playing bar at the bottom of the screen"
},
"additionalPeople": "People",
"@additionalPeople": {
"description": "Label for the feature chips showing additional people in the credits of a track or album"
},
"playbackMode": "Playback Mode",
"@playbackMode": {
"description": "Label for the feature chips showing the playback mode of a track. See [playbackModeLocal], [playbackModeDirectPlaying], and [playbackModeTranscoding]"
},
"codec": "Codec",
"@codec": {
"description": "Label for the feature chips showing the codec of a track"
},
"bitRate": "Bit Rate",
"@bitRate": {
"description": "Label for the feature chips showing the bit rate of a track"
},
"bitDepth": "Bit Depth",
"@bitDepth": {
"description": "Label for the feature chips showing the bit depth of a track"
},
"size": "Size",
"@size": {
"description": "Label for the feature chips showing the size (original file size or transcoded size, if available) of a track"
},
"normalizationGain": "Gain",
"@normalizationGain": {
"description": "Label for the feature chips showing the normalization gain / LUFS offset of a track"
},
"sampleRate": "Sample Rate",
"@sampleRate": {
"description": "Label for the feature chips showing the sample rate of a track"
},
"showFeatureChipsToggleTitle": "Show Advanced Track Info",
"@showFeatureChipsToggleTitle": {
"description": "Title for the setting that controls if the feature chips showing advanced track info are shown on the player screen"
},
"showFeatureChipsToggleSubtitle": "Show advanced track info like codec, bit rate, and more on the player screen.",
"@showFeatureChipsToggleSubtitle": {
"description": "Subtitle for the setting that controls if the feature chips showing advanced track info are shown on the player screen"
}
}
Loading

0 comments on commit aac06b3

Please sign in to comment.