diff options
Diffstat (limited to 'lib/data/models')
-rw-r--r-- | lib/data/models/audio_state.dart | 30 | ||||
-rw-r--r-- | lib/data/models/mediaplayer_state.dart | 49 | ||||
-rw-r--r-- | lib/data/models/radio_state.dart | 32 |
3 files changed, 49 insertions, 62 deletions
diff --git a/lib/data/models/audio_state.dart b/lib/data/models/audio_state.dart index cfa550b..60720a8 100644 --- a/lib/data/models/audio_state.dart +++ b/lib/data/models/audio_state.dart @@ -40,36 +40,6 @@ class AudioState { ); } - Map<String, dynamic> toMap() { - return { - 'volume': volume, - 'balance': balance, - 'fade': fade, - 'treble': treble, - 'bass': bass, - }; - } - - factory AudioState.fromMap(Map<String, dynamic> map) { - return AudioState( - volume: map['volume']?.toDouble() ?? 0.0, - balance: map['balance']?.toDouble() ?? 0.0, - fade: map['fade']?.toDouble() ?? 0.0, - treble: map['treble']?.toDouble() ?? 0.0, - bass: map['bass']?.toDouble() ?? 0.0, - ); - } - - String toJson() => json.encode(toMap()); - - factory AudioState.fromJson(String source) => - AudioState.fromMap(json.decode(source)); - - @override - String toString() { - return 'AudioState(volume: $volume, balance: $balance, fade: $fade, treble: $treble, bass: $bass)'; - } - @override bool operator ==(Object other) { if (identical(this, other)) return true; diff --git a/lib/data/models/mediaplayer_state.dart b/lib/data/models/mediaplayer_state.dart new file mode 100644 index 0000000..f880a1e --- /dev/null +++ b/lib/data/models/mediaplayer_state.dart @@ -0,0 +1,49 @@ +import 'package:flutter_ics_homescreen/export.dart'; +import 'package:flutter_ics_homescreen/data/data_providers/playlist_notifier.dart'; + +enum PlayState { stopped, playing, paused } + +@immutable +class MediaPlayerState { + final int playlistPosition; + final PlayState playState; + final PlaylistEntry? song; + + const MediaPlayerState( + {required this.playlistPosition, + required this.playState, + required this.song}); + + const MediaPlayerState.initial() + : playlistPosition = -1, + playState = PlayState.stopped, + song = null; + + MediaPlayerState copyWith( + {int? playlistPosition, + PlayState? playState, + PlaylistEntry? song, + Duration? songPosition, + Duration? songLength}) { + return MediaPlayerState( + playlistPosition: playlistPosition ?? this.playlistPosition, + playState: playState ?? this.playState, + song: song ?? this.song, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is MediaPlayerState && + other.playlistPosition == playlistPosition && + other.playState == playState && + other.song == song; + } + + @override + int get hashCode { + return playlistPosition.hashCode ^ playState.hashCode ^ song.hashCode; + } +} diff --git a/lib/data/models/radio_state.dart b/lib/data/models/radio_state.dart index dd307d9..da972fd 100644 --- a/lib/data/models/radio_state.dart +++ b/lib/data/models/radio_state.dart @@ -43,38 +43,6 @@ class RadioState { ); } - Map<String, dynamic> toMap() { - return { - 'freqMin': freqMin, - 'freqMax': freqMax, - 'freqStep': freqStep, - 'freqCurrent': freqCurrent, - 'playing': playing, - 'scanning': scanning, - }; - } - - factory RadioState.fromMap(Map<String, dynamic> map) { - return RadioState( - freqMin: map['freqMin']?.toInt().toUnsigned() ?? 0, - freqMax: map['freqMax']?.toInt().toUnsigned() ?? 0, - freqStep: map['freqStep']?.toInt().toUnsigned() ?? 0, - freqCurrent: map['freqCurrent']?.toInt().toUnsigned() ?? 0, - playing: map['playing']?.toBool() ?? false, - scanning: map['scanning']?.toBool() ?? false, - ); - } - - String toJson() => json.encode(toMap()); - - factory RadioState.fromJson(String source) => - RadioState.fromMap(json.decode(source)); - - @override - String toString() { - return 'RadioState(freqMin: $freqMin, freqMax: $freqMax, freqStep: $freqStep, freqCurrent: $freqCurrent, playing: $playing, scanning: $scanning)'; - } - @override bool operator ==(Object other) { if (identical(this, other)) return true; |