From 48922e65ccc23f966f20219d6fe63c90d883a2a5 Mon Sep 17 00:00:00 2001 From: stonega Date: Wed, 17 Feb 2021 00:57:06 +0800 Subject: [PATCH] Option to always hide new mark for podcast. --- lib/local_storage/sqflite_localpodcast.dart | 34 ++++++++++++++++++--- lib/podcasts/podcast_settings.dart | 31 +++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/lib/local_storage/sqflite_localpodcast.dart b/lib/local_storage/sqflite_localpodcast.dart index e01fd68..221c306 100644 --- a/lib/local_storage/sqflite_localpodcast.dart +++ b/lib/local_storage/sqflite_localpodcast.dart @@ -28,7 +28,7 @@ class DBHelper { var documentsDirectory = await getDatabasesPath(); var path = join(documentsDirectory, "podcasts.db"); var theDb = await openDatabase(path, - version: 6, onCreate: _onCreate, onUpgrade: _onUpgrade); + version: 7, onCreate: _onCreate, onUpgrade: _onUpgrade); return theDb; } @@ -40,7 +40,8 @@ class DBHelper { background_image TEXT DEFAULT '', hosts TEXT DEFAULT '',update_count INTEGER DEFAULT 0, episode_count INTEGER DEFAULT 0, skip_seconds INTEGER DEFAULT 0, auto_download INTEGER DEFAULT 0, skip_seconds_end INTEGER DEFAULT 0, - never_update INTEGER DEFAULT 0, funding TEXT DEFAULT '[]')"""); + never_update INTEGER DEFAULT 0, funding TEXT DEFAULT '[]', + hide_new_mark INTEGER DEFAULT 0 )"""); await db .execute("""CREATE TABLE Episodes(id INTEGER PRIMARY KEY,title TEXT, enclosure_url TEXT UNIQUE, enclosure_length INTEGER, pubDate TEXT, @@ -90,6 +91,8 @@ class DBHelper { case (5): await _v6Update(db); break; + case (6): + await _v7Update(db); } } @@ -126,6 +129,10 @@ class DBHelper { """); } + Future _v7Update(Database db) async { + await db.execute("ALTER TABLE PodcastLocal ADD hide_new_mark INTEGER DEFAULT 0"); + } + Future> getPodcastLocal(List podcasts, {bool updateOnly = false}) async { var dbClient = await database; @@ -254,6 +261,21 @@ class DBHelper { [boo ? 1 : 0, id]); } + Future getHideNewMark(String id) async { + var dbClient = await database; + List list = await dbClient + .rawQuery('SELECT hide_new_mark FROM PodcastLocal WHERE id = ?', [id]); + if (list.isNotEmpty) return list.first['hide_new_mark'] == 1; + return false; + } + + Future saveHideNewMark(String id, {bool boo}) async { + var dbClient = await database; + return await dbClient.rawUpdate( + "UPDATE PodcastLocal SET hide_new_mark = ? WHERE id = ?", + [boo ? 1 : 0, id]); + } + Future getPodcastUpdateCounts(String id) async { var dbClient = await database; List list = await dbClient.rawQuery( @@ -682,10 +704,11 @@ class DBHelper { Future updatePodcastRss(PodcastLocal podcastLocal, {int removeMark = 0}) async { - var options = BaseOptions( + final options = BaseOptions( connectTimeout: 20000, receiveTimeout: 20000, ); + final hideNewMark = await getHideNewMark(podcastLocal.id); try { var response = await Dio(options).get(podcastLocal.rssUrl); if (response.statusCode == 200) { @@ -728,7 +751,7 @@ class DBHelper { await txn.rawInsert( """INSERT OR IGNORE INTO Episodes(title, enclosure_url, enclosure_length, pubDate, description, feed_id, milliseconds, duration, explicit, media_id, chapter_link, - episode_image, is_new) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)""", + episode_image, is_new) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", [ title, url, @@ -741,7 +764,8 @@ class DBHelper { explicit, url, chapter, - image + image, + hideNewMark ? 0 : 1 ]); }); } diff --git a/lib/podcasts/podcast_settings.dart b/lib/podcasts/podcast_settings.dart index c300dd6..53f2039 100644 --- a/lib/podcasts/podcast_settings.dart +++ b/lib/podcasts/podcast_settings.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:image/image.dart' as img; +import 'package:line_icons/line_icons.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; @@ -63,6 +64,11 @@ class _PodcastSettingState extends State { if (mounted) setState(() {}); } + Future _setHideNewMark(bool boo) async { + await _dbHelper.saveHideNewMark(widget.podcastLocal.id, boo: boo); + if (mounted) setState(() {}); + } + Future _saveSkipSecondsStart(int seconds) async { await _dbHelper.saveSkipSecondsStart(widget.podcastLocal.id, seconds); } @@ -79,6 +85,10 @@ class _PodcastSettingState extends State { return await _dbHelper.getNeverUpdate(id); } + Future _getHideNewMark(String id) async { + return await _dbHelper.getHideNewMark(id); + } + Future _getSkipSecondStart(String id) async { return await _dbHelper.getSkipSecondsStart(id); } @@ -249,6 +259,27 @@ class _PodcastSettingState extends State { ), ); }), + FutureBuilder( + future: _getHideNewMark(widget.podcastLocal.id), + initialData: false, + builder: (context, snapshot) { + return ListTile( + dense: true, + onTap: () => _setHideNewMark(!snapshot.data), + title: Row( + children: [ + Icon(LineIcons.eraser, size: 20), + SizedBox(width: 20), + Text('Always hide new mark', style: textStyle), + ], + ), + trailing: Transform.scale( + scale: 0.8, + child: + Switch(value: snapshot.data, onChanged: _setHideNewMark), + ), + ); + }), FutureBuilder( future: _getSkipSecondStart(widget.podcastLocal.id), initialData: 0,