Skip to content

Commit

Permalink
feat: sync programmes in playlist configuration screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed May 6, 2024
1 parent c4baa7e commit 024b633
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Profiles {

val REPOS_PLAYLIST = Profile("repos-playlist")
val REPOS_STREAM = Profile("repos-stream")
val REPOS_PROGRAMME = Profile("repos-programme")
val REPOS_PROGRAMME = Profile("repos-programme", Message.LEVEL_INFO)
val REPOS_TELEVISION = Profile("repos-television")
val REPOS_MEDIA = Profile("repos-media")

Expand Down
11 changes: 11 additions & 0 deletions data/src/main/java/com/m3u/data/database/dao/ProgrammeDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,15 @@ interface ProgrammeDao {
epgUrls: List<String>,
channelId: String
): Flow<ProgrammeRange>

@Query(
"""
SELECT MIN(start) AS start_edge, MAX(`end`) AS end_edge
FROM programmes
WHERE epg_url in (:epgUrls)
"""
)
fun observeProgrammeRange(
epgUrls: List<String>
): Flow<ProgrammeRange>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ interface ProgrammeRepository {
): PagingSource<Int, Programme>

fun observeProgrammeRange(
epgUrls: List<String>,
playlistUrl: String,
channelId: String
): Flow<ProgrammeRange>

fun observeProgrammeRange(
playlistUrl: String
): Flow<ProgrammeRange>

val refreshingEpgUrls: StateFlow<List<String>>
fun checkOrRefreshProgrammesOrThrow(
playlistUrl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.supervisorScope
Expand Down Expand Up @@ -50,11 +52,23 @@ internal class ProgrammeRepositoryImpl @Inject constructor(
): PagingSource<Int, Programme> = programmeDao.pagingByEpgUrlsAndChannelId(epgUrls, channelId)

override fun observeProgrammeRange(
epgUrls: List<String>,
playlistUrl: String,
channelId: String
): Flow<ProgrammeRange> = programmeDao
.observeProgrammeRange(epgUrls, channelId)
.filterNot { (start, _) -> start == 0L }
): Flow<ProgrammeRange> = playlistDao.observeByUrl(playlistUrl).flatMapLatest { playlist ->
playlist ?: return@flatMapLatest flowOf()
programmeDao
.observeProgrammeRange(playlist.epgUrlsOrXtreamXmlUrl(), channelId)
.filterNot { (start, end) -> start == 0L || end == 0L }
}

override fun observeProgrammeRange(playlistUrl: String): Flow<ProgrammeRange> =
playlistDao.observeByUrl(playlistUrl)
.map { playlist ->
playlist?.epgUrlsOrXtreamXmlUrl() ?: emptyList()
}
.flatMapLatest { epgUrls ->
programmeDao.observeProgrammeRange(epgUrls)
}

override fun checkOrRefreshProgrammesOrThrow(
playlistUrl: String,
Expand Down
2 changes: 2 additions & 0 deletions features/playlist-configuration/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ dependencies {
implementation(libs.com.google.dagger.hilt.android)
implementation(libs.androidx.hilt.hilt.navigation.compose)
ksp(libs.com.google.dagger.hilt.compiler)

implementation(libs.androidx.work.work.runtime.ktx)
}
Loading

0 comments on commit 024b633

Please sign in to comment.