From 873ad1cf8c5072c7e0e85ea6475992dc91e77fd0 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 10 Sep 2024 23:06:15 +0800 Subject: [PATCH] :bug: Fix cross source swap siblings issue --- lib/services/sourced_track/sourced_track.dart | 15 +++++++++------ lib/services/sourced_track/sources/kugou.dart | 4 ++-- lib/services/sourced_track/sources/netease.dart | 4 ++-- lib/services/sourced_track/sources/piped.dart | 4 ++-- lib/services/sourced_track/sources/youtube.dart | 3 +-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/services/sourced_track/sourced_track.dart b/lib/services/sourced_track/sourced_track.dart index 70609fc..eb2db77 100755 --- a/lib/services/sourced_track/sourced_track.dart +++ b/lib/services/sourced_track/sourced_track.dart @@ -5,6 +5,7 @@ import 'package:rhythm_box/providers/database.dart'; import 'package:rhythm_box/providers/error_notifier.dart'; import 'package:rhythm_box/providers/user_preferences.dart'; import 'package:rhythm_box/services/database/database.dart'; +import 'package:rhythm_box/services/server/active_sourced_track.dart'; import 'package:rhythm_box/services/sourced_track/sources/kugou.dart'; import 'package:rhythm_box/services/sourced_track/sources/netease.dart'; import 'package:rhythm_box/services/utils.dart'; @@ -81,14 +82,16 @@ abstract class SourcedTrack extends Track { }; } - static Type getTrackBySourceInfo(SourceInfo info) { + Future reRoutineSwapSiblings(SourceInfo info) { final sourceInfoTrackMap = { - YoutubeSourceInfo: YoutubeSourcedTrack, - PipedSourceInfo: PipedSourcedTrack, - NeteaseSourceInfo: NeteaseSourcedTrack, - KugouSourceInfo: KugouSourcedTrack, + YoutubeSourceInfo: YoutubeSourcedTrack.fetchFromTrack, + PipedSourceInfo: PipedSourcedTrack.fetchFromTrack, + NeteaseSourceInfo: NeteaseSourcedTrack.fetchFromTrack, + KugouSourceInfo: KugouSourcedTrack.fetchFromTrack, }; - return sourceInfoTrackMap[info.runtimeType]!; + return sourceInfoTrackMap[info.runtimeType]!( + track: Get.find().state.value!, + ); } static String getSearchTerm(Track track) { diff --git a/lib/services/sourced_track/sources/kugou.dart b/lib/services/sourced_track/sources/kugou.dart index b947481..7b03986 100644 --- a/lib/services/sourced_track/sources/kugou.dart +++ b/lib/services/sourced_track/sources/kugou.dart @@ -77,6 +77,7 @@ class KugouSourcedTrack extends SourcedTrack { sourceId: siblings.first.info.id, sourceType: const Value(SourceType.kugou), ), + mode: InsertMode.insertOrReplace, ); return KugouSourcedTrack( @@ -171,8 +172,7 @@ class KugouSourcedTrack extends SourcedTrack { @override Future swapWithSibling(SourceInfo sibling) async { if (sibling is! KugouSourceInfo) { - return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack) - .swapWithSibling(sibling); + return reRoutineSwapSiblings(sibling); } if (sibling.id == sourceInfo.id) { diff --git a/lib/services/sourced_track/sources/netease.dart b/lib/services/sourced_track/sources/netease.dart index 8133430..93b9cff 100755 --- a/lib/services/sourced_track/sources/netease.dart +++ b/lib/services/sourced_track/sources/netease.dart @@ -105,6 +105,7 @@ class NeteaseSourcedTrack extends SourcedTrack { sourceId: siblings.first.info.id, sourceType: const Value(SourceType.netease), ), + mode: InsertMode.insertOrReplace, ); return NeteaseSourcedTrack( @@ -202,8 +203,7 @@ class NeteaseSourcedTrack extends SourcedTrack { @override Future swapWithSibling(SourceInfo sibling) async { if (sibling is! NeteaseSourceInfo) { - return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack) - .swapWithSibling(sibling); + return reRoutineSwapSiblings(sibling); } if (sibling.id == sourceInfo.id) { diff --git a/lib/services/sourced_track/sources/piped.dart b/lib/services/sourced_track/sources/piped.dart index 7e64f9d..a4a8cfc 100755 --- a/lib/services/sourced_track/sources/piped.dart +++ b/lib/services/sourced_track/sources/piped.dart @@ -73,6 +73,7 @@ class PipedSourcedTrack extends SourcedTrack { : SourceType.youtubeMusic, ), ), + mode: InsertMode.insertOrReplace, ); return PipedSourcedTrack( @@ -256,8 +257,7 @@ class PipedSourcedTrack extends SourcedTrack { @override Future swapWithSibling(SourceInfo sibling) async { if (sibling is! PipedSourceInfo) { - return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack) - .swapWithSibling(sibling); + return reRoutineSwapSiblings(sibling); } if (sibling.id == sourceInfo.id) { diff --git a/lib/services/sourced_track/sources/youtube.dart b/lib/services/sourced_track/sources/youtube.dart index ed51f03..85b5360 100755 --- a/lib/services/sourced_track/sources/youtube.dart +++ b/lib/services/sourced_track/sources/youtube.dart @@ -271,8 +271,7 @@ class YoutubeSourcedTrack extends SourcedTrack { @override Future swapWithSibling(SourceInfo sibling) async { if (sibling is! YoutubeSourceInfo) { - return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack) - .swapWithSibling(sibling); + return reRoutineSwapSiblings(sibling); } if (sibling.id == sourceInfo.id) {