From 67d57c5334632326ded43b3194d38a007a9db5d1 Mon Sep 17 00:00:00 2001 From: stonegate Date: Tue, 13 Oct 2020 00:40:51 +0800 Subject: [PATCH] Multi select for favorite page. --- lib/home/home.dart | 346 ++++++++++++++++++++++++++------------------- 1 file changed, 203 insertions(+), 143 deletions(-) diff --git a/lib/home/home.dart b/lib/home/home.dart index 264e835..df4fcfc 100644 --- a/lib/home/home.dart +++ b/lib/home/home.dart @@ -1204,11 +1204,19 @@ class _MyFavoriteState extends State<_MyFavorite> Layout _layout; int _sortBy; bool _hideListened; + + ///Selected episode list. + List _selectedEpisodes; + + ///Toggle for multi-select. + bool _multiSelect; + @override void initState() { super.initState(); _loadMore = false; _sortBy = 0; + _multiSelect = false; } @override @@ -1264,6 +1272,11 @@ class _MyFavoriteState extends State<_MyFavorite> episodes: snapshot.data, layout: _layout, initNum: 0, + multiSelect: _multiSelect, + selectedList: _selectedEpisodes ?? [], + onSelect: (value) => setState(() { + _selectedEpisodes = value; + }), ), SliverList( delegate: SliverChildBuilderDelegate( @@ -1281,98 +1294,140 @@ class _MyFavoriteState extends State<_MyFavorite> ], ), ), - Container( - height: 40, - color: context.primaryColor, - child: Row( - children: [ - Material( - color: Colors.transparent, - child: PopupMenuButton( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(10))), - elevation: 1, - tooltip: s.homeSubMenuSortBy, - child: Container( - height: 50, - padding: EdgeInsets.symmetric( - horizontal: 20), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text(s.homeSubMenuSortBy), - Padding( + Column( + children: [ + if (!_multiSelect) + Container( + height: 40, + color: context.primaryColor, + child: Row( + children: [ + Material( + color: Colors.transparent, + child: PopupMenuButton( + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.all( + Radius.circular(10))), + elevation: 1, + tooltip: s.homeSubMenuSortBy, + child: Container( + height: 50, padding: EdgeInsets.symmetric( - horizontal: 5), + horizontal: 20), + child: Row( + mainAxisSize: + MainAxisSize.min, + children: [ + Text(s.homeSubMenuSortBy), + Padding( + padding: EdgeInsets + .symmetric( + horizontal: 5), + ), + Icon( + LineIcons + .hourglass_start_solid, + size: 18, + ) + ], + )), + itemBuilder: (context) => [ + PopupMenuItem( + value: 0, + child: Row( + children: [ + Text(s.updateDate), + Spacer(), + if (_sortBy == 0) + DotIndicator() + ], + ), ), - Icon( - LineIcons - .hourglass_start_solid, - size: 18, + PopupMenuItem( + value: 1, + child: Row( + children: [ + Text(s.likeDate), + Spacer(), + if (_sortBy == 1) + DotIndicator() + ], + ), ) ], - )), - itemBuilder: (context) => [ - PopupMenuItem( - value: 0, - child: Row( - children: [ - Text(s.updateDate), - Spacer(), - if (_sortBy == 0) DotIndicator() - ], + onSelected: (value) { + if (value == 0) { + setState(() => _sortBy = 0); + } else if (value == 1) { + setState(() => _sortBy = 1); + } + }, ), ), - PopupMenuItem( - value: 1, - child: Row( - children: [ - Text(s.likeDate), - Spacer(), - if (_sortBy == 1) DotIndicator() - ], + Spacer(), + Material( + color: Colors.transparent, + child: IconButton( + icon: SizedBox( + width: 30, + height: 15, + child: HideListened( + hideListened: + _hideListened ?? false, + ), + ), + onPressed: () { + setState(() => _hideListened = + !_hideListened); + }, ), - ) + ), + Material( + color: Colors.transparent, + child: LayoutButton( + layout: _layout, + onPressed: (layout) => + setState(() { + _layout = layout; + }), + ), + ), + Material( + color: Colors.transparent, + child: IconButton( + icon: SizedBox( + width: 20, + height: 10, + child: CustomPaint( + painter: + MultiSelectPainter( + color: context + .accentColor)), + ), + onPressed: () { + setState(() { + _selectedEpisodes = []; + _multiSelect = true; + }); + }, + )), ], - onSelected: (value) { - if (value == 0) { - setState(() => _sortBy = 0); - } else if (value == 1) { - setState(() => _sortBy = 1); + ), + ), + if (_multiSelect) + MultiSelectMenuBar( + selectedList: _selectedEpisodes, + hideFavorite: true, + onClose: (value) { + setState(() { + if (value) { + _multiSelect = false; } - }, - ), + }); + }, ), - Spacer(), - Material( - color: Colors.transparent, - child: IconButton( - icon: SizedBox( - width: 30, - height: 15, - child: HideListened( - hideListened: - _hideListened ?? false, - ), - ), - onPressed: () { - setState(() => - _hideListened = !_hideListened); - }, - ), - ), - Material( - color: Colors.transparent, - child: LayoutButton( - layout: _layout, - onPressed: (layout) => setState(() { - _layout = layout; - }), - ), - ), - ], - ), + ], ), ], ), @@ -1427,72 +1482,77 @@ class _MyDownloadState extends State<_MyDownload> future: _getDownloadedEpisodes(_sortBy, hideListened: _hideListened), builder: (context, snapshot) { var episodes = snapshot.data ?? []; - return CustomScrollView( - key: PageStorageKey('download_list'), - slivers: [ - DownloadList(), - SliverToBoxAdapter( - child: Container( - height: 40, - color: context.primaryColor, - child: Row( - children: [ - Container( - padding: EdgeInsets.symmetric(horizontal: 20), - child: Text(s.downloaded)), - Spacer(), - Material( - color: Colors.transparent, - child: IconButton( - icon: SizedBox( - width: 30, - height: 15, - child: HideListened( - hideListened: _hideListened ?? false, + return ScrollConfiguration( + behavior: NoGrowBehavior(), + child: CustomScrollView( + key: PageStorageKey('download_list'), + slivers: [ + DownloadList(), + SliverToBoxAdapter( + child: Container( + height: 40, + color: context.primaryColor, + child: Row( + children: [ + Container( + padding: EdgeInsets.symmetric(horizontal: 20), + child: Text(s.downloaded)), + Spacer(), + Material( + color: Colors.transparent, + child: IconButton( + icon: SizedBox( + width: 30, + height: 15, + child: HideListened( + hideListened: _hideListened ?? false, + ), ), + onPressed: () { + setState( + () => _hideListened = !_hideListened); + }, ), - onPressed: () { - setState(() => _hideListened = !_hideListened); - }, + ), + Material( + color: Colors.transparent, + child: LayoutButton( + layout: _layout ?? Layout.one, + onPressed: (layout) => setState(() { + _layout = layout; + }), + ), + ), + ], + )), + ), + episodes.length == 0 + ? SliverToBoxAdapter( + child: Padding( + padding: const EdgeInsets.only(top: 110), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(LineIcons.download_solid, + size: 80, color: Colors.grey[500]), + Padding( + padding: + EdgeInsets.symmetric(vertical: 10)), + Text( + s.noEpisodeDownload, + style: TextStyle(color: Colors.grey[500]), + ) + ], ), ), - Material( - color: Colors.transparent, - child: LayoutButton( - layout: _layout ?? Layout.one, - onPressed: (layout) => setState(() { - _layout = layout; - }), - ), - ), - ], - )), - ), - episodes.length == 0 - ? SliverToBoxAdapter( - child: Padding( - padding: const EdgeInsets.only(top: 110), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(LineIcons.download_solid, - size: 80, color: Colors.grey[500]), - Padding( - padding: EdgeInsets.symmetric(vertical: 10)), - Text( - s.noEpisodeDownload, - style: TextStyle(color: Colors.grey[500]), - ) - ], - ), + ) + : EpisodeGrid( + episodes: episodes, + layout: _layout, + initNum: 0, ), - ) - : EpisodeGrid( - episodes: episodes, - layout: _layout, - initNum: 0, - ), - ], + ], + ), ); }), );