Minor change.

This commit is contained in:
stonegate 2020-08-14 20:13:10 +08:00
parent e17ed8a81f
commit 5c01a9c83c
10 changed files with 89 additions and 69 deletions

View File

@ -6,6 +6,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../state/podcast_group.dart';
const String groupsKey = 'groups';
const String playlistKey = 'playlist';
const String autoPlayKey = 'autoPlay';
const String audioPositionKey = 'audioposition';
const String lastWorkKey = 'lastWork';

View File

@ -41,7 +41,7 @@ class _PodcastGroupListState extends State<PodcastGroupList> {
final podcast = widget.group.podcasts.removeAt(oldIndex);
widget.group.podcasts.insert(newIndex, podcast);
});
widget.group.setOrderedPodcasts = widget.group.podcasts;
widget.group.orderedPodcasts = widget.group.podcasts;
groupList.addToOrderChanged(widget.group);
},
children: widget.group.podcasts.map<Widget>((podcastLocal) {
@ -49,7 +49,7 @@ class _PodcastGroupListState extends State<PodcastGroupList> {
decoration:
BoxDecoration(color: Theme.of(context).primaryColor),
key: ObjectKey(podcastLocal.title),
child: PodcastCard(
child: _PodcastCard(
podcastLocal: podcastLocal,
group: widget.group,
),
@ -60,15 +60,15 @@ class _PodcastGroupListState extends State<PodcastGroupList> {
}
}
class PodcastCard extends StatefulWidget {
class _PodcastCard extends StatefulWidget {
final PodcastLocal podcastLocal;
final PodcastGroup group;
PodcastCard({this.podcastLocal, this.group, Key key}) : super(key: key);
_PodcastCard({this.podcastLocal, this.group, Key key}) : super(key: key);
@override
_PodcastCardState createState() => _PodcastCardState();
__PodcastCardState createState() => __PodcastCardState();
}
class _PodcastCardState extends State<PodcastCard>
class __PodcastCardState extends State<_PodcastCard>
with SingleTickerProviderStateMixin {
bool _loadMenu;
bool _addGroup;
@ -161,11 +161,11 @@ class _PodcastCardState extends State<PodcastCard>
@override
Widget build(BuildContext context) {
var _c = (Theme.of(context).brightness == Brightness.light)
final c = (Theme.of(context).brightness == Brightness.light)
? widget.podcastLocal.primaryColor.colorizedark()
: widget.podcastLocal.primaryColor.colorizeLight();
final s = context.s;
var _width = MediaQuery.of(context).size.width;
var width = context.width;
var groupList = context.watch<GroupList>();
_belongGroups = groupList.getPodcastGroup(widget.podcastLocal.id);
@ -199,7 +199,7 @@ class _PodcastCardState extends State<PodcastCard>
Container(
child: Icon(
Icons.unfold_more,
color: _c,
color: c,
),
),
Container(
@ -214,7 +214,7 @@ class _PodcastCardState extends State<PodcastCard>
),
),
Container(
width: _width / 2,
width: width / 2,
padding: EdgeInsets.symmetric(horizontal: 10),
alignment: Alignment.centerLeft,
child: Column(

View File

@ -551,6 +551,10 @@ class AudioPlayerNotifier extends ChangeNotifier {
await AudioService.removeQueueItem(episodeNew.toMediaItem());
}
var index = await _queue.delFromPlaylist(episodeNew);
if (index == 0) {
_lastPostion = 0;
await positionStorage.saveInt(0);
}
_queueUpdate = !_queueUpdate;
notifyListeners();
return index;

View File

@ -13,6 +13,7 @@ import 'package:image/image.dart' as img;
import 'package:path_provider/path_provider.dart';
import 'package:webfeed/webfeed.dart';
import 'package:uuid/uuid.dart';
import 'package:equatable/equatable.dart';
import '../local_storage/key_value_storage.dart';
import '../local_storage/sqflite_localpodcast.dart';
@ -38,7 +39,7 @@ class GroupEntity {
}
}
class PodcastGroup {
class PodcastGroup extends Equatable {
/// Group name.
final String name;
@ -48,22 +49,28 @@ class PodcastGroup {
final String color;
/// Id lists of podcasts in group.
List<String> podcastList;
List<String> _podcastList;
List<String> get podcastList => _podcastList;
set podcastList(list) {
_podcastList = list;
}
PodcastGroup(this.name,
{this.color = '#000000', String id, List<String> podcastList})
: id = id ?? Uuid().v4(),
podcastList = podcastList ?? [];
_podcastList = podcastList ?? [];
Future getPodcasts() async {
Future<void> getPodcasts() async {
var dbHelper = DBHelper();
if (podcastList != []) {
if (_podcastList != []) {
try {
_podcasts = await dbHelper.getPodcastLocal(podcastList);
_podcasts = await dbHelper.getPodcastLocal(_podcastList);
} catch (e) {
await Future.delayed(Duration(milliseconds: 200));
try {
_podcasts = await dbHelper.getPodcastLocal(podcastList);
_podcasts = await dbHelper.getPodcastLocal(_podcastList);
} catch (e) {
developer.log(e.toString());
}
@ -86,9 +93,9 @@ class PodcastGroup {
///Ordered podcast list.
List<PodcastLocal> _orderedPodcasts;
List<PodcastLocal> get ordereddPodcasts => _orderedPodcasts;
List<PodcastLocal> get orderedPodcasts => _orderedPodcasts;
set setOrderedPodcasts(List<PodcastLocal> list) => _orderedPodcasts = list;
set orderedPodcasts(list) => _orderedPodcasts = list;
GroupEntity toEntity() {
return GroupEntity(name, id, color, podcastList);
@ -102,6 +109,9 @@ class PodcastGroup {
podcastList: entity.podcastList,
);
}
@override
List<Object> get props => [id, name];
}
enum SubscribeState { none, start, subscribe, fetch, stop, exist, error }
@ -136,10 +146,10 @@ class GroupList extends ChangeNotifier {
final List<PodcastGroup> _groups = [];
List<PodcastGroup> get groups => _groups;
DBHelper dbHelper = DBHelper();
final DBHelper _dbHelper = DBHelper();
/// Groups save in shared_prefrences.
KeyValueStorage storage = KeyValueStorage('groups');
final KeyValueStorage _groupStorage = KeyValueStorage(groupsKey);
//GroupList({List<PodcastGroup> groups}) : _groups = groups ?? [];
@ -238,7 +248,7 @@ class GroupList extends ChangeNotifier {
notifyListeners();
}
clearOrderChanged() async {
Future<void> clearOrderChanged() async {
if (_orderChanged.length > 0) {
for (var group in _orderChanged) {
await group.getPodcasts();
@ -264,7 +274,7 @@ class GroupList extends ChangeNotifier {
Future loadGroups() async {
_isLoading = true;
notifyListeners();
storage.getGroups().then((loadgroups) async {
_groupStorage.getGroups().then((loadgroups) async {
_groups.addAll(loadgroups.map(PodcastGroup.fromEntity));
for (var group in _groups) {
await group.getPodcasts();
@ -306,7 +316,7 @@ class GroupList extends ChangeNotifier {
notifyListeners();
}
updateGroup(PodcastGroup podcastGroup) async {
Future<void> updateGroup(PodcastGroup podcastGroup) async {
var oldGroup = _groups.firstWhere((it) => it.id == podcastGroup.id);
var index = _groups.indexOf(oldGroup);
_groups.replaceRange(index, index + 1, [podcastGroup]);
@ -315,21 +325,21 @@ class GroupList extends ChangeNotifier {
_saveGroup();
}
_saveGroup() async {
await storage.saveGroup(_groups.map((it) => it.toEntity()).toList());
Future<void> _saveGroup() async {
await _groupStorage.saveGroup(_groups.map((it) => it.toEntity()).toList());
}
/// Subscribe podcast from search result.
Future subscribe(PodcastLocal podcastLocal) async {
_groups[0].podcastList.insert(0, podcastLocal.id);
await _saveGroup();
await dbHelper.savePodcastLocal(podcastLocal);
await _dbHelper.savePodcastLocal(podcastLocal);
await _groups[0].getPodcasts();
notifyListeners();
}
Future updatePodcast(String id) async {
var counts = await dbHelper.getPodcastCounts(id);
var counts = await _dbHelper.getPodcastCounts(id);
for (var group in _groups) {
if (group.podcastList.contains(id)) {
group.podcasts.firstWhere((podcast) => podcast.id == id)
@ -381,7 +391,7 @@ class GroupList extends ChangeNotifier {
}
//Change podcast groups
changeGroup(String id, List<PodcastGroup> list) async {
Future<void> changeGroup(String id, List<PodcastGroup> list) async {
_isLoading = true;
notifyListeners();
@ -404,14 +414,14 @@ class GroupList extends ChangeNotifier {
}
/// Unsubscribe podcast
removePodcast(String id) async {
Future<void> removePodcast(String id) async {
_isLoading = true;
notifyListeners();
for (var group in _groups) {
group.podcastList.remove(id);
}
await _saveGroup();
await dbHelper.delPodcastLocal(id);
await _dbHelper.delPodcastLocal(id);
for (var group in _groups) {
await group.getPodcasts();
}
@ -420,7 +430,7 @@ class GroupList extends ChangeNotifier {
}
saveOrder(PodcastGroup group) async {
group.podcastList = group.ordereddPodcasts.map((e) => e.id).toList();
group.podcastList = group.orderedPodcasts.map((e) => e.id).toList();
await _saveGroup();
await group.getPodcasts();
notifyListeners();

View File

@ -1,8 +1,8 @@
import 'dart:ui';
import 'package:equatable/equatable.dart';
import 'package:audio_service/audio_service.dart';
class EpisodeBrief {
class EpisodeBrief extends Equatable {
final String title;
final String description;
final int pubDate;
@ -50,11 +50,5 @@ class EpisodeBrief {
}
@override
bool operator ==(Object episode) =>
episode is EpisodeBrief &&
episode.title == title &&
episode.enclosureUrl == enclosureUrl;
@override
int get hashCode => hashValues(enclosureUrl, title);
List<Object> get props => [enclosureUrl, title];
}

View File

@ -15,7 +15,7 @@ class FiresideData {
List<PodcastHost> get hosts => _hosts;
FiresideData(this.id, this.link);
DBHelper dbHelper = DBHelper();
final DBHelper _dbHelper = DBHelper();
String parseLink(String link) {
if (link == "http://www.shengfm.cn/") {
@ -26,7 +26,12 @@ class FiresideData {
}
Future fatchData() async {
var response = await Dio().get(parseLink(link));
var options = BaseOptions(
connectTimeout: 20000,
receiveTimeout: 20000,
);
var response = await Dio(options).get(parseLink(link));
if (response.statusCode == 200) {
var doc = parse(response.data);
var reg = RegExp(r'https(.+)jpg');
@ -54,12 +59,12 @@ class FiresideData {
backgroundImage,
json.encode({'hosts': hosts.map((host) => host.toJson()).toList()})
];
await dbHelper.saveFiresideData(data);
await _dbHelper.saveFiresideData(data);
}
}
Future getData() async {
var data = await dbHelper.getFiresideData(id);
var data = await _dbHelper.getFiresideData(id);
_background = data[0];
if (data[1] != '') {
_hosts = json

View File

@ -2,7 +2,7 @@ import '../local_storage/sqflite_localpodcast.dart';
import 'episodebrief.dart';
class PlayHistory {
DBHelper dbHelper = DBHelper();
final DBHelper _dbHelper = DBHelper();
/// Episdoe title.
String title;
@ -26,6 +26,6 @@ class PlayHistory {
EpisodeBrief get episode => _episode;
getEpisode() async {
_episode = await dbHelper.getRssItemWithUrl(url);
_episode = await _dbHelper.getRssItemWithUrl(url);
}
}

View File

@ -4,28 +4,28 @@ import 'episodebrief.dart';
class Playlist {
String name;
DBHelper dbHelper = DBHelper();
final DBHelper _dbHelper = DBHelper();
List<EpisodeBrief> _playlist;
List<EpisodeBrief> get playlist => _playlist;
KeyValueStorage storage = KeyValueStorage('playlist');
final KeyValueStorage _playlistStorage = KeyValueStorage(playlistKey);
getPlaylist() async {
var urls = await storage.getStringList();
Future<void> getPlaylist() async {
var urls = await _playlistStorage.getStringList();
if (urls.length == 0) {
_playlist = [];
} else {
_playlist = [];
for (var url in urls) {
var episode = await dbHelper.getRssItemWithUrl(url);
var episode = await _dbHelper.getRssItemWithUrl(url);
if (episode != null) _playlist.add(episode);
}
}
}
savePlaylist() async {
Future<void> savePlaylist() async {
var urls = <String>[];
urls.addAll(_playlist.map((e) => e.enclosureUrl));
await storage.saveStringList(urls.toSet().toList());
await _playlistStorage.saveStringList(urls.toSet().toList());
}
Future<void> addToPlayList(EpisodeBrief episodeBrief) async {
@ -33,7 +33,7 @@ class Playlist {
_playlist.add(episodeBrief);
await savePlaylist();
if (episodeBrief.isNew == 1) {
await dbHelper.removeEpisodeNewMark(episodeBrief.enclosureUrl);
await _dbHelper.removeEpisodeNewMark(episodeBrief.enclosureUrl);
}
}
}
@ -44,7 +44,7 @@ class Playlist {
_playlist.removeWhere(
(episode) => episode.enclosureUrl == episodeBrief.enclosureUrl);
if (episodeBrief.isNew == 1) {
await dbHelper.removeEpisodeNewMark(episodeBrief.enclosureUrl);
await _dbHelper.removeEpisodeNewMark(episodeBrief.enclosureUrl);
}
}
_playlist.insert(index, episodeBrief);

View File

@ -1,6 +1,6 @@
import 'dart:ui';
import 'package:equatable/equatable.dart';
class PodcastLocal {
class PodcastLocal extends Equatable {
final String title;
final String imageUrl;
final String rssUrl;
@ -13,18 +13,22 @@ class PodcastLocal {
final String link;
final String description;
int upateCount;
int episodeCount;
int _upateCount;
int get updateCount => _upateCount;
set updateCount(i) => _upateCount = i;
int _episodeCount;
int get episodeCount => _episodeCount;
set episodeCount(i) => _episodeCount = i;
PodcastLocal(this.title, this.imageUrl, this.rssUrl, this.primaryColor,
this.author, this.id, this.imagePath, this.provider, this.link,
{this.description = '', this.upateCount = 0, this.episodeCount = 0})
: assert(rssUrl != null);
@override
bool operator ==(Object podcastLocal) =>
podcastLocal is PodcastLocal &&
podcastLocal.rssUrl == rssUrl &&
podcastLocal.id == id;
{this.description = '', int upateCount, int episodeCount})
: assert(rssUrl != null),
_episodeCount = episodeCount ?? 0,
_upateCount = upateCount ?? 0;
@override
int get hashCode => hashValues(id, rssUrl);
List<Object> get props => [id, rssUrl];
}

View File

@ -1,5 +1,5 @@
name: tsacdop
description: An easy-use podacasts player.
description: An open source podacasts player.
version: 0.4.11+28
@ -20,6 +20,7 @@ dependencies:
dio: ^3.0.9
extended_nested_scroll_view: ^1.0.1
effective_dart: ^1.2.4
equatable: ^1.2.3
feature_discovery: ^0.10.0
file_picker: ^1.12.0
flutter_html: ^0.11.1