mirror of
https://github.com/stonega/tsacdop
synced 2025-02-10 16:40:44 +01:00
Support auto download.
This commit is contained in:
parent
f4b56938ae
commit
e69a2dbc00
@ -267,7 +267,7 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
|
|||||||
? (_description.contains('<'))
|
? (_description.contains('<'))
|
||||||
? Html(
|
? Html(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 20.0, right: 20, bottom: 10),
|
left: 20.0, right: 20, bottom: 20),
|
||||||
defaultTextStyle:
|
defaultTextStyle:
|
||||||
// GoogleFonts.libreBaskerville(
|
// GoogleFonts.libreBaskerville(
|
||||||
GoogleFonts.martel(
|
GoogleFonts.martel(
|
||||||
@ -290,7 +290,7 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
|
|||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 20.0,
|
left: 20.0,
|
||||||
right: 20.0,
|
right: 20.0,
|
||||||
bottom: 10.0),
|
bottom: 20.0),
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: SelectableLinkify(
|
child: SelectableLinkify(
|
||||||
onOpen: (link) {
|
onOpen: (link) {
|
||||||
@ -390,18 +390,16 @@ class _MenuBarState extends State<MenuBar> {
|
|||||||
return await dbHelper.getPosition(episode);
|
return await dbHelper.getPosition(episode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> saveLiked(String url) async {
|
saveLiked(String url) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
int result = await dbHelper.setLiked(url);
|
await dbHelper.setLiked(url);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> setUnliked(String url) async {
|
setUnliked(String url) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
int result = await dbHelper.setUniked(url);
|
await dbHelper.setUniked(url);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _isLiked(EpisodeBrief episode) async {
|
Future<bool> _isLiked(EpisodeBrief episode) async {
|
||||||
|
@ -7,7 +7,6 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
import 'package:line_icons/line_icons.dart';
|
import 'package:line_icons/line_icons.dart';
|
||||||
import 'package:feature_discovery/feature_discovery.dart';
|
|
||||||
|
|
||||||
import '../type/episodebrief.dart';
|
import '../type/episodebrief.dart';
|
||||||
import '../state/podcast_group.dart';
|
import '../state/podcast_group.dart';
|
||||||
@ -507,16 +506,14 @@ class ShowEpisode extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> _saveLiked(String url) async {
|
_saveLiked(String url) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
int result = await dbHelper.setLiked(url);
|
await dbHelper.setLiked(url);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> _setUnliked(String url) async {
|
_setUnliked(String url) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
int result = await dbHelper.setUniked(url);
|
await dbHelper.setUniked(url);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_showPopupMenu(Offset offset, EpisodeBrief episode, BuildContext context,
|
_showPopupMenu(Offset offset, EpisodeBrief episode, BuildContext context,
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
|
import 'package:connectivity/connectivity.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../local_storage/key_value_storage.dart';
|
||||||
|
import '../local_storage/sqflite_localpodcast.dart';
|
||||||
import '../state/podcast_group.dart';
|
import '../state/podcast_group.dart';
|
||||||
import '../state/subscribe_podcast.dart';
|
import '../state/subscribe_podcast.dart';
|
||||||
|
import '../state/download_state.dart';
|
||||||
import '../state/refresh_podcast.dart';
|
import '../state/refresh_podcast.dart';
|
||||||
|
import '../type/episodebrief.dart';
|
||||||
import '../util/context_extension.dart';
|
import '../util/context_extension.dart';
|
||||||
|
|
||||||
class Import extends StatelessWidget {
|
class Import extends StatelessWidget {
|
||||||
@ -24,6 +30,30 @@ class Import extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_autoDownloadNew(BuildContext context) async {
|
||||||
|
final DBHelper dbHelper = DBHelper();
|
||||||
|
var downloader = Provider.of<DownloadState>(context, listen: false);
|
||||||
|
var result = await Connectivity().checkConnectivity();
|
||||||
|
KeyValueStorage autoDownloadStorage =
|
||||||
|
KeyValueStorage(autoDownloadNetworkKey);
|
||||||
|
int autoDownloadNetwork = await autoDownloadStorage.getInt();
|
||||||
|
if (autoDownloadNetwork == 1) {
|
||||||
|
List<EpisodeBrief> episodes = await dbHelper.getNewEpisodes('all');
|
||||||
|
// For safety
|
||||||
|
if (episodes.length < 100)
|
||||||
|
episodes.forEach((episode) {
|
||||||
|
downloader.startTask(episode, showNotification: false);
|
||||||
|
});
|
||||||
|
} else if (result == ConnectivityResult.wifi) {
|
||||||
|
List<EpisodeBrief> episodes = await dbHelper.getNewEpisodes('all');
|
||||||
|
//For safety
|
||||||
|
if (episodes.length < 100)
|
||||||
|
episodes.forEach((episode) {
|
||||||
|
downloader.startTask(episode, showNotification: false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
GroupList groupList = Provider.of<GroupList>(context, listen: false);
|
GroupList groupList = Provider.of<GroupList>(context, listen: false);
|
||||||
@ -57,7 +87,7 @@ class Import extends StatelessWidget {
|
|||||||
RefreshItem item = refreshWorker.currentRefreshItem;
|
RefreshItem item = refreshWorker.currentRefreshItem;
|
||||||
if (refreshWorker.complete) {
|
if (refreshWorker.complete) {
|
||||||
groupList.updateGroups();
|
groupList.updateGroups();
|
||||||
// audio.addNewEpisode('all');
|
_autoDownloadNew(context);
|
||||||
}
|
}
|
||||||
switch (item.refreshState) {
|
switch (item.refreshState) {
|
||||||
case RefreshState.fetch:
|
case RefreshState.fetch:
|
||||||
|
@ -76,7 +76,7 @@ class _PopupMenuState extends State<PopupMenu> {
|
|||||||
try {
|
try {
|
||||||
String opml = file.readAsStringSync();
|
String opml = file.readAsStringSync();
|
||||||
|
|
||||||
var content = xml.parse(opml);
|
var content = xml.XmlDocument.parse(opml);
|
||||||
var total = content
|
var total = content
|
||||||
.findAllElements('outline')
|
.findAllElements('outline')
|
||||||
.map((ele) => OmplOutline.parse(ele))
|
.map((ele) => OmplOutline.parse(ele))
|
||||||
@ -184,11 +184,6 @@ class _PopupMenuState extends State<PopupMenu> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// PopupMenuItem(
|
|
||||||
// value: 3,
|
|
||||||
// child: setting.theme != 2 ? Text('Night Mode') : Text('Light Mode'),
|
|
||||||
// ),
|
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 4,
|
value: 4,
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -273,8 +273,8 @@ class DBHelper {
|
|||||||
Future<int> isListened(String url) async {
|
Future<int> isListened(String url) async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
List<Map> list =
|
List<Map> list = await dbClient.rawQuery(
|
||||||
await dbClient.rawQuery("SELECT listen_time FROM PlayHistory WHERE enclosure_url = ?", [url]);
|
"SELECT listen_time FROM PlayHistory WHERE enclosure_url = ?", [url]);
|
||||||
if (list.length == 0)
|
if (list.length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
@ -648,7 +648,7 @@ class DBHelper {
|
|||||||
E.milliseconds, P.imagePath, P.title as feed_title, E.duration, E.explicit, E.liked,
|
E.milliseconds, P.imagePath, P.title as feed_title, E.duration, E.explicit, E.liked,
|
||||||
E.downloaded, P.primaryColor, E.media_id, E.is_new, P.skip_seconds
|
E.downloaded, P.primaryColor, E.media_id, E.is_new, P.skip_seconds
|
||||||
FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id
|
FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id
|
||||||
WHERE E.is_new = 1 ORDER BY E.milliseconds ASC""",
|
WHERE E.is_new = 1 AND E.downloaded = 'ND' AND P.auto_download = 1 ORDER BY E.milliseconds ASC""",
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
list = await dbClient.rawQuery(
|
list = await dbClient.rawQuery(
|
||||||
@ -656,7 +656,7 @@ class DBHelper {
|
|||||||
E.milliseconds, P.imagePath, P.title as feed_title, E.duration, E.explicit, E.liked,
|
E.milliseconds, P.imagePath, P.title as feed_title, E.duration, E.explicit, E.liked,
|
||||||
E.downloaded, P.primaryColor, E.media_id, E.is_new, P.skip_seconds
|
E.downloaded, P.primaryColor, E.media_id, E.is_new, P.skip_seconds
|
||||||
FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id
|
FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id
|
||||||
WHERE E.is_new = 1 AND E.feed_id = ? ORDER BY E.milliseconds ASC""",
|
WHERE E.is_new = 1 AND E.downloaded = 'ND' AND E.feed_id = ? ORDER BY E.milliseconds ASC""",
|
||||||
[id]);
|
[id]);
|
||||||
if (list.length > 0)
|
if (list.length > 0)
|
||||||
for (int x = 0; x < list.length; x++) {
|
for (int x = 0; x < list.length; x++) {
|
||||||
@ -961,9 +961,11 @@ class DBHelper {
|
|||||||
return episodes;
|
return episodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> removeAllNewMark() async {
|
removeAllNewMark() async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
return await dbClient.rawUpdate("UPDATE Episodes SET is_new = 0 ");
|
await dbClient.transaction((txn) async {
|
||||||
|
await txn.rawUpdate("UPDATE Episodes SET is_new = 0 ");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<EpisodeBrief>> getGroupNewRssItem(List<String> group) async {
|
Future<List<EpisodeBrief>> getGroupNewRssItem(List<String> group) async {
|
||||||
@ -1000,20 +1002,23 @@ class DBHelper {
|
|||||||
return episodes;
|
return episodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> removeGroupNewMark(List<String> group) async {
|
removeGroupNewMark(List<String> group) async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
if (group.length > 0) {
|
if (group.length > 0) {
|
||||||
List<String> s = group.map<String>((e) => "'$e'").toList();
|
List<String> s = group.map<String>((e) => "'$e'").toList();
|
||||||
return await dbClient.rawUpdate(
|
await dbClient.transaction((txn) async {
|
||||||
|
await txn.rawUpdate(
|
||||||
"UPDATE Episodes SET is_new = 0 WHERE feed_id in (${s.join(',')})");
|
"UPDATE Episodes SET is_new = 0 WHERE feed_id in (${s.join(',')})");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> removeEpisodeNewMark(String url) async {
|
removeEpisodeNewMark(String url) async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
return await dbClient.rawUpdate(
|
await dbClient.transaction((txn) async {
|
||||||
|
await txn.rawUpdate(
|
||||||
"UPDATE Episodes SET is_new = 0 WHERE enclosure_url = ?", [url]);
|
"UPDATE Episodes SET is_new = 0 WHERE enclosure_url = ?", [url]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<EpisodeBrief>> getLikedRssItem(int i, int sortBy) async {
|
Future<List<EpisodeBrief>> getLikedRssItem(int i, int sortBy) async {
|
||||||
@ -1069,20 +1074,22 @@ class DBHelper {
|
|||||||
return episodes;
|
return episodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> setLiked(String url) async {
|
setLiked(String url) async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
int milliseconds = DateTime.now().millisecondsSinceEpoch;
|
int milliseconds = DateTime.now().millisecondsSinceEpoch;
|
||||||
int count = await dbClient.rawUpdate(
|
await dbClient.transaction((txn) async {
|
||||||
|
await txn.rawUpdate(
|
||||||
"UPDATE Episodes SET liked = 1, liked_date = ? WHERE enclosure_url= ?",
|
"UPDATE Episodes SET liked = 1, liked_date = ? WHERE enclosure_url= ?",
|
||||||
[milliseconds, url]);
|
[milliseconds, url]);
|
||||||
return count;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> setUniked(String url) async {
|
setUniked(String url) async {
|
||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
int count = await dbClient.rawUpdate(
|
await dbClient.transaction((txn) async {
|
||||||
|
await txn.rawUpdate(
|
||||||
"UPDATE Episodes SET liked = 0 WHERE enclosure_url = ?", [url]);
|
"UPDATE Episodes SET liked = 0 WHERE enclosure_url = ?", [url]);
|
||||||
return count;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isLiked(String url) async {
|
Future<bool> isLiked(String url) async {
|
||||||
|
@ -46,7 +46,6 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
bool _scroll;
|
bool _scroll;
|
||||||
Future _updateRssItem(PodcastLocal podcastLocal) async {
|
Future _updateRssItem(PodcastLocal podcastLocal) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
|
|
||||||
final result = await dbHelper.updatePodcastRss(podcastLocal);
|
final result = await dbHelper.updatePodcastRss(podcastLocal);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
@ -58,8 +57,10 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
msg: 'Updated $result Episodes',
|
msg: 'Updated $result Episodes',
|
||||||
gravity: ToastGravity.TOP,
|
gravity: ToastGravity.TOP,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool autoDownload = await dbHelper.getAutoDownload(podcastLocal.id);
|
bool autoDownload = await dbHelper.getAutoDownload(podcastLocal.id);
|
||||||
if (autoDownload) {
|
if (autoDownload) {
|
||||||
|
var downloader = Provider.of<DownloadState>(context, listen: false);
|
||||||
var result = await Connectivity().checkConnectivity();
|
var result = await Connectivity().checkConnectivity();
|
||||||
KeyValueStorage autoDownloadStorage =
|
KeyValueStorage autoDownloadStorage =
|
||||||
KeyValueStorage(autoDownloadNetworkKey);
|
KeyValueStorage(autoDownloadNetworkKey);
|
||||||
@ -67,19 +68,21 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
if (autoDownloadNetwork == 1) {
|
if (autoDownloadNetwork == 1) {
|
||||||
List<EpisodeBrief> episodes =
|
List<EpisodeBrief> episodes =
|
||||||
await dbHelper.getNewEpisodes(podcastLocal.id);
|
await dbHelper.getNewEpisodes(podcastLocal.id);
|
||||||
|
// For safety
|
||||||
|
if (episodes.length < 100)
|
||||||
episodes.forEach((episode) {
|
episodes.forEach((episode) {
|
||||||
DownloadState().startTask(episode, showNotification: false);
|
downloader.startTask(episode, showNotification: false);
|
||||||
});
|
});
|
||||||
} else if (result == ConnectivityResult.wifi) {
|
} else if (result == ConnectivityResult.wifi) {
|
||||||
List<EpisodeBrief> episodes =
|
List<EpisodeBrief> episodes =
|
||||||
await dbHelper.getNewEpisodes(podcastLocal.id);
|
await dbHelper.getNewEpisodes(podcastLocal.id);
|
||||||
|
//For safety
|
||||||
|
if (episodes.length < 100)
|
||||||
episodes.forEach((episode) {
|
episodes.forEach((episode) {
|
||||||
DownloadState().startTask(episode, showNotification: false);
|
downloader.startTask(episode, showNotification: false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Provider.of<GroupList>(context, listen: false)
|
|
||||||
// .updatePodcast(podcastLocal.id);
|
|
||||||
} else {
|
} else {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: 'Update failed, network error',
|
msg: 'Update failed, network error',
|
||||||
|
@ -361,7 +361,7 @@ class _PodcastCardState extends State<PodcastCard>
|
|||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return _buttonOnMenu(
|
return _buttonOnMenu(
|
||||||
icon: Container(
|
icon: Container(
|
||||||
child: Icon(Icons.done_all,
|
child: Icon(Icons.file_download,
|
||||||
size: _value * 15,
|
size: _value * 15,
|
||||||
color: snapshot.data
|
color: snapshot.data
|
||||||
? Colors.white
|
? Colors.white
|
||||||
@ -369,20 +369,23 @@ class _PodcastCardState extends State<PodcastCard>
|
|||||||
height: _value == 0 ? 1 : 18 * _value,
|
height: _value == 0 ? 1 : 18 * _value,
|
||||||
width: _value == 0 ? 1 : 18 * _value,
|
width: _value == 0 ? 1 : 18 * _value,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(
|
border: snapshot.data
|
||||||
|
? Border.all(
|
||||||
width: 1,
|
width: 1,
|
||||||
color: snapshot.data
|
color: snapshot.data
|
||||||
? context.accentColor
|
? context.accentColor
|
||||||
: context.textTheme.subtitle1
|
: context.textTheme
|
||||||
.color),
|
.subtitle1.color)
|
||||||
|
: null,
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: snapshot.data
|
color: snapshot.data
|
||||||
? context.accentColor
|
? context.accentColor
|
||||||
: null),
|
: null),
|
||||||
),
|
),
|
||||||
tooltip: 'Auto Download',
|
tooltip: 'Auto Download',
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
_setAutoDownload(widget.podcastLocal.id,
|
await _setAutoDownload(
|
||||||
|
widget.podcastLocal.id,
|
||||||
!snapshot.data);
|
!snapshot.data);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
|
@ -2,7 +2,6 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:line_icons/line_icons.dart';
|
import 'package:line_icons/line_icons.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
@ -498,7 +498,6 @@ class HistoryChart extends StatelessWidget {
|
|||||||
]),
|
]),
|
||||||
dotData: FlDotData(
|
dotData: FlDotData(
|
||||||
show: true,
|
show: true,
|
||||||
dotSize: 5,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -449,7 +449,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
|
|||||||
newEpisodes = await dbHelper.getRecentNewRssItem();
|
newEpisodes = await dbHelper.getRecentNewRssItem();
|
||||||
else
|
else
|
||||||
newEpisodes = await dbHelper.getGroupNewRssItem(group);
|
newEpisodes = await dbHelper.getGroupNewRssItem(group);
|
||||||
if (newEpisodes.length > 0)
|
if (newEpisodes.length > 0 && newEpisodes.length < 100)
|
||||||
await Future.forEach(newEpisodes, (episode) async {
|
await Future.forEach(newEpisodes, (episode) async {
|
||||||
await addToPlaylist(episode);
|
await addToPlaylist(episode);
|
||||||
});
|
});
|
||||||
|
@ -80,8 +80,7 @@ class PodcastGroup {
|
|||||||
class GroupList extends ChangeNotifier {
|
class GroupList extends ChangeNotifier {
|
||||||
List<PodcastGroup> _groups;
|
List<PodcastGroup> _groups;
|
||||||
DBHelper dbHelper = DBHelper();
|
DBHelper dbHelper = DBHelper();
|
||||||
UnmodifiableListView<PodcastGroup> get groups =>
|
List<PodcastGroup> get groups => _groups;
|
||||||
UnmodifiableListView(_groups);
|
|
||||||
|
|
||||||
KeyValueStorage storage = KeyValueStorage('groups');
|
KeyValueStorage storage = KeyValueStorage('groups');
|
||||||
GroupList({List<PodcastGroup> groups}) : _groups = groups ?? [];
|
GroupList({List<PodcastGroup> groups}) : _groups = groups ?? [];
|
||||||
@ -112,10 +111,18 @@ class GroupList extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_initGroup() async {
|
||||||
|
storage.getGroups().then((loadgroups) async {
|
||||||
|
_groups.addAll(loadgroups.map((e) => PodcastGroup.fromEntity(e)));
|
||||||
|
await Future.forEach(_groups, (group) async {
|
||||||
|
await group.getPodcasts();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addListener(VoidCallback listener) {
|
void addListener(VoidCallback listener) {
|
||||||
super.addListener(listener);
|
loadGroups().then((value) => super.addListener(listener));
|
||||||
loadGroups();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future loadGroups() async {
|
Future loadGroups() async {
|
||||||
@ -142,7 +149,7 @@ class GroupList extends ChangeNotifier {
|
|||||||
Future addGroup(PodcastGroup podcastGroup) async {
|
Future addGroup(PodcastGroup podcastGroup) async {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
_groups.add(podcastGroup);
|
_groups.add(podcastGroup);
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
@ -154,7 +161,7 @@ class GroupList extends ChangeNotifier {
|
|||||||
_groups[0].podcastList.insert(0, podcast);
|
_groups[0].podcastList.insert(0, podcast);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
_groups.remove(podcastGroup);
|
_groups.remove(podcastGroup);
|
||||||
await _groups[0].getPodcasts();
|
await _groups[0].getPodcasts();
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
@ -170,13 +177,13 @@ class GroupList extends ChangeNotifier {
|
|||||||
_saveGroup();
|
_saveGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveGroup() {
|
_saveGroup() async {
|
||||||
storage.saveGroup(_groups.map((it) => it.toEntity()).toList());
|
await storage.saveGroup(_groups.map((it) => it.toEntity()).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future subscribe(PodcastLocal podcastLocal) async {
|
Future subscribe(PodcastLocal podcastLocal) async {
|
||||||
_groups[0].podcastList.insert(0, podcastLocal.id);
|
_groups[0].podcastList.insert(0, podcastLocal.id);
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
await dbHelper.savePodcastLocal(podcastLocal);
|
await dbHelper.savePodcastLocal(podcastLocal);
|
||||||
await _groups[0].getPodcasts();
|
await _groups[0].getPodcasts();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -194,8 +201,9 @@ class GroupList extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future subscribeNewPodcast(String id) async {
|
Future subscribeNewPodcast(String id) async {
|
||||||
|
if (!_groups[0].podcastList.contains(id))
|
||||||
_groups[0].podcastList.insert(0, id);
|
_groups[0].podcastList.insert(0, id);
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
await _groups[0].getPodcasts();
|
await _groups[0].getPodcasts();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
@ -224,7 +232,7 @@ class GroupList extends ChangeNotifier {
|
|||||||
list.forEach((s) {
|
list.forEach((s) {
|
||||||
s.podcastList.insert(0, id);
|
s.podcastList.insert(0, id);
|
||||||
});
|
});
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
await Future.forEach(_groups, (group) async {
|
await Future.forEach(_groups, (group) async {
|
||||||
await group.getPodcasts();
|
await group.getPodcasts();
|
||||||
});
|
});
|
||||||
@ -239,7 +247,7 @@ class GroupList extends ChangeNotifier {
|
|||||||
_groups.forEach((group) async {
|
_groups.forEach((group) async {
|
||||||
group.podcastList.remove(id);
|
group.podcastList.remove(id);
|
||||||
});
|
});
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
await dbHelper.delPodcastLocal(id);
|
await dbHelper.delPodcastLocal(id);
|
||||||
await Future.forEach(_groups, (group) async {
|
await Future.forEach(_groups, (group) async {
|
||||||
await group.getPodcasts();
|
await group.getPodcasts();
|
||||||
@ -250,7 +258,7 @@ class GroupList extends ChangeNotifier {
|
|||||||
|
|
||||||
saveOrder(PodcastGroup group) async {
|
saveOrder(PodcastGroup group) async {
|
||||||
group.podcastList = group.ordereddPodcasts.map((e) => e.id).toList();
|
group.podcastList = group.ordereddPodcasts.map((e) => e.id).toList();
|
||||||
_saveGroup();
|
await _saveGroup();
|
||||||
await group.getPodcasts();
|
await group.getPodcasts();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,10 @@ import 'dart:isolate';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_isolate/flutter_isolate.dart';
|
import 'package:flutter_isolate/flutter_isolate.dart';
|
||||||
import 'package:connectivity/connectivity.dart';
|
|
||||||
|
|
||||||
import '../local_storage/key_value_storage.dart';
|
import '../local_storage/key_value_storage.dart';
|
||||||
import '../local_storage/sqflite_localpodcast.dart';
|
import '../local_storage/sqflite_localpodcast.dart';
|
||||||
import '../type/podcastlocal.dart';
|
import '../type/podcastlocal.dart';
|
||||||
import '../type/episodebrief.dart';
|
|
||||||
import 'download_state.dart';
|
|
||||||
|
|
||||||
enum RefreshState { none, fetch, error }
|
enum RefreshState { none, fetch, error }
|
||||||
|
|
||||||
@ -71,33 +68,13 @@ class RefreshWorker extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> refreshIsolateEntryPoint(SendPort sendPort) async {
|
Future<void> refreshIsolateEntryPoint(SendPort sendPort) async {
|
||||||
KeyValueStorage refreshstorage = KeyValueStorage(refreshdateKey);
|
KeyValueStorage refreshstorage = KeyValueStorage(refreshdateKey);
|
||||||
KeyValueStorage autoDownloadStorage = KeyValueStorage(autoDownloadNetworkKey);
|
|
||||||
await refreshstorage.saveInt(DateTime.now().millisecondsSinceEpoch);
|
await refreshstorage.saveInt(DateTime.now().millisecondsSinceEpoch);
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
List<PodcastLocal> podcastList = await dbHelper.getPodcastLocalAll();
|
List<PodcastLocal> podcastList = await dbHelper.getPodcastLocalAll();
|
||||||
//int i = 0;
|
|
||||||
await Future.forEach<PodcastLocal>(podcastList, (podcastLocal) async {
|
await Future.forEach<PodcastLocal>(podcastList, (podcastLocal) async {
|
||||||
sendPort.send([podcastLocal.title, 1]);
|
sendPort.send([podcastLocal.title, 1]);
|
||||||
int updateCount = await dbHelper.updatePodcastRss(podcastLocal);
|
int updateCount = await dbHelper.updatePodcastRss(podcastLocal);
|
||||||
bool autoDownload = await dbHelper.getAutoDownload(podcastLocal.id);
|
print('Refresh ' + podcastLocal.title + updateCount.toString());
|
||||||
if (autoDownload && updateCount > 0) {
|
|
||||||
var result = await Connectivity().checkConnectivity();
|
|
||||||
int autoDownloadNetwork = await autoDownloadStorage.getInt();
|
|
||||||
if (autoDownloadNetwork == 1) {
|
|
||||||
List<EpisodeBrief> episodes =
|
|
||||||
await dbHelper.getNewEpisodes(podcastLocal.id);
|
|
||||||
episodes.forEach((episode) {
|
|
||||||
DownloadState().startTask(episode, showNotification: false);
|
|
||||||
});
|
|
||||||
} else if (result == ConnectivityResult.wifi) {
|
|
||||||
List<EpisodeBrief> episodes =
|
|
||||||
await dbHelper.getNewEpisodes(podcastLocal.id);
|
|
||||||
episodes.forEach((episode) {
|
|
||||||
DownloadState().startTask(episode, showNotification: false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print('Refresh ' + podcastLocal.title);
|
|
||||||
});
|
});
|
||||||
// KeyValueStorage refreshcountstorage = KeyValueStorage('refreshcount');
|
// KeyValueStorage refreshcountstorage = KeyValueStorage('refreshcount');
|
||||||
// await refreshcountstorage.saveInt(i);
|
// await refreshcountstorage.saveInt(i);
|
||||||
|
@ -32,13 +32,13 @@ void callbackDispatcher() {
|
|||||||
List<EpisodeBrief> episodes =
|
List<EpisodeBrief> episodes =
|
||||||
await dbHelper.getNewEpisodes(podcastLocal.id);
|
await dbHelper.getNewEpisodes(podcastLocal.id);
|
||||||
episodes.forEach((episode) {
|
episodes.forEach((episode) {
|
||||||
DownloadState().startTask(episode, showNotification: false);
|
DownloadState().startTask(episode, showNotification: true);
|
||||||
});
|
});
|
||||||
} else if (result == ConnectivityResult.wifi) {
|
} else if (result == ConnectivityResult.wifi) {
|
||||||
List<EpisodeBrief> episodes =
|
List<EpisodeBrief> episodes =
|
||||||
await dbHelper.getNewEpisodes(podcastLocal.id);
|
await dbHelper.getNewEpisodes(podcastLocal.id);
|
||||||
episodes.forEach((episode) {
|
episodes.forEach((episode) {
|
||||||
DownloadState().startTask(episode, showNotification: false);
|
DownloadState().startTask(episode, showNotification: true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ class SubscribeWorker extends ChangeNotifier {
|
|||||||
_setCurrentSubscribeItem(SubscribeItem(message[1], message[0],
|
_setCurrentSubscribeItem(SubscribeItem(message[1], message[0],
|
||||||
subscribeState: SubscribeState.values[message[2]],
|
subscribeState: SubscribeState.values[message[2]],
|
||||||
id: message.length == 4 ? message[3] : ''));
|
id: message.length == 4 ? message[3] : ''));
|
||||||
print(message[2]);
|
|
||||||
} else if (message is String && message == "done") {
|
} else if (message is String && message == "done") {
|
||||||
subIsolate.kill();
|
subIsolate.kill();
|
||||||
subIsolate = null;
|
subIsolate = null;
|
||||||
|
@ -74,16 +74,14 @@ class EpisodeGrid extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> _saveLiked(String url) async {
|
_saveLiked(String url) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
int result = await dbHelper.setLiked(url);
|
await dbHelper.setLiked(url);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> _setUnliked(String url) async {
|
_setUnliked(String url) async {
|
||||||
var dbHelper = DBHelper();
|
var dbHelper = DBHelper();
|
||||||
int result = await dbHelper.setUniked(url);
|
await dbHelper.setUniked(url);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String _stringForSeconds(double seconds) {
|
String _stringForSeconds(double seconds) {
|
||||||
@ -116,9 +114,9 @@ class EpisodeGrid extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _listenIndicater(BuildContext context,
|
//Widget _listenIndicater(BuildContext context,
|
||||||
{EpisodeBrief episode, int isListened}) =>
|
// {EpisodeBrief episode, int isListened}) =>
|
||||||
Center();
|
// Center();
|
||||||
// Selector<AudioPlayerNotifier, Tuple2<EpisodeBrief, bool>>(
|
// Selector<AudioPlayerNotifier, Tuple2<EpisodeBrief, bool>>(
|
||||||
// selector: (_, audio) => Tuple2(audio.episode, audio.playerRunning),
|
// selector: (_, audio) => Tuple2(audio.episode, audio.playerRunning),
|
||||||
// builder: (_, data, __) {
|
// builder: (_, data, __) {
|
||||||
|
@ -39,7 +39,7 @@ class AtomFeed {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory AtomFeed.parse(String xmlString) {
|
factory AtomFeed.parse(String xmlString) {
|
||||||
var document = parse(xmlString);
|
var document = XmlDocument.parse(xmlString);
|
||||||
XmlElement feedElement;
|
XmlElement feedElement;
|
||||||
try {
|
try {
|
||||||
feedElement = document.findElements("feed").first;
|
feedElement = document.findElements("feed").first;
|
||||||
|
@ -59,7 +59,7 @@ class RssFeed {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory RssFeed.parse(String xmlString) {
|
factory RssFeed.parse(String xmlString) {
|
||||||
var document = parse(xmlString);
|
var document = XmlDocument.parse(xmlString);
|
||||||
XmlElement channelElement;
|
XmlElement channelElement;
|
||||||
try {
|
try {
|
||||||
channelElement = document.findAllElements("channel").first;
|
channelElement = document.findAllElements("channel").first;
|
||||||
|
@ -33,7 +33,7 @@ dependencies:
|
|||||||
tuple: ^1.0.3
|
tuple: ^1.0.3
|
||||||
cached_network_image: ^2.2.0+1
|
cached_network_image: ^2.2.0+1
|
||||||
workmanager: ^0.2.2
|
workmanager: ^0.2.2
|
||||||
fl_chart: ^0.9.4
|
fl_chart: ^0.10.0
|
||||||
audio_service: ^0.8.0
|
audio_service: ^0.8.0
|
||||||
flutter_file_dialog: ^0.0.5
|
flutter_file_dialog: ^0.0.5
|
||||||
flutter_linkify: ^3.1.3
|
flutter_linkify: ^3.1.3
|
||||||
@ -57,8 +57,8 @@ dev_dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
flutter_isolate: "1.0.0+13"
|
flutter_isolate: "1.0.0+14"
|
||||||
xml: "4.1.0"
|
xml: "4.2.0"
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
assets:
|
assets:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user