feat(playlist): 歌单变更与歌单内元数据实时刷新
两个边界场景: 1) 新建/重命名/删除歌单、加入/移除歌曲后,主页歌单页不刷新 2) 歌单详情页里歌曲补全元数据后,标题/封面不更新 - 新增 PlaylistEvents(void 事件) - PlaylistRepository 的创建/重命名/删除/批量加入/移除后 publish - 主页订阅后重新拉取歌单摘要 - 歌单详情页订阅 MetadataEvents,按 path 就地更新行
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:math';
|
||||
import '../database/song_database.dart';
|
||||
import '../models/playlist.dart';
|
||||
import '../models/playlist_summary.dart';
|
||||
import '../services/playlist_events.dart';
|
||||
import '../services/audio_service.dart';
|
||||
|
||||
class PlaylistRepository {
|
||||
@@ -35,6 +36,7 @@ class PlaylistRepository {
|
||||
Future<Playlist> createPlaylist(String name) async {
|
||||
final playlist = Playlist(id: _generateId(), name: name);
|
||||
await _db.insertPlaylist(playlist.toJson());
|
||||
PlaylistEvents().publish();
|
||||
return playlist;
|
||||
}
|
||||
|
||||
@@ -55,6 +57,7 @@ class PlaylistRepository {
|
||||
existing.add(id);
|
||||
added++;
|
||||
}
|
||||
if (added > 0) PlaylistEvents().publish();
|
||||
return added;
|
||||
}
|
||||
Future<void> updatePlaylistName(String id, String newName) async {
|
||||
@@ -62,6 +65,7 @@ class PlaylistRepository {
|
||||
'name': newName,
|
||||
'updated_at': DateTime.now().millisecondsSinceEpoch,
|
||||
});
|
||||
PlaylistEvents().publish();
|
||||
}
|
||||
|
||||
// ⭐ 新增:更新播放模式
|
||||
@@ -78,6 +82,7 @@ class PlaylistRepository {
|
||||
|
||||
Future<void> deletePlaylist(String id) async {
|
||||
await _db.deletePlaylist(id);
|
||||
PlaylistEvents().publish();
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════
|
||||
@@ -95,6 +100,7 @@ class PlaylistRepository {
|
||||
|
||||
Future<void> removeSong(String playlistId, String songId) async {
|
||||
await _db.removeSongFromPlaylist(playlistId, songId);
|
||||
PlaylistEvents().publish();
|
||||
}
|
||||
|
||||
Future<void> reorderSongs(
|
||||
|
||||
Reference in New Issue
Block a user