🐛 Fix cross source swap siblings issue

This commit is contained in:
LittleSheep 2024-09-10 23:06:15 +08:00
parent e0c9edad78
commit 873ad1cf8c
5 changed files with 16 additions and 14 deletions

View File

@ -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<SourcedTrack?> 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<ActiveSourcedTrackProvider>().state.value!,
);
}
static String getSearchTerm(Track track) {

View File

@ -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<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
if (sibling is! KugouSourceInfo) {
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
.swapWithSibling(sibling);
return reRoutineSwapSiblings(sibling);
}
if (sibling.id == sourceInfo.id) {

View File

@ -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<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
if (sibling is! NeteaseSourceInfo) {
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
.swapWithSibling(sibling);
return reRoutineSwapSiblings(sibling);
}
if (sibling.id == sourceInfo.id) {

View File

@ -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<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
if (sibling is! PipedSourceInfo) {
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
.swapWithSibling(sibling);
return reRoutineSwapSiblings(sibling);
}
if (sibling.id == sourceInfo.id) {

View File

@ -271,8 +271,7 @@ class YoutubeSourcedTrack extends SourcedTrack {
@override
Future<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
if (sibling is! YoutubeSourceInfo) {
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
.swapWithSibling(sibling);
return reRoutineSwapSiblings(sibling);
}
if (sibling.id == sourceInfo.id) {