From f219ac9d3f2575e1ed3c6384483aee96a934c717 Mon Sep 17 00:00:00 2001 From: stonega Date: Sun, 24 Jan 2021 22:00:32 +0800 Subject: [PATCH] Bug fixs, playlist item was wrongly deleted --- lib/playlists/playlist_home.dart | 126 +++++++------- lib/widgets/dismissible_container.dart | 229 +++++++++---------------- 2 files changed, 146 insertions(+), 209 deletions(-) diff --git a/lib/playlists/playlist_home.dart b/lib/playlists/playlist_home.dart index 7666a58..5c8b578 100644 --- a/lib/playlists/playlist_home.dart +++ b/lib/playlists/playlist_home.dart @@ -273,71 +273,73 @@ class __QueueState extends State<_Queue> { @override Widget build(BuildContext context) { return Selector>( - selector: (_, audio) => - Tuple3(audio.playlist, audio.playerRunning, audio.episode), - builder: (_, data, __) { - var episodes = data.item1?.episodes?.toSet()?.toList(); - var queue = data.item1; - var running = data.item2; - return queue == null - ? Center() - : queue?.name == 'Queue' - ? ReorderableListView( - onReorder: (oldIndex, newIndex) { - context - .read() - .reorderPlaylist(oldIndex, newIndex); - setState(() {}); - }, - scrollDirection: Axis.vertical, - children: data.item2 - ? episodes.map((episode) { - if (episode.enclosureUrl != - episodes.first.enclosureUrl) { - return DismissibleContainer( + selector: (_, audio) => + Tuple3(audio.playlist, audio.playerRunning, audio.episode), + builder: (_, data, __) { + var episodes = data.item1?.episodes?.toSet()?.toList(); + var queue = data.item1; + var running = data.item2; + return queue == null + ? Center() + : queue.isQueue + ? ReorderableListView( + onReorder: (oldIndex, newIndex) { + context + .read() + .reorderPlaylist(oldIndex, newIndex); + setState(() {}); + }, + scrollDirection: Axis.vertical, + children: data.item2 + ? episodes.map((episode) { + if (episode.enclosureUrl != + episodes.first.enclosureUrl) { + return DismissibleContainer( + episode: episode, + onRemove: (value) => setState(() {}), + key: ValueKey(episode.enclosureUrl), + ); + } else { + return EpisodeCard(episode, + key: ValueKey('playing'), + isPlaying: true, + canReorder: true, + tileColor: context.primaryColorDark); + } + }).toList() + : episodes + .map((episode) => DismissibleContainer( episode: episode, onRemove: (value) => setState(() {}), key: ValueKey(episode.enclosureUrl), - ); - } else { - return EpisodeCard(episode, - key: ValueKey('playing'), - isPlaying: true, - canReorder: true, - tileColor: context.primaryColorDark); - } - }).toList() - : episodes - .map((episode) => DismissibleContainer( - episode: episode, - onRemove: (value) => setState(() {}), - key: ValueKey(episode.enclosureUrl), - )) - .toList()) - : ListView.builder( - itemCount: queue?.length, - itemBuilder: (context, index) { - final episode = - queue != null ? queue.episodes[index] : null; - final isPlaying = - data.item3 != null && data.item3 == episode; - return episode == null - ? Center() - : EpisodeCard( - episode, - isPlaying: isPlaying && running, - tileColor: - isPlaying ? context.primaryColorDark : null, - onTap: () async { - if (!isPlaying) { - await context - .read() - .loadEpisodeFromPlaylist(episode); - } - }, - ); - }); - }); + )) + .toList()) + : ListView.builder( + itemCount: queue?.length, + itemBuilder: (context, index) { + final episode = + queue != null ? queue.episodes[index] : null; + final isPlaying = + data.item3 != null && data.item3 == episode; + return episode == null + ? Center() + : EpisodeCard( + episode, + isPlaying: isPlaying && running, + tileColor: + isPlaying ? context.primaryColorDark : null, + onTap: () async { + if (!isPlaying) { + await context + .read() + .loadEpisodeFromPlaylist(episode); + } + }, + ); + }, + ); + }, + ); } } diff --git a/lib/widgets/dismissible_container.dart b/lib/widgets/dismissible_container.dart index 7d2777e..dd7e12d 100644 --- a/lib/widgets/dismissible_container.dart +++ b/lib/widgets/dismissible_container.dart @@ -33,157 +33,91 @@ class _DismissibleContainerState extends State { duration: Duration(milliseconds: 300), curve: Curves.easeInSine, alignment: Alignment.center, - height: _delete ? 0 : 90.0, + height: _delete ? 0 : 91.0, child: _delete ? Container( color: Colors.transparent, ) - : Dismissible( - key: ValueKey('${widget.episode.enclosureUrl}dis'), - background: Container( - padding: EdgeInsets.symmetric(horizontal: 20.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - decoration: BoxDecoration( - shape: BoxShape.circle, color: Colors.red), - padding: EdgeInsets.all(5), - alignment: Alignment.center, - child: Icon( - LineIcons.trash_alt_solid, - color: Colors.white, - size: 15, + : Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + child: Dismissible( + key: ValueKey('${widget.episode.enclosureUrl}dis'), + background: Container( + padding: EdgeInsets.symmetric(horizontal: 20.0), + height: 30, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( + decoration: BoxDecoration( + shape: BoxShape.circle, color: Colors.red), + padding: EdgeInsets.all(5), + alignment: Alignment.center, + child: Icon( + LineIcons.trash_alt_solid, + color: Colors.white, + size: 15, + ), + ), + Container( + decoration: BoxDecoration( + shape: BoxShape.circle, color: Colors.red), + padding: EdgeInsets.all(5), + alignment: Alignment.center, + child: Icon( + LineIcons.trash_alt_solid, + color: Colors.white, + size: 15, + ), + ), + ], ), ), - Container( - decoration: BoxDecoration( - shape: BoxShape.circle, color: Colors.red), - padding: EdgeInsets.all(5), - alignment: Alignment.center, - child: Icon( - LineIcons.trash_alt_solid, - color: Colors.white, - size: 15, - ), - ), - ], - ), - height: 30, - color: context.accentColor, - ), - onDismissed: (direction) async { - setState(() { - _delete = true; - }); - var index = await context - .read() - .delFromPlaylist(widget.episode); - widget.onRemove(true); - final episodeRemove = widget.episode; - Scaffold.of(context).removeCurrentSnackBar(); - Scaffold.of(context).showSnackBar(SnackBar( - behavior: SnackBarBehavior.floating, - backgroundColor: Colors.grey[800], - content: Text(s.toastRemovePlaylist, - style: TextStyle(color: Colors.white)), - action: SnackBarAction( - textColor: context.accentColor, - label: s.undo, - onPressed: () async { + onDismissed: (direction) async { + setState(() { + _delete = true; + }); + var index = await context + .read() + .delFromPlaylist(widget.episode); + widget.onRemove(true); + final episodeRemove = widget.episode; + Scaffold.of(context).removeCurrentSnackBar(); + Scaffold.of(context).showSnackBar(SnackBar( + behavior: SnackBarBehavior.floating, + backgroundColor: Colors.grey[800], + content: Text(s.toastRemovePlaylist, + style: TextStyle(color: Colors.white)), + action: SnackBarAction( + textColor: context.accentColor, + label: s.undo, + onPressed: () async { + await context + .read() + .addToPlaylistAt(episodeRemove, index); + widget.onRemove(false); + }), + )); + }, + child: EpisodeCard( + widget.episode, + isPlaying: false, + canReorder: true, + showDivider: false, + onTap: () async { await context .read() - .addToPlaylistAt(episodeRemove, index); - widget.onRemove(false); - }), - )); - }, - child: EpisodeCard( - widget.episode, - isPlaying: false, - canReorder: true, - onTap: () async { - await context - .read() - .episodeLoad(widget.episode); - widget.onRemove(true); - }, - ), - // SizedBox( - // height: 90.0, - // child: Column( - // mainAxisAlignment: MainAxisAlignment.spaceAround, - // children: [ - // Expanded( - // child: ListTile( - // contentPadding: EdgeInsets.symmetric(vertical: 8), - // onTap: () async { - // await context - // .read() - // .episodeLoad(widget.episode); - // widget.onRemove(true); - // }, - // title: Container( - // padding: EdgeInsets.fromLTRB(0, 5.0, 20.0, 5.0), - // child: Text( - // widget.episode.title, - // maxLines: 1, - // overflow: TextOverflow.ellipsis, - // ), - // ), - // leading: Row( - // mainAxisAlignment: MainAxisAlignment.start, - // crossAxisAlignment: CrossAxisAlignment.center, - // mainAxisSize: MainAxisSize.min, - // children: [ - // Icon(Icons.unfold_more, color: c), - // CircleAvatar( - // backgroundColor: c.withOpacity(0.5), - // backgroundImage: widget.episode.avatarImage), - // ], - // ), - // subtitle: Container( - // padding: EdgeInsets.only(top: 5, bottom: 5), - // height: 35, - // child: Row( - // children: [ - // if (widget.episode.explicit == 1) - // Container( - // decoration: BoxDecoration( - // color: Colors.red[800], - // shape: BoxShape.circle), - // height: 25.0, - // width: 25.0, - // margin: EdgeInsets.only(right: 10.0), - // alignment: Alignment.center, - // child: Text('E', - // style: TextStyle(color: Colors.white))), - // if (widget.episode.duration != 0) - // episodeTag( - // widget.episode.duration == 0 - // ? '' - // : s.minsCount( - // widget.episode.duration ~/ 60), - // Colors.cyan[300]), - // if (widget.episode.enclosureLength != null) - // episodeTag( - // widget.episode.enclosureLength == 0 - // ? '' - // : '${(widget.episode.enclosureLength) ~/ 1000000}MB', - // Colors.lightBlue[300]), - // ], - // ), - // ), - // //trailing: Icon(Icons.menu), - // ), - // ), - // Divider( - // height: 2, - // ), - // ], - // ), - // ), - ), + .episodeLoad(widget.episode); + widget.onRemove(true); + }, + ), + ), + ), + Divider(height: 1) + ], + ), ); } } @@ -194,13 +128,16 @@ class EpisodeCard extends StatelessWidget { final VoidCallback onTap; final bool isPlaying; final bool canReorder; + final bool showDivider; const EpisodeCard(this.episode, {this.tileColor, this.onTap, this.isPlaying, this.canReorder = false, + this.showDivider = true, Key key}) - : assert(episode != null), super(key: key); + : assert(episode != null), + super(key: key); @override Widget build(BuildContext context) { @@ -278,9 +215,7 @@ class EpisodeCard extends StatelessWidget { : SizedBox(width: 1), ), ), - Divider( - height: 1, - ), + if (showDivider) Divider(height: 1), ], ), );