diff --git a/lib/main.dart b/lib/main.dart index a85d367..1996c4e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'package:audio_session/audio_session.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; import 'injection_container.dart'; @@ -9,7 +10,6 @@ import 'presentation/pages/currently_playing.dart'; import 'presentation/pages/home_page.dart'; import 'presentation/pages/library_page.dart'; import 'presentation/pages/settings_page.dart'; -import 'presentation/state/audio_store.dart'; import 'presentation/state/navigation_store.dart'; import 'presentation/theming.dart'; import 'presentation/widgets/audio_service_widget.dart'; @@ -23,6 +23,10 @@ Future main() async { final session = await AudioSession.instance; await session.configure(const AudioSessionConfiguration.music()); + Logger.root.onRecord.listen((record) { + print('${record.time} [${record.level.name}] ${record.loggerName}: ${record.message}'); + }); + runApp(MyApp()); } @@ -70,8 +74,6 @@ class _RootPageState extends State { @override void dispose() { - final AudioStore _audioStore = Provider.of(context); - _audioStore.dispose(); super.dispose(); } diff --git a/lib/presentation/pages/currently_playing.dart b/lib/presentation/pages/currently_playing.dart index 0c319b2..a01ad3a 100644 --- a/lib/presentation/pages/currently_playing.dart +++ b/lib/presentation/pages/currently_playing.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; import '../../domain/entities/song.dart'; @@ -14,9 +15,11 @@ import 'queue_page.dart'; class CurrentlyPlayingPage extends StatelessWidget { const CurrentlyPlayingPage({Key key}) : super(key: key); + static final _log = Logger('CurrentlyPlayingPage'); + @override Widget build(BuildContext context) { - print('CurrentlyPlayingPage.build'); + _log.info('build started'); final AudioStore audioStore = Provider.of(context); return Scaffold( @@ -25,10 +28,8 @@ class CurrentlyPlayingPage extends StatelessWidget { builder: (BuildContext context, BoxConstraints constraints) => Observer( builder: (BuildContext context) { - print('CurrentlyPlayingPage.build -> Observer.build'); - final Song song = audioStore.song; - - print(audioStore.queueIndexStream.value); + _log.info('Observer.build'); + final Song song = audioStore.currentSongStream.value; return Padding( padding: const EdgeInsets.only( diff --git a/lib/presentation/state/audio_store.dart b/lib/presentation/state/audio_store.dart index b349db7..1b4313b 100644 --- a/lib/presentation/state/audio_store.dart +++ b/lib/presentation/state/audio_store.dart @@ -15,7 +15,7 @@ class AudioStore extends _AudioStore with _$AudioStore { abstract class _AudioStore with Store { _AudioStore(this._audioRepository) { - currentSong = _audioRepository.currentSongStream.asObservable(); + currentSongStream = _audioRepository.currentSongStream.distinct().asObservable(); currentPositionStream = _audioRepository.currentPositionStream.asObservable(initialValue: 0); @@ -27,22 +27,13 @@ abstract class _AudioStore with Store { shuffleModeStream = _audioRepository.shuffleModeStream .asObservable(initialValue: ShuffleMode.none); - _disposers.add(autorun((_) { - updateSong(currentSong.value); - })); - playbackStateStream = _audioRepository.playbackStateStream.asObservable(); } final AudioRepository _audioRepository; - final List _disposers = []; - - // TODO: naming and usage confusing! @observable - ObservableStream currentSong; - @observable - Song song; + ObservableStream currentSongStream; @observable ObservableStream playbackStateStream; @@ -59,13 +50,6 @@ abstract class _AudioStore with Store { @observable ObservableStream shuffleModeStream; - void dispose() { - print('AudioStore.dispose'); - for (final ReactionDisposer d in _disposers) { - d(); - } - } - @action Future playSong(int index, List songList) async { _audioRepository.playSong(index, songList); @@ -98,13 +82,4 @@ abstract class _AudioStore with Store { Future shuffleAll() async { _audioRepository.shuffleAll(); } - - @action - Future updateSong(Song streamValue) async { - print('updateSong'); - if (streamValue != null && streamValue != song) { - print('actually updating...'); - song = streamValue; - } - } } diff --git a/lib/presentation/state/audio_store.g.dart b/lib/presentation/state/audio_store.g.dart index 0770988..ce884b0 100644 --- a/lib/presentation/state/audio_store.g.dart +++ b/lib/presentation/state/audio_store.g.dart @@ -9,33 +9,18 @@ part of 'audio_store.dart'; // ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic mixin _$AudioStore on _AudioStore, Store { - final _$currentSongAtom = Atom(name: '_AudioStore.currentSong'); + final _$currentSongStreamAtom = Atom(name: '_AudioStore.currentSongStream'); @override - ObservableStream get currentSong { - _$currentSongAtom.reportRead(); - return super.currentSong; + ObservableStream get currentSongStream { + _$currentSongStreamAtom.reportRead(); + return super.currentSongStream; } @override - set currentSong(ObservableStream value) { - _$currentSongAtom.reportWrite(value, super.currentSong, () { - super.currentSong = value; - }); - } - - final _$songAtom = Atom(name: '_AudioStore.song'); - - @override - Song get song { - _$songAtom.reportRead(); - return super.song; - } - - @override - set song(Song value) { - _$songAtom.reportWrite(value, super.song, () { - super.song = value; + set currentSongStream(ObservableStream value) { + _$currentSongStreamAtom.reportWrite(value, super.currentSongStream, () { + super.currentSongStream = value; }); } @@ -152,18 +137,10 @@ mixin _$AudioStore on _AudioStore, Store { return _$skipToPreviousAsyncAction.run(() => super.skipToPrevious()); } - final _$updateSongAsyncAction = AsyncAction('_AudioStore.updateSong'); - - @override - Future updateSong(Song streamValue) { - return _$updateSongAsyncAction.run(() => super.updateSong(streamValue)); - } - @override String toString() { return ''' -currentSong: ${currentSong}, -song: ${song}, +currentSongStream: ${currentSongStream}, playbackStateStream: ${playbackStateStream}, currentPositionStream: ${currentPositionStream}, queueStream: ${queueStream}, diff --git a/lib/presentation/widgets/currently_playing_bar.dart b/lib/presentation/widgets/currently_playing_bar.dart index f52d579..b10f6e8 100644 --- a/lib/presentation/widgets/currently_playing_bar.dart +++ b/lib/presentation/widgets/currently_playing_bar.dart @@ -18,14 +18,14 @@ class CurrentlyPlayingBar extends StatelessWidget { return Observer( builder: (BuildContext context) { - if (audioStore.currentSong.value != null) { - final Song song = audioStore.currentSong.value; + if (audioStore.currentSongStream.value != null) { + final Song song = audioStore.currentSongStream.value; return Column( children: [ Container( child: LinearProgressIndicator( - value: audioStore.currentPositionStream.value / audioStore.currentSong.value.duration, + value: audioStore.currentPositionStream.value / audioStore.currentSongStream.value.duration, ), height: 2, ), diff --git a/lib/presentation/widgets/song_customization_buttons.dart b/lib/presentation/widgets/song_customization_buttons.dart index bccf8d8..d7c1811 100644 --- a/lib/presentation/widgets/song_customization_buttons.dart +++ b/lib/presentation/widgets/song_customization_buttons.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:provider/provider.dart'; +import '../../domain/entities/song.dart'; import '../state/audio_store.dart'; import '../state/music_data_store.dart'; import '../theming.dart'; @@ -15,34 +16,38 @@ class SongCustomizationButtons extends StatelessWidget { final AudioStore audioStore = Provider.of(context); return Observer( - builder: (BuildContext context) => Row( - children: [ - const Icon( - Icons.link, - size: 20.0, - ), - Container( - width: 40, - ), - const Icon( - Icons.favorite, - size: 20.0, - color: RASPBERRY, - ), - Container( - width: 40, - ), - IconButton( - icon: Icon( - Icons.remove_circle_outline, + builder: (BuildContext context) { + final Song song = audioStore.currentSongStream.value; + return Row( + children: [ + const Icon( + Icons.link, size: 20.0, - color: audioStore.song.blocked ? Colors.red : Colors.white70, ), - onPressed: () => musicDataStore.setSongBlocked(audioStore.song, !audioStore.song.blocked), - ), - ], - mainAxisAlignment: MainAxisAlignment.center, - ), + Container( + width: 40, + ), + const Icon( + Icons.favorite, + size: 20.0, + color: RASPBERRY, + ), + Container( + width: 40, + ), + IconButton( + icon: Icon( + Icons.remove_circle_outline, + size: 20.0, + color: song.blocked ? Colors.red : Colors.white70, + ), + onPressed: () => musicDataStore.setSongBlocked( + song, !song.blocked), + ), + ], + mainAxisAlignment: MainAxisAlignment.center, + ); + }, ); } } diff --git a/lib/presentation/widgets/time_progress_indicator.dart b/lib/presentation/widgets/time_progress_indicator.dart index 2d1cc73..fcbcbf7 100644 --- a/lib/presentation/widgets/time_progress_indicator.dart +++ b/lib/presentation/widgets/time_progress_indicator.dart @@ -14,7 +14,7 @@ class TimeProgressIndicator extends StatelessWidget { return Observer( builder: (BuildContext context) { - final int duration = audioStore.song?.duration ?? 1000; + final int duration = audioStore.currentSongStream.value?.duration ?? 1000; return Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), diff --git a/lib/system/datasources/audio_player_task.dart b/lib/system/datasources/audio_player_task.dart index 611d4a8..c2056dd 100644 --- a/lib/system/datasources/audio_player_task.dart +++ b/lib/system/datasources/audio_player_task.dart @@ -118,7 +118,7 @@ class AudioPlayerTask extends BackgroundAudioTask { print('AudioPlayerTask.init'); audioPlayer.positionStream.listen((position) => handlePosition(position)); audioPlayer.playerStateStream.listen((event) => handlePlayerState(event)); - audioPlayer.sequenceStateStream.listen((event) => playbackIndex = event.currentIndex); + audioPlayer.sequenceStateStream.listen((event) => playbackIndex = event?.currentIndex); final connectPort = IsolateNameServer.lookupPortByName(MOOR_ISOLATE); final MoorIsolate moorIsolate = MoorIsolate.fromConnectPort(connectPort); diff --git a/pubspec.lock b/pubspec.lock index ee13412..edd9f0a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -367,7 +367,7 @@ packages: source: hosted version: "0.4.0" logging: - dependency: transitive + dependency: "direct main" description: name: logging url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index fbdc185..6ef0128 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: get_it: ^4.0.2 provider: ^4.0.4 + logging: ^0.11.4 moor: ^3.0.2 moor_ffi: ^0.5.0 path_provider: