From 26d49b4da3e0aaef86a1cd4f5ed6b46b32211809 Mon Sep 17 00:00:00 2001 From: stonega Date: Mon, 28 Dec 2020 22:08:52 +0800 Subject: [PATCH] Refresh and remove new mark button --- lib/home/home.dart | 330 ++++++++++++++++++--------------- lib/widgets/custom_widget.dart | 44 +++++ 2 files changed, 228 insertions(+), 146 deletions(-) diff --git a/lib/home/home.dart b/lib/home/home.dart index 7681375..8cd5a95 100644 --- a/lib/home/home.dart +++ b/lib/home/home.dart @@ -506,8 +506,8 @@ class _RecentUpdate extends StatefulWidget { class _RecentUpdateState extends State<_RecentUpdate> with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin { - final GlobalKey _refreshIndicatorKey = - GlobalKey(); + //final GlobalKey _refreshIndicatorKey = + // GlobalKey(); final _dbHelper = DBHelper(); /// Episodes loaded first time. @@ -593,6 +593,15 @@ class _RecentUpdateState extends State<_RecentUpdate> } } + /// Remove new mark. + Future _removeNewMark(List group) async { + if (group.isEmpty) { + _dbHelper.removeAllNewMark(); + } else { + _dbHelper.removeGroupNewMark(group); + } + } + Widget _switchGroupButton() { return Consumer( builder: (context, groupList, child) => PopupMenuButton( @@ -656,7 +665,7 @@ class _RecentUpdateState extends State<_RecentUpdate> } Widget _addNewButton() { - final audio = context.read(); + // final audio = context.read(); final s = context.s; return FutureBuilder( future: _getUpdateCounts(_group), @@ -665,27 +674,47 @@ class _RecentUpdateState extends State<_RecentUpdate> return snapshot.data != 0 ? Material( color: Colors.transparent, - child: IconButton( - tooltip: s.addNewEpisodeTooltip, - icon: SizedBox( - height: 15, - width: 20, - child: CustomPaint( - painter: AddToPlaylistPainter( - context.textTheme.bodyText1.color, - Colors.red))), - onPressed: () async { - await audio.addNewEpisode(_group); - if (mounted) { - setState(() {}); - } - Fluttertoast.showToast( - msg: _groupName == 'All' - ? s.addNewEpisodeAll(snapshot.data) - : s.addEpisodeGroup(_groupName, snapshot.data), - gravity: ToastGravity.BOTTOM, - ); - }), + child: Row( + children: [ + IconButton( + tooltip: s.removeNewMark, + icon: SizedBox( + height: 20, + width: 20, + child: CustomPaint( + painter: RemoveNewFlagPainter( + context.textTheme.bodyText1.color, + Colors.red))), + onPressed: () async { + _removeNewMark(_group); + if (mounted) { + setState(() {}); + } + }), + // IconButton( + // tooltip: s.addNewEpisodeTooltip, + // icon: SizedBox( + // height: 15, + // width: 20, + // child: CustomPaint( + // painter: AddToPlaylistPainter( + // context.textTheme.bodyText1.color, + // Colors.red))), + // onPressed: () async { + // await audio.addNewEpisode(_group); + // if (mounted) { + // setState(() {}); + // } + // Fluttertoast.showToast( + // msg: _groupName == 'All' + // ? s.addNewEpisodeAll(snapshot.data) + // : s.addEpisodeGroup( + // _groupName, snapshot.data), + // gravity: ToastGravity.BOTTOM, + // ); + // }), + ], + ), ) : Center(); }); @@ -738,135 +767,144 @@ class _RecentUpdateState extends State<_RecentUpdate> } return true; }, - child: RefreshIndicator( - key: _refreshIndicatorKey, - color: Colors.white, - backgroundColor: context.accentColor, - semanticsLabel: s.refreshStarted, - onRefresh: _updateRssItem, - child: Stack( - children: [ - ScrollConfiguration( - behavior: NoGrowBehavior(), - child: CustomScrollView( - key: PageStorageKey('update'), - physics: - const AlwaysScrollableScrollPhysics(), - slivers: [ - SliverToBoxAdapter( - child: SizedBox( - height: 40, - ), - ), - EpisodeGrid( - episodes: snapshot.data, - layout: _layout, - initNum: _scroll ? 0 : 12, - multiSelect: _multiSelect, - openPodcast: true, - selectedList: - _selectedEpisodes ?? [], - onSelect: (value) => setState(() { - _selectedEpisodes = value; - }), - ), - SliverList( - delegate: - SliverChildBuilderDelegate( - (context, index) { - return _loadMore - ? Container( - height: 2, - child: - LinearProgressIndicator()) - : Center(); - }, - childCount: 1, - ), - ), - ]), - ), - Column( - children: [ - if (!_multiSelect) - Container( + child: Stack( + children: [ + ScrollConfiguration( + behavior: NoGrowBehavior(), + child: CustomScrollView( + key: PageStorageKey('update'), + physics: + const AlwaysScrollableScrollPhysics(), + slivers: [ + SliverToBoxAdapter( + child: SizedBox( height: 40, - color: context.primaryColor, - child: Material( - color: Colors.transparent, - child: Row( - children: [ - _switchGroupButton(), - Spacer(), - _addNewButton(), - Material( + ), + ), + EpisodeGrid( + episodes: snapshot.data, + layout: _layout, + initNum: _scroll ? 0 : 12, + multiSelect: _multiSelect, + openPodcast: true, + selectedList: _selectedEpisodes ?? [], + onSelect: (value) => setState(() { + _selectedEpisodes = value; + }), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (context, index) { + return _loadMore + ? Container( + height: 2, + child: + LinearProgressIndicator()) + : Center(); + }, + childCount: 1, + ), + ), + ]), + ), + Column( + children: [ + if (!_multiSelect) + Container( + height: 40, + color: context.primaryColor, + child: Material( + color: Colors.transparent, + child: Row( + children: [ + _switchGroupButton(), + Spacer(), + Material( + color: Colors.transparent, + child: IconButton( + tooltip: + context.s.refresh, + icon: Icon( + LineIcons + .redo_alt_solid, + size: 16), + onPressed: () { + _updateRssItem(); + Fluttertoast.showToast( + msg: s.refreshStarted, + gravity: ToastGravity + .BOTTOM, + ); + }), + ), + _addNewButton(), + Material( + color: Colors.transparent, + child: IconButton( + tooltip: + s.hideListenedSetting, + 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( - tooltip: - s.hideListenedSetting, icon: SizedBox( - width: 30, - height: 15, - child: HideListened( - hideListened: - _hideListened ?? - false, - ), + width: 20, + height: 10, + child: CustomPaint( + painter: MultiSelectPainter( + color: context + .accentColor)), ), onPressed: () { - setState(() => - _hideListened = - !_hideListened); + setState(() { + _selectedEpisodes = + []; + _multiSelect = true; + }); }, - ), - ), - 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; - }); - }, - )), - ], - ), - )), - if (_multiSelect) - MultiSelectMenuBar( - selectedList: _selectedEpisodes, - onClose: (value) { - setState(() { - if (value) { - _multiSelect = false; - } - }); - }, - ), - ], - ), - ], - ), + )), + ], + ), + )), + if (_multiSelect) + MultiSelectMenuBar( + selectedList: _selectedEpisodes, + onClose: (value) { + setState(() { + if (value) { + _multiSelect = false; + } + }); + }, + ), + ], + ), + ], ), ) : Center(); diff --git a/lib/widgets/custom_widget.dart b/lib/widgets/custom_widget.dart index ab9e146..e099d4b 100644 --- a/lib/widgets/custom_widget.dart +++ b/lib/widgets/custom_widget.dart @@ -409,6 +409,50 @@ class AddToPlaylistPainter extends CustomPainter { } } +/// Remove new flag icon. +class RemoveNewFlagPainter extends CustomPainter { + final Color color; + final Color textColor; + RemoveNewFlagPainter(this.color, this.textColor); + + @override + void paint(Canvas canvas, Size size) { + var _paint = Paint() + ..color = color + ..strokeWidth = 1 + ..strokeCap = StrokeCap.round + ..style = PaintingStyle.stroke; + + var _path = Path(); + + _path.moveTo(size.width * 3 / 5, size.height / 5); + _path.lineTo(size.width * 4 / 5, size.height * 2 / 5); + _path.lineTo(size.width * 2 / 5, size.height * 4 / 5); + _path.lineTo(size.width / 5, size.height * 3 / 5); + _path.lineTo(size.width * 3 / 5, size.height / 5); + _path.moveTo(size.width * 2 / 5, size.height * 2 / 5); + _path.lineTo(size.width * 3 / 5, size.height * 3 / 5); + + var textPainter = TextPainter( + textAlign: TextAlign.center, + textDirection: TextDirection.ltr, + text: TextSpan( + text: 'N', + style: TextStyle( + fontStyle: FontStyle.italic, color: textColor, fontSize: 10), + )) + ..layout(); + textPainter.paint(canvas, Offset(size.width * 4 / 7, size.height * 3 / 5)); + canvas.drawPath(_path, _paint); + } + + @override + bool shouldRepaint(RemoveNewFlagPainter oldDelegate) => false; + + @override + bool shouldRebuildSemantics(RemoveNewFlagPainter oldDelegate) => false; +} + //Wave play indicator class WavePainter extends CustomPainter { final double _fraction;