Update playlist class.
This commit is contained in:
parent
085eb1d78e
commit
1e42cde733
|
@ -0,0 +1,18 @@
|
|||
import 'package:state_notifier/state_notifier.dart';
|
||||
|
||||
import '../local_storage/key_value_storage.dart';
|
||||
import '../type/playlist.dart';
|
||||
|
||||
class PlaylistProvider extends StateNotifier<List<Playlist>> {
|
||||
PlaylistProvider() : super([]);
|
||||
|
||||
Future<void> loadPlaylist() async {
|
||||
var storage = KeyValueStorage(playlistsAllKey);
|
||||
var playlistEntities = await storage.getPlaylists();
|
||||
var initState = [...playlistEntities.map(Playlist.fromEntity).toList()];
|
||||
for (var playlist in initState) {
|
||||
await playlist.getPlaylist();
|
||||
}
|
||||
state = initState;
|
||||
}
|
||||
}
|
|
@ -66,28 +66,22 @@ class PodcastGroup extends Equatable {
|
|||
final String color;
|
||||
|
||||
/// Id lists of podcasts in group.
|
||||
List<String> _podcastList;
|
||||
|
||||
List<String> get podcastList => _podcastList;
|
||||
|
||||
set podcastList(list) {
|
||||
_podcastList = list;
|
||||
}
|
||||
List<String> podcastList;
|
||||
|
||||
PodcastGroup(this.name,
|
||||
{this.color = '#000000', String id, List<String> podcastList})
|
||||
: id = id ?? Uuid().v4(),
|
||||
_podcastList = podcastList ?? [];
|
||||
podcastList = podcastList ?? [];
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -526,13 +520,14 @@ class GroupList extends ChangeNotifier {
|
|||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
/// Delete podcsat from device.
|
||||
Future<void> removePodcast(
|
||||
PodcastLocal podcast,
|
||||
) async {
|
||||
_syncRemove(podcast.rssUrl);
|
||||
final id = podcast.id;
|
||||
await _unsubscribe(id);
|
||||
await _unsubscribe(podcast.id);
|
||||
await File(podcast.imagePath)?.delete();
|
||||
}
|
||||
|
||||
Future<void> saveOrder(PodcastGroup group) async {
|
||||
|
|
|
@ -1,16 +1,60 @@
|
|||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../local_storage/key_value_storage.dart';
|
||||
import '../local_storage/sqflite_localpodcast.dart';
|
||||
import 'episodebrief.dart';
|
||||
|
||||
class PlaylistEntity {
|
||||
final String name;
|
||||
final String id;
|
||||
final List<String> episodeList;
|
||||
|
||||
PlaylistEntity(this.name, this.id, this.episodeList);
|
||||
|
||||
Map<String, Object> toJson() {
|
||||
return {'name': name, 'id': id, 'episodeList': episodeList};
|
||||
}
|
||||
|
||||
static PlaylistEntity fromJson(Map<String, Object> json) {
|
||||
var list = List<String>.from(json['episodeList']);
|
||||
return PlaylistEntity(json['name'] as String, json['id'] as String, list);
|
||||
}
|
||||
}
|
||||
|
||||
class Playlist {
|
||||
String name;
|
||||
/// Playlist name. the default playlist is named "Playlist".
|
||||
final String name;
|
||||
|
||||
/// Unique id for playlist.
|
||||
final String id;
|
||||
|
||||
/// Episode url list for playlist.
|
||||
final List<String> episodeList;
|
||||
|
||||
Playlist(this.name, {String id, List<String> episodeList})
|
||||
: id = id ?? Uuid().v4(),
|
||||
episodeList = episodeList ?? [];
|
||||
|
||||
PlaylistEntity toEntity() {
|
||||
return PlaylistEntity(name, id, episodeList);
|
||||
}
|
||||
|
||||
static Playlist fromEntity(PlaylistEntity entity) {
|
||||
return Playlist(
|
||||
entity.name,
|
||||
id: entity.id,
|
||||
episodeList: entity.episodeList,
|
||||
);
|
||||
}
|
||||
|
||||
final DBHelper _dbHelper = DBHelper();
|
||||
List<EpisodeBrief> _playlist;
|
||||
List<EpisodeBrief> _playlist = [];
|
||||
List<EpisodeBrief> get playlist => _playlist;
|
||||
final KeyValueStorage _playlistStorage = KeyValueStorage(playlistKey);
|
||||
|
||||
Future<void> getPlaylist() async {
|
||||
var urls = await _playlistStorage.getStringList();
|
||||
episodeList.addAll(urls);
|
||||
if (urls.length == 0) {
|
||||
_playlist = [];
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue