mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-07-28 23:08:59 +02:00
Single homes for logic that was copy-pasted across screens: the settings collapsing header, album detail header (online screen's design as the reference), selection pill button + bottom-bar chrome, disc separator chip, error card, cover URL upgrade, byte/clock formatting, duration extraction, UnifiedLibraryItem (moved out of the queue_tab library so other screens can import it), and the batch convert/ReplayGain engine keyed on it.
40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
/// Parses a dynamic value to a positive integer (> 0), or returns null.
|
|
///
|
|
/// Accepts [num] and parseable [String] values.
|
|
int? readPositiveInt(dynamic value) {
|
|
if (value == null) return null;
|
|
if (value is num) {
|
|
final asInt = value.toInt();
|
|
return asInt > 0 ? asInt : null;
|
|
}
|
|
final parsed = int.tryParse(value.toString());
|
|
if (parsed == null || parsed <= 0) return null;
|
|
return parsed;
|
|
}
|
|
|
|
int extractDurationMs(Map<String, dynamic> data) {
|
|
final durationMsRaw = data['duration_ms'];
|
|
if (durationMsRaw is num && durationMsRaw > 0) {
|
|
return durationMsRaw.toInt();
|
|
}
|
|
if (durationMsRaw is String) {
|
|
final parsed = num.tryParse(durationMsRaw.trim());
|
|
if (parsed != null && parsed > 0) {
|
|
return parsed.toInt();
|
|
}
|
|
}
|
|
|
|
final durationSecRaw = data['duration'];
|
|
if (durationSecRaw is num && durationSecRaw > 0) {
|
|
return (durationSecRaw * 1000).toInt();
|
|
}
|
|
if (durationSecRaw is String) {
|
|
final parsed = num.tryParse(durationSecRaw.trim());
|
|
if (parsed != null && parsed > 0) {
|
|
return (parsed * 1000).toInt();
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|