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: [
icon: SizedBox( IconButton(
height: 15, tooltip: s.removeNewMark,
width: 20, icon: SizedBox(
child: CustomPaint( height: 20,
painter: AddToPlaylistPainter( width: 20,
context.textTheme.bodyText1.color, child: CustomPaint(
Colors.red))), painter: RemoveNewFlagPainter(
onPressed: () async { context.textTheme.bodyText1.color,
await audio.addNewEpisode(_group); Colors.red))),
if (mounted) { onPressed: () async {
setState(() {}); _removeNewMark(_group);
} if (mounted) {
Fluttertoast.showToast( setState(() {});
msg: _groupName == 'All' }
? s.addNewEpisodeAll(snapshot.data) }),
: s.addEpisodeGroup(_groupName, snapshot.data), // IconButton(
gravity: ToastGravity.BOTTOM, // 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,135 +767,144 @@ class _RecentUpdateState extends State<_RecentUpdate>
} }
return true; return true;
}, },
child: RefreshIndicator( child: Stack(
key: _refreshIndicatorKey, children: [
color: Colors.white, ScrollConfiguration(
backgroundColor: context.accentColor, behavior: NoGrowBehavior(),
semanticsLabel: s.refreshStarted, child: CustomScrollView(
onRefresh: _updateRssItem, key: PageStorageKey<String>('update'),
child: Stack( physics:
children: [ const AlwaysScrollableScrollPhysics(),
ScrollConfiguration( slivers: <Widget>[
behavior: NoGrowBehavior(), SliverToBoxAdapter(
child: CustomScrollView( child: SizedBox(
key: PageStorageKey<String>('update'),
physics:
const AlwaysScrollableScrollPhysics(),
slivers: <Widget>[
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(
height: 40, height: 40,
color: context.primaryColor, ),
child: Material( ),
color: Colors.transparent, EpisodeGrid(
child: Row( episodes: snapshot.data,
children: <Widget>[ layout: _layout,
_switchGroupButton(), initNum: _scroll ? 0 : 12,
Spacer(), multiSelect: _multiSelect,
_addNewButton(), openPodcast: true,
Material( 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: <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,
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, color: Colors.transparent,
child: IconButton( child: IconButton(
tooltip:
s.hideListenedSetting,
icon: SizedBox( icon: SizedBox(
width: 30, width: 20,
height: 15, height: 10,
child: HideListened( child: CustomPaint(
hideListened: painter: MultiSelectPainter(
_hideListened ?? color: context
false, .accentColor)),
),
), ),
onPressed: () { onPressed: () {
setState(() => setState(() {
_hideListened = _selectedEpisodes =
!_hideListened); [];
_multiSelect = true;
});
}, },
), )),
), ],
Material( ),
color: Colors.transparent, )),
child: LayoutButton( if (_multiSelect)
layout: _layout, MultiSelectMenuBar(
onPressed: (layout) => selectedList: _selectedEpisodes,
setState(() { onClose: (value) {
_layout = layout; setState(() {
}), if (value) {
), _multiSelect = false;
), }
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;
}
});
},
),
],
),
],
),
), ),
) )
: 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;