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>
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
//final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
// GlobalKey<RefreshIndicatorState>();
final _dbHelper = DBHelper();
/// 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() {
return Consumer<GroupList>(
builder: (context, groupList, child) => PopupMenuButton<String>(
@ -656,7 +665,7 @@ class _RecentUpdateState extends State<_RecentUpdate>
}
Widget _addNewButton() {
final audio = context.read<AudioPlayerNotifier>();
// final audio = context.read<AudioPlayerNotifier>();
final s = context.s;
return FutureBuilder<int>(
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,
child: Row(
children: [
IconButton(
tooltip: s.removeNewMark,
icon: SizedBox(
height: 15,
height: 20,
width: 20,
child: CustomPaint(
painter: AddToPlaylistPainter(
painter: RemoveNewFlagPainter(
context.textTheme.bodyText1.color,
Colors.red))),
onPressed: () async {
await audio.addNewEpisode(_group);
_removeNewMark(_group);
if (mounted) {
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();
});
@ -738,12 +767,6 @@ 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(
@ -764,15 +787,13 @@ class _RecentUpdateState extends State<_RecentUpdate>
initNum: _scroll ? 0 : 12,
multiSelect: _multiSelect,
openPodcast: true,
selectedList:
_selectedEpisodes ?? [],
selectedList: _selectedEpisodes ?? [],
onSelect: (value) => setState(() {
_selectedEpisodes = value;
}),
),
SliverList(
delegate:
SliverChildBuilderDelegate(
delegate: SliverChildBuilderDelegate(
(context, index) {
return _loadMore
? Container(
@ -798,6 +819,24 @@ class _RecentUpdateState extends State<_RecentUpdate>
children: <Widget>[
_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,
@ -867,7 +906,6 @@ class _RecentUpdateState extends State<_RecentUpdate>
),
],
),
),
)
: 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
class WavePainter extends CustomPainter {
final double _fraction;