From 26353bb67b4c593b392aee9ad7ea9509bdf1bee2 Mon Sep 17 00:00:00 2001 From: Stonegate Date: Fri, 1 Jan 2021 23:42:32 +0800 Subject: [PATCH] Change setting menu, remove playlist. --- lib/playlists/playlist_page.dart | 212 +++++++++++++++++++++++++------ 1 file changed, 172 insertions(+), 40 deletions(-) diff --git a/lib/playlists/playlist_page.dart b/lib/playlists/playlist_page.dart index 7558047..c1eef93 100644 --- a/lib/playlists/playlist_page.dart +++ b/lib/playlists/playlist_page.dart @@ -2,6 +2,7 @@ import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:tsacdop/widgets/general_dialog.dart'; import '../state/audio_state.dart'; import '../type/episodebrief.dart'; @@ -19,10 +20,11 @@ class PlaylistDetail extends StatefulWidget { class _PlaylistDetailState extends State { final List _selectedEpisodes = []; bool _resetSelected; + @override - void setState(fn) { + void initState() { _resetSelected = false; - super.setState(fn); + super.initState(); } @override @@ -42,15 +44,16 @@ class _PlaylistDetailState extends State { ? widget.playlist.name : '${_selectedEpisodes.length} selected'), actions: [ - IconButton( - splashRadius: 20, - icon: Icon(Icons.delete_outline_rounded), - onPressed: () { - context.read().removeEpisodeFromPlaylist( - widget.playlist, - episodes: _selectedEpisodes); - setState(_selectedEpisodes.clear); - }), + if (_selectedEpisodes.isNotEmpty) + IconButton( + splashRadius: 20, + icon: Icon(Icons.delete_outline_rounded), + onPressed: () { + context.read().removeEpisodeFromPlaylist( + widget.playlist, + episodes: _selectedEpisodes); + setState(_selectedEpisodes.clear); + }), if (_selectedEpisodes.isNotEmpty) IconButton( splashRadius: 20, @@ -61,35 +64,51 @@ class _PlaylistDetailState extends State { _resetSelected = !_resetSelected; }); }), - SizedBox( - height: 40, - width: 40, - child: Material( - color: Colors.transparent, - borderRadius: BorderRadius.circular(100), - clipBehavior: Clip.hardEdge, - child: SizedBox( - height: 40, - width: 40, - child: PopupMenuButton( - icon: Icon(Icons.more_vert), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10)), - elevation: 1, - tooltip: s.menu, - itemBuilder: (context) => [ - PopupMenuItem(value: 1, child: Text('Clear all')), - ], - onSelected: (value) { - if (value == 1) { - context - .read() - .clearPlaylist(widget.playlist); - } - }), - ), - ), - ) + IconButton( + splashRadius: 20, + icon: Icon(Icons.more_vert), + onPressed: () => generalSheet(context, + title: widget.playlist.name, + child: _PlaylistSetting(widget.playlist)) + .then((value) { + if (!context + .read() + .playlists + .contains(widget.playlist)) { + Navigator.pop(context); + } + setState(() {}); + }), + ), + //SizedBox( + // height: 40, + // width: 40, + // child: Material( + // color: Colors.transparent, + // borderRadius: BorderRadius.circular(100), + // clipBehavior: Clip.hardEdge, + // child: SizedBox( + // height: 40, + // width: 40, + // child: PopupMenuButton( + // icon: Icon(Icons.more_vert), + // shape: RoundedRectangleBorder( + // borderRadius: BorderRadius.circular(10)), + // elevation: 1, + // tooltip: s.menu, + // itemBuilder: (context) => [ + // PopupMenuItem(value: 1, child: Text('Clear all')), + // ], + // onSelected: (value) { + // if (value == 1) { + // context + // .read() + // .clearPlaylist(widget.playlist); + // } + // }), + // ), + // ), + //) ], ), body: Selector>( @@ -287,3 +306,116 @@ class __PlaylistItemState extends State<_PlaylistItem> )); } } + +class _PlaylistSetting extends StatefulWidget { + final Playlist playlist; + _PlaylistSetting(this.playlist, {Key key}) : super(key: key); + + @override + __PlaylistSettingState createState() => __PlaylistSettingState(); +} + +class __PlaylistSettingState extends State<_PlaylistSetting> { + bool _clearConfirm; + bool _removeConfirm; + + @override + void initState() { + _clearConfirm = false; + _removeConfirm = false; + super.initState(); + } + + @override + Widget build(BuildContext context) { + final s = context.s; + final textStyle = context.textTheme.bodyText2; + return Column( + children: [ + ListTile( + onTap: () { + setState(() => _clearConfirm = true); + }, + dense: true, + title: Row( + children: [ + Icon(Icons.highlight_off, size: 18), + SizedBox(width: 20), + Text('Clear all', style: textStyle), + ], + ), + ), + if (_clearConfirm) + Container( + width: double.infinity, + color: context.primaryColorDark, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + FlatButton( + onPressed: () => setState(() { + _clearConfirm = false; + }), + child: + Text(s.cancel, style: TextStyle(color: Colors.grey[600])), + ), + FlatButton( + splashColor: Colors.red.withAlpha(70), + onPressed: () async { + context + .read() + .clearPlaylist(widget.playlist); + Navigator.of(context).pop(); + }, + child: + Text(s.confirm, style: TextStyle(color: Colors.red))), + ], + ), + ), + if (widget.playlist.name != 'Queue') + ListTile( + onTap: () { + setState(() => _removeConfirm = true); + }, + dense: true, + title: Row( + children: [ + Icon(Icons.delete, color: Colors.red, size: 18), + SizedBox(width: 20), + Text('Remove playlist', + style: textStyle.copyWith( + color: Colors.red, fontWeight: FontWeight.bold)), + ], + ), + ), + if (_removeConfirm) + Container( + width: double.infinity, + color: context.primaryColorDark, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + FlatButton( + onPressed: () => setState(() { + _removeConfirm = false; + }), + child: + Text(s.cancel, style: TextStyle(color: Colors.grey[600])), + ), + FlatButton( + splashColor: Colors.red.withAlpha(70), + onPressed: () async { + context + .read() + .deletePlaylist(widget.playlist); + Navigator.of(context).pop(); + }, + child: + Text(s.confirm, style: TextStyle(color: Colors.red))), + ], + ), + ), + ], + ); + } +}