diff --git a/lib/local_storage/sqflite_localpodcast.dart b/lib/local_storage/sqflite_localpodcast.dart index 7741340..937db2c 100644 --- a/lib/local_storage/sqflite_localpodcast.dart +++ b/lib/local_storage/sqflite_localpodcast.dart @@ -180,6 +180,15 @@ class DBHelper { return 0; } + Future removePodcastNewMark(String id) async { + var dbClient = await database; + await dbClient.transaction((txn) async { + await txn.rawUpdate( + "UPDATE Episodes SET is_new = 0 WHERE feed_id = ? AND is_new = 1", + [id]); + }); + } + Future getNeverUpdate(String id) async { var dbClient = await database; List list = await dbClient @@ -414,11 +423,12 @@ class DBHelper { ORDER BY add_date DESC"""); return list .map((record) => SubHistory( - DateTime.fromMillisecondsSinceEpoch(record['remove_date']), - DateTime.fromMillisecondsSinceEpoch(record['add_date']), - record['rss_url'], - record['title'], - status: record['status'] == 0 ? true : false,)) + DateTime.fromMillisecondsSinceEpoch(record['remove_date']), + DateTime.fromMillisecondsSinceEpoch(record['add_date']), + record['rss_url'], + record['title'], + status: record['status'] == 0 ? true : false, + )) .toList(); } @@ -1131,8 +1141,7 @@ class DBHelper { P.imagePath, P.primaryColor FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id LEFT JOIN PlayHistory H ON E.enclosure_url = H.enclosure_url GROUP BY E.enclosure_url HAVING SUM(H.listen_time) is null - OR SUM(H.listen_time) = 0 ORDER BY RANDOM() LIMIT ? """, - [random]); + OR SUM(H.listen_time) = 0 ORDER BY RANDOM() LIMIT ? """, [random]); } else { list = await dbClient.rawQuery( """SELECT E.title, E.enclosure_url, E.enclosure_length, E.is_new, diff --git a/lib/podcasts/podcast_detail.dart b/lib/podcasts/podcast_detail.dart index 16dd5cc..fd5770d 100644 --- a/lib/podcasts/podcast_detail.dart +++ b/lib/podcasts/podcast_detail.dart @@ -113,7 +113,8 @@ class _PodcastDetailState extends State { super.dispose(); } - Future _updateRssItem(BuildContext context, PodcastLocal podcastLocal) async { + Future _updateRssItem( + BuildContext context, PodcastLocal podcastLocal) async { final result = await _dbHelper.updatePodcastRss(podcastLocal); if (result >= 0) { Fluttertoast.showToast( @@ -204,6 +205,14 @@ class _PodcastDetailState extends State { } } + Future _getNewCount() async { + return await _dbHelper.getPodcastUpdateCounts(widget.podcastLocal.id); + } + + Future _removePodcastNewMark() async { + await _dbHelper.removePodcastNewMark(widget.podcastLocal.id); + } + Widget _podcastInfo(BuildContext context) { return Container( height: 170, @@ -471,7 +480,7 @@ class _PodcastDetailState extends State { Widget _actionBar(BuildContext context) { final s = context.s; - return Container( + return SizedBox( height: 30, child: Row( children: [ @@ -612,6 +621,40 @@ class _PodcastDetailState extends State { } }), Spacer(), + FutureBuilder( + future: _getNewCount(), + initialData: 0, + builder: (context, snapshot) { + return snapshot.data != 0 + ? Padding( + padding: EdgeInsets.symmetric(horizontal: 4), + child: Material( + color: Colors.transparent, + clipBehavior: Clip.hardEdge, + borderRadius: BorderRadius.circular(100), + child: SizedBox( + width: 30, + child: IconButton( + padding: EdgeInsets.only(bottom: 5), + tooltip: s.removeNewMark, + icon: Container( + height: 18, + width: 18, + child: CustomPaint( + painter: RemoveNewFlagPainter( + context.textTheme.bodyText1.color, + Colors.red))), + onPressed: () async { + await _removePodcastNewMark(); + if (mounted) { + setState(() {}); + } + }), + ), + ), + ) + : Center(); + }), if (!widget.hide) Material( color: Colors.transparent,