diff --git a/lib/home/audioplayer.dart b/lib/home/audioplayer.dart index 0e89475..b28f051 100644 --- a/lib/home/audioplayer.dart +++ b/lib/home/audioplayer.dart @@ -62,13 +62,11 @@ class PlayerWidget extends StatelessWidget { height: 60, child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [ - Selector>( + Selector>( selector: (_, audio) => - Tuple2(audio.episode?.primaryColor, audio.seekSliderValue), + Tuple2(audio.episode, audio.seekSliderValue), builder: (_, data, __) { - final c = context.brightness == Brightness.light - ? data.item1.colorizedark() - : data.item1.colorizeLight(); + final c = data.item1.backgroudColor(context); return SizedBox( height: 2, child: LinearProgressIndicator( diff --git a/lib/home/search_podcast.dart b/lib/home/search_podcast.dart index 51651c5..8877ac2 100644 --- a/lib/home/search_podcast.dart +++ b/lib/home/search_podcast.dart @@ -11,6 +11,7 @@ import 'package:flutter_html/flutter_html.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; import 'package:tsacdop/state/audio_state.dart'; +import 'package:tsacdop/type/episodebrief.dart'; import 'package:webfeed/webfeed.dart'; import '../.env.dart'; @@ -1002,17 +1003,16 @@ class _SearchResultDetailState extends State : Text(context.s.loadMore), onPressed: () { if (widget.searchEngine == - SearchEngine.listenNotes) { - _loading - ? null - : setState( - () { - _loading = true; - _searchFuture = _getListenNotesEpisodes( - id: widget.onlinePodcast.id, - nextEpisodeDate: _nextEpisdoeDate); - }, - ); + SearchEngine.listenNotes && + !_loading) { + setState( + () { + _loading = true; + _searchFuture = _getListenNotesEpisodes( + id: widget.onlinePodcast.id, + nextEpisodeDate: _nextEpisdoeDate); + }, + ); } }), ), @@ -1027,25 +1027,37 @@ class _SearchResultDetailState extends State : '${content[index].length.toTime} | ' '${content[index].pubDate.toDate(context)}', style: TextStyle(color: context.accentColor)), - trailing: TextButton( - style: ButtonStyle( - foregroundColor: MaterialStateProperty.all( - context.accentColor), - overlayColor: MaterialStateProperty.all( - context.primaryColor.withOpacity(0.3)), - padding: MaterialStateProperty.all( - EdgeInsets.symmetric(horizontal: 2))), - child: Text(context.s.play), - onPressed: () { - context.read().episodeLoad( - content[index].toEpisode, - fromSearch: true); - Fluttertoast.showToast( - msg: 'Wait a moment', - gravity: ToastGravity.BOTTOM, - ); - }, - ), + trailing: Selector( + selector: (_, audio) => audio.episode, + builder: (_, episode, __) { + if (episode != null && + episode.enclosureUrl == content[index].audio) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 20), + child: SizedBox( + width: 20, + height: 15, + child: WaveLoader(color: context.accentColor), + ), + ); + } + return TextButton( + style: ButtonStyle( + foregroundColor: MaterialStateProperty.all( + context.accentColor), + overlayColor: MaterialStateProperty.all( + context.scaffoldBackgroundColor.withOpacity(0.3)), + padding: + MaterialStateProperty.all( + EdgeInsets.symmetric(horizontal: 2))), + child: Text(context.s.play.toUpperCase()), + onPressed: () { + context.read().episodeLoad( + content[index].toEpisode, + fromSearch: true); + }, + ); + }), ); }, ); diff --git a/lib/state/audio_state.dart b/lib/state/audio_state.dart index 8542347..421dd0f 100644 --- a/lib/state/audio_state.dart +++ b/lib/state/audio_state.dart @@ -282,7 +282,9 @@ class AudioPlayerNotifier extends ChangeNotifier { await _playlist.getPlaylist(); if (state[1] != '') { var episode = await _dbHelper.getRssItemWithUrl(state[1]); - if ((!_playlist.isQueue && episode != null && _playlist.contains(episode)) || + if ((!_playlist.isQueue && + episode != null && + _playlist.contains(episode)) || (_playlist.isQueue && _queue.isNotEmpty && _queue.episodes.first.title == episode.title)) { @@ -371,9 +373,13 @@ class AudioPlayerNotifier extends ChangeNotifier { } //TODO load episode from last position when player running if (playerRunning) { - final history = PlayHistory(_episode.title, _episode.enclosureUrl, - backgroundAudioPosition ~/ 1000, seekSliderValue); - await _dbHelper.saveHistory(history); + if (_playFromSearchList.contains(_episode)) { + _queue.delFromPlaylist(_episode); + } else { + final history = PlayHistory(_episode.title, _episode.enclosureUrl, + backgroundAudioPosition ~/ 1000, seekSliderValue); + await _dbHelper.saveHistory(history); + } _queue.addToPlayListAt(episodeNew, 0); await updatePlaylist(_queue, updateEpisodes: !fromSearch); if (!_playlist.isQueue) { @@ -495,8 +501,9 @@ class AudioPlayerNotifier extends ChangeNotifier { .where((event) => event != null) .listen((item) async { var episode = await _dbHelper.getRssItemWithMediaId(item.id); - if(episode == null){ - episode = _playFromSearchList.firstWhere((e) => e.mediaId == item.id, orElse: () => null); + if (episode == null) { + episode = _playFromSearchList.firstWhere((e) => e.mediaId == item.id, + orElse: () => null); } _backgroundAudioDuration = item.duration?.inMilliseconds ?? 0; if (episode != null) { diff --git a/lib/type/episodebrief.dart b/lib/type/episodebrief.dart index 78a101b..34966a0 100644 --- a/lib/type/episodebrief.dart +++ b/lib/type/episodebrief.dart @@ -72,6 +72,7 @@ class EpisodeBrief extends Equatable { } Color backgroudColor(BuildContext context) { + if (primaryColor == '') return context.accentColor; return context.brightness == Brightness.light ? primaryColor.colorizedark() : primaryColor.colorizeLight(); diff --git a/lib/type/search_api/searchepisodes.dart b/lib/type/search_api/searchepisodes.dart index 65a988f..24afca1 100644 --- a/lib/type/search_api/searchepisodes.dart +++ b/lib/type/search_api/searchepisodes.dart @@ -51,7 +51,7 @@ class OnlineEpisode { 0, pubDate, title, - jsonEncode([120,220,128]), + '', length ?? 0, 0, '',