diff --git a/app/src/main/java/com/happyseal/zenplayer/core/datastore/QueueSnapshotDataStore.kt b/app/src/main/java/com/happyseal/zenplayer/core/datastore/QueueSnapshotDataStore.kt index 9c8b04cf..204b70e1 100644 --- a/app/src/main/java/com/happyseal/zenplayer/core/datastore/QueueSnapshotDataStore.kt +++ b/app/src/main/java/com/happyseal/zenplayer/core/datastore/QueueSnapshotDataStore.kt @@ -13,6 +13,7 @@ import com.happyseal.zenplayer.LogMusic import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map +import org.json.JSONArray private val Context.queueDataStore: DataStore by preferencesDataStore( name = "zenplayer_queue_snapshot", @@ -33,7 +34,7 @@ class QueueSnapshotDataStore( */ suspend fun saveQueueSnapshot(snapshot: QueueSnapshot) { dataStore.edit { prefs -> - prefs[KEY_TRACK_URIS] = snapshot.trackUris.joinToString(SEPARATOR) + prefs[KEY_TRACK_URIS] = JSONArray(snapshot.trackUris).toString() prefs[KEY_CURRENT_INDEX] = snapshot.currentIndex prefs[KEY_POSITION_MS] = snapshot.positionMs } @@ -50,7 +51,8 @@ class QueueSnapshotDataStore( }.map { prefs -> val urisRaw = prefs[KEY_TRACK_URIS] ?: return@map null if (urisRaw.isBlank()) return@map null - val uris = urisRaw.split(SEPARATOR).filter { it.isNotBlank() } + val jsonArray = JSONArray(urisRaw) + val uris = List(jsonArray.length()) { jsonArray.getString(it) }.filter { it.isNotBlank() } if (uris.isEmpty()) return@map null QueueSnapshot( @@ -76,7 +78,6 @@ class QueueSnapshotDataStore( private val KEY_TRACK_URIS = stringPreferencesKey("queue_track_uris") private val KEY_CURRENT_INDEX = intPreferencesKey("queue_current_index") private val KEY_POSITION_MS = longPreferencesKey("queue_position_ms") - private const val SEPARATOR = "|||" } }