Skip to content

Commit 9c0a9d1

Browse files
committed
Add reorderPlaylistAudios api
1 parent 7dcc67a commit 9c0a9d1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

app/src/main/java/com/ismartcoding/plain/ui/components/WebAddressBar.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import androidx.compose.ui.text.AnnotatedString
3333
import androidx.compose.ui.text.TextStyle
3434
import androidx.compose.ui.unit.dp
3535
import androidx.compose.ui.unit.sp
36-
import com.ismartcoding.lib.channel.Channel
3736
import com.ismartcoding.plain.R
3837
import com.ismartcoding.plain.TempData
3938
import com.ismartcoding.plain.clipboardManager

app/src/main/java/com/ismartcoding/plain/web/SXGraphQL.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,42 @@ class SXGraphQL(val schema: Schema) {
990990
true
991991
}
992992
}
993+
mutation("reorderPlaylistAudios") {
994+
resolver { paths: List<String> ->
995+
val context = MainApp.instance
996+
997+
// Get current playlist
998+
val currentPlaylist = AudioPlaylistPreference.getValueAsync(context)
999+
if (currentPlaylist.isEmpty() || paths.isEmpty()) {
1000+
return@resolver true
1001+
}
1002+
1003+
// Create a map of paths to audio items
1004+
val audioMap = currentPlaylist.associateBy { it.path }
1005+
1006+
// Reorder the playlist based on the provided paths
1007+
val reorderedPlaylist = mutableListOf<DPlaylistAudio>()
1008+
1009+
// First add audio items in the new order
1010+
paths.forEach { path ->
1011+
audioMap[path]?.let { audio ->
1012+
reorderedPlaylist.add(audio)
1013+
}
1014+
}
1015+
1016+
// Add other audio items that are not in the reorder list (keep their original positions)
1017+
currentPlaylist.forEach { audio ->
1018+
if (!paths.contains(audio.path)) {
1019+
reorderedPlaylist.add(audio)
1020+
}
1021+
}
1022+
1023+
// Save the reordered playlist
1024+
AudioPlaylistPreference.putAsync(context, reorderedPlaylist)
1025+
1026+
true
1027+
}
1028+
}
9931029
mutation("createFeed") {
9941030
resolver { url: String, fetchContent: Boolean ->
9951031
val syndFeed = withIO { FeedHelper.fetchAsync(url) }

0 commit comments

Comments
 (0)