From 3371b1c61419147d47f1a1b276542820e0ae94db Mon Sep 17 00:00:00 2001 From: stonegate Date: Sat, 6 Jun 2020 12:51:34 +0800 Subject: [PATCH] :sparkles: Add mark as listened --- lib/episodes/episodedetail.dart | 94 ++++++++++++++++++++++++++++++++- lib/settings/history.dart | 12 ++++- lib/util/custompaint.dart | 35 ++++++++++++ lib/util/episodegrid.dart | 3 +- 4 files changed, 139 insertions(+), 5 deletions(-) diff --git a/lib/episodes/episodedetail.dart b/lib/episodes/episodedetail.dart index 2337e32..f5206a5 100644 --- a/lib/episodes/episodedetail.dart +++ b/lib/episodes/episodedetail.dart @@ -69,6 +69,13 @@ class _EpisodeDetailState extends State { } } + _markListened(EpisodeBrief episode) async { + DBHelper dbHelper = DBHelper(); + final PlayHistory history = + PlayHistory(episode.title, episode.enclosureUrl, 0, 1); + await dbHelper.saveHistory(history); + } + @override void initState() { super.initState(); @@ -99,6 +106,53 @@ class _EpisodeDetailState extends State { appBar: AppBar( // title: Text(widget.episodeItem.feedTitle), centerTitle: true, + actions: [ + PopupMenuButton( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10))), + elevation: 1, + tooltip: 'Menu', + itemBuilder: (context) => [ + PopupMenuItem( + value: 0, + child: Container( + padding: EdgeInsets.only(left: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + width: 25, + height: 25, + child: CustomPaint( + painter: ListenedAllPainter( + context.textTheme.bodyText1.color, + stroke: 1.5)), + ), + Padding( + padding: EdgeInsets.symmetric(horizontal: 5.0), + ), + Text( + 'Mark listened', + ), + ], + ), + ), + ), + ], + onSelected: (int value) async { + switch (value) { + case 0: + await _markListened(widget.episodeItem); + setState(() {}); + Fluttertoast.showToast( + msg: 'Mark as listened', + gravity: ToastGravity.BOTTOM, + ); + break; + } + }, + ), + ], ), body: Stack( children: [ @@ -280,8 +334,7 @@ class _EpisodeDetailState extends State { selector: (_, audio) => audio.playerRunning, builder: (_, data, __) { return Padding( - padding: EdgeInsets.only( - bottom: data ? 60.0 : 0), + padding: EdgeInsets.only(bottom: data ? 60.0 : 0), ); }), ], @@ -360,6 +413,13 @@ class _MenuBarState extends State { return '${(seconds ~/ 60)}:${(seconds.truncate() % 60).toString().padLeft(2, '0')}'; } + _markListened(EpisodeBrief episode) async { + DBHelper dbHelper = DBHelper(); + final PlayHistory history = + PlayHistory(episode.title, episode.enclosureUrl, 0, 1); + await dbHelper.saveHistory(history); + } + @override void initState() { super.initState(); @@ -505,6 +565,36 @@ class _MenuBarState extends State { ), ) : snapshot.data.seconds < 0.1 + // ? Material( + // color: Colors.transparent, + // child: InkWell( + // onTap: () async { + // await _markListened(widget.episodeItem); + // setState(() {}); + // Fluttertoast.showToast( + // msg: 'Mark as listened', + // gravity: ToastGravity.BOTTOM, + // ); + // }, + // child: Container( + // height: 50, + // padding: EdgeInsets.only( + // left: 15, + // right: 15, + // top: 12, + // bottom: 12), + // child: SizedBox( + // width: 22, + // height: 22, + // child: CustomPaint( + // painter: MarkListenedPainter( + // Colors.grey[700], + // stroke: 2.0), + // ), + // ), + // ), + // ), + // ) ? Center() : Material( color: Colors.transparent, diff --git a/lib/settings/history.dart b/lib/settings/history.dart index 5be983b..eaf9788 100644 --- a/lib/settings/history.dart +++ b/lib/settings/history.dart @@ -267,8 +267,16 @@ class _PlayedHistoryState extends State 10))), padding: EdgeInsets.all(2), child: Text( - _stringForSeconds(snapshot - .data[index].seconds), + snapshot.data[index] + .seconds == + 0 && + snapshot.data[index] + .seekValue == + 1 + ? 'Mark' + : _stringForSeconds( + snapshot.data[index] + .seconds), style: TextStyle( color: Colors.white), ), diff --git a/lib/util/custompaint.dart b/lib/util/custompaint.dart index 6d05d97..c80b33c 100644 --- a/lib/util/custompaint.dart +++ b/lib/util/custompaint.dart @@ -156,6 +156,41 @@ class ListenedAllPainter extends CustomPainter { } } +//Mark Listened indicator +class MarkListenedPainter extends CustomPainter { + Color _color; + double stroke; + MarkListenedPainter(this._color, {this.stroke = 1.0}); + @override + void paint(Canvas canvas, Size size) { + Paint _paint = Paint() + ..color = _color + ..strokeWidth = stroke + ..strokeCap = StrokeCap.round + ..style = PaintingStyle.stroke; + Path _path = Path(); + _path.moveTo(size.width / 6, size.height * 3 / 8); + _path.lineTo(size.width / 6, size.height * 5 / 8); + _path.moveTo(size.width / 3, size.height / 4); + _path.lineTo(size.width / 3, size.height * 3 / 4); + _path.moveTo(size.width / 2, size.height * 3 / 8); + _path.lineTo(size.width / 2, size.height * 5 / 8); + // _path.moveTo(size.width * 2 / 3, size.height * 4 / 9); + // _path.lineTo(size.width * 2 / 3, size.height * 5 / 9); + _path.moveTo(size.width / 2, size.height * 13 / 18); + _path.lineTo(size.width * 5 / 6, size.height * 13 / 18); + _path.moveTo(size.width * 2 / 3, size.height * 5 / 9); + _path.lineTo(size.width * 2 / 3, size.height * 8 / 9); + + canvas.drawPath(_path, _paint); + } + + @override + bool shouldRepaint(CustomPainter oldDelegate) { + return true; + } +} + //Add new episode to palylist class AddToPlaylistPainter extends CustomPainter { Color _color; diff --git a/lib/util/episodegrid.dart b/lib/util/episodegrid.dart index 2b5d81e..e94f348 100644 --- a/lib/util/episodegrid.dart +++ b/lib/util/episodegrid.dart @@ -96,11 +96,12 @@ class EpisodeGrid extends StatelessWidget { shape: BoxShape.circle, ), child: WaveLoader(color: context.accentColor)) - : layout == Layout.two && isListened > 0 + : layout != Layout.three && isListened > 0 ? Container( height: 20, width: 20, margin: EdgeInsets.symmetric(horizontal: 2), + padding: EdgeInsets.all(2), decoration: BoxDecoration( color: context.accentColor, shape: BoxShape.circle,