Skip to content

Commit

Permalink
Fix Incorrect playlist order when updating to newer version (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr3y-the-programmer authored Apr 23, 2024
1 parent d8b1bd6 commit dd0cae5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ class PodcasterAppState @Inject constructor(
val playbackSpeed = currentlyPlayingEpisode.value?.playingSpeed ?: 1.0f
_trackProgress.update { episode.progressInSec ?: 0 }
podcastsRepository.setCurrentlyPlayingEpisode(CurrentlyPlayingEpisode(episode, PlayingStatus.Loading, playbackSpeed))
podcastsRepository.addEpisodeToQueue(episode)
if (currentEpisodeId != null) {
podcastsRepository.removeEpisodeFromQueue(currentEpisodeId)
podcastsRepository.replaceEpisodeInQueue(episode, currentEpisodeId)
} else {
podcastsRepository.addEpisodeToQueue(episode)
}
controller?.setMediaItemForEpisode(episode)
controller?.setPlaybackSpeed(playbackSpeed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ interface PodcastsRepository {

fun addEpisodeToQueue(episode: Episode)

fun replaceEpisodeInQueue(newEpisode: Episode, oldEpisodeId: Long)

fun removeEpisodeFromQueue(episodeId: Long)

fun isEpisodeInQueue(episodeId: Long): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class DefaultPodcastsRepository @Inject constructor(
podcastsDao.addEpisodeToQueue(episode)
}

override fun replaceEpisodeInQueue(newEpisode: Episode, oldEpisodeId: Long) {
podcastsDao.replaceEpisodeInQueue(newEpisode, oldEpisodeId)
}

override fun removeEpisodeFromQueue(episodeId: Long) {
podcastsDao.removeEpisodeFromQueue(episodeId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ interface PodcastsDao {

fun addEpisodeToQueue(episode: Episode)

fun replaceEpisodeInQueue(newEpisode: Episode, oldEpisodeId: Long)

fun removeEpisodeFromQueue(episodeId: Long)

fun isEpisodeInQueue(episodeId: Long): Boolean
Expand Down Expand Up @@ -362,6 +364,18 @@ class DefaultPodcastsDao @Inject constructor(
}
}

override fun replaceEpisodeInQueue(newEpisode: Episode, oldEpisodeId: Long) {
if (isEpisodeAvailableNonObservable(newEpisode.id)) {
database.queueEntityQueries.replaceQueueEpisode(newEpisode.id, oldEpisodeId)
return
}

database.episodeEntityQueries.transaction {
database.episodeEntityQueries.insertEpisode(newEpisode.toEpisodeEntity())
database.queueEntityQueries.replaceQueueEpisode(newEpisode.id, oldEpisodeId)
}
}

override fun removeEpisodeFromQueue(episodeId: Long) {
database.queueEntityQueries.deleteEpisodeFromQueue(episodeId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ ORDER BY datetime(qe.added_at) ASC;
insertNewQueueEpisode:
INSERT OR REPLACE INTO queueEntity (episodeId) VALUES (:episodeId);

replaceQueueEpisode:
UPDATE queueEntity SET episodeId = :newEpisodeId WHERE episodeId = :oldEpisodeId;

deleteEpisodeFromQueue:
DELETE FROM queueEntity WHERE episodeId = :episodeId;

Expand Down

0 comments on commit dd0cae5

Please sign in to comment.