Refresh and remove new mark button

This commit is contained in:
stonega 2020-12-28 22:08:52 +08:00
parent 526eeb885b
commit 26d49b4da3
2 changed files with 228 additions and 146 deletions

View File

@ -506,8 +506,8 @@ class _RecentUpdate extends StatefulWidget {
class _RecentUpdateState extends State<_RecentUpdate> class _RecentUpdateState extends State<_RecentUpdate>
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin { with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = //final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>(); // GlobalKey<RefreshIndicatorState>();
final _dbHelper = DBHelper(); final _dbHelper = DBHelper();
/// Episodes loaded first time. /// Episodes loaded first time.
@ -593,6 +593,15 @@ class _RecentUpdateState extends State<_RecentUpdate>
} }
} }
/// Remove new mark.
Future<void> _removeNewMark(List<String> group) async {
if (group.isEmpty) {
_dbHelper.removeAllNewMark();
} else {
_dbHelper.removeGroupNewMark(group);
}
}
Widget _switchGroupButton() { Widget _switchGroupButton() {
return Consumer<GroupList>( return Consumer<GroupList>(
builder: (context, groupList, child) => PopupMenuButton<String>( builder: (context, groupList, child) => PopupMenuButton<String>(
@ -656,7 +665,7 @@ class _RecentUpdateState extends State<_RecentUpdate>
} }
Widget _addNewButton() { Widget _addNewButton() {
final audio = context.read<AudioPlayerNotifier>(); // final audio = context.read<AudioPlayerNotifier>();
final s = context.s; final s = context.s;
return FutureBuilder<int>( return FutureBuilder<int>(
future: _getUpdateCounts(_group), future: _getUpdateCounts(_group),
@ -665,27 +674,47 @@ class _RecentUpdateState extends State<_RecentUpdate>
return snapshot.data != 0 return snapshot.data != 0
? Material( ? Material(
color: Colors.transparent, color: Colors.transparent,
child: IconButton( child: Row(
tooltip: s.addNewEpisodeTooltip, children: [
IconButton(
tooltip: s.removeNewMark,
icon: SizedBox( icon: SizedBox(
height: 15, height: 20,
width: 20, width: 20,
child: CustomPaint( child: CustomPaint(
painter: AddToPlaylistPainter( painter: RemoveNewFlagPainter(
context.textTheme.bodyText1.color, context.textTheme.bodyText1.color,
Colors.red))), Colors.red))),
onPressed: () async { onPressed: () async {
await audio.addNewEpisode(_group); _removeNewMark(_group);
if (mounted) { if (mounted) {
setState(() {}); setState(() {});
} }
Fluttertoast.showToast(
msg: _groupName == 'All'
? s.addNewEpisodeAll(snapshot.data)
: s.addEpisodeGroup(_groupName, snapshot.data),
gravity: ToastGravity.BOTTOM,
);
}), }),
// 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(); : Center();
}); });
@ -738,12 +767,6 @@ class _RecentUpdateState extends State<_RecentUpdate>
} }
return true; return true;
}, },
child: RefreshIndicator(
key: _refreshIndicatorKey,
color: Colors.white,
backgroundColor: context.accentColor,
semanticsLabel: s.refreshStarted,
onRefresh: _updateRssItem,
child: Stack( child: Stack(
children: [ children: [
ScrollConfiguration( ScrollConfiguration(
@ -764,15 +787,13 @@ class _RecentUpdateState extends State<_RecentUpdate>
initNum: _scroll ? 0 : 12, initNum: _scroll ? 0 : 12,
multiSelect: _multiSelect, multiSelect: _multiSelect,
openPodcast: true, openPodcast: true,
selectedList: selectedList: _selectedEpisodes ?? [],
_selectedEpisodes ?? [],
onSelect: (value) => setState(() { onSelect: (value) => setState(() {
_selectedEpisodes = value; _selectedEpisodes = value;
}), }),
), ),
SliverList( SliverList(
delegate: delegate: SliverChildBuilderDelegate(
SliverChildBuilderDelegate(
(context, index) { (context, index) {
return _loadMore return _loadMore
? Container( ? Container(
@ -798,6 +819,24 @@ class _RecentUpdateState extends State<_RecentUpdate>
children: <Widget>[ children: <Widget>[
_switchGroupButton(), _switchGroupButton(),
Spacer(), 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(), _addNewButton(),
Material( Material(
color: Colors.transparent, color: Colors.transparent,
@ -867,7 +906,6 @@ class _RecentUpdateState extends State<_RecentUpdate>
), ),
], ],
), ),
),
) )
: Center(); : Center();
}, },

View File

@ -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 //Wave play indicator
class WavePainter extends CustomPainter { class WavePainter extends CustomPainter {
final double _fraction; final double _fraction;