diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/ChannelRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/ChannelRow.kt deleted file mode 100644 index 3f105e65..00000000 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/ChannelRow.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.damontecres.wholphin.ui.detail.livetv - -import androidx.compose.runtime.Composable - -@Composable -fun ChannelRow() { -} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/LiveTvViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/LiveTvViewModel.kt index bee58b7e..2bf96ef2 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/LiveTvViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/livetv/LiveTvViewModel.kt @@ -48,6 +48,7 @@ class LiveTvViewModel val start = LocalDateTime.now().truncatedTo(ChronoUnit.HOURS) + private lateinit var channelsIdToIndex: Map val channels = MutableLiveData>() val programs = MutableLiveData>() @@ -75,91 +76,94 @@ class LiveTvViewModel ) } Timber.d("Got ${channels.size} channels") - val channelsIdToIndex = + channelsIdToIndex = channels.withIndex().associateBy({ it.value.id }, { it.index }) - val maxStartDate = start.plusHours(MAX_HOURS).minusMinutes(1) - val minEndDate = start.plusMinutes(1L) - val request = - GetProgramsDto( - maxStartDate = maxStartDate, - minEndDate = minEndDate, -// maxEndDate = start.plusHours(25), - channelIds = channels.map { it.id }, - sortBy = listOf(ItemSortBy.START_DATE), - ) -// val pager = ApiRequestPager(api, request, GetProgramsDtoHandler, viewModelScope).init() -// (0.. - TvProgram( - id = dto.id, - channelId = dto.channelId!!, - start = dto.startDate!!, - end = dto.endDate!!, - startHours = hoursBetween(start, dto.startDate!!), - endHours = hoursBetween(start, dto.endDate!!), - duration = dto.runTimeTicks!!.ticks, - name = dto.seriesName ?: dto.name, - subtitle = dto.episodeTitle.takeIf { dto.isSeries ?: false }, - seasonEpisode = - if (dto.indexNumber != null && dto.parentIndexNumber != null) { - SeasonEpisode(dto.parentIndexNumber!!, dto.indexNumber!!) - } else { - null - }, - isRecording = dto.timerId.isNotNullOrBlank(), - isSeriesRecording = dto.seriesTimerId.isNotNullOrBlank(), - ) - }.filter { it.startHours >= 0 && it.endHours >= 0 } // TODO shouldn't need to filter client side + fetchPrograms(channels) - val programsByChannel = programs.groupBy { it.channelId } - val emptyChannels = channels.filter { programsByChannel[it.id].orEmpty().isEmpty() } - val fake = mutableListOf() - val finalProgramsByChannel = - programsByChannel.toMutableMap().apply { - emptyChannels.forEach { channel -> - val fakePrograms = - (0..) { + val maxStartDate = start.plusHours(MAX_HOURS).minusMinutes(1) + val minEndDate = start.plusMinutes(1L) + val request = + GetProgramsDto( + maxStartDate = maxStartDate, + minEndDate = minEndDate, + channelIds = channels.map { it.id }, + sortBy = listOf(ItemSortBy.START_DATE), + ) + val programs = + GetProgramsDtoHandler + .execute(api, request) + .content.items + .map { dto -> + TvProgram( + id = dto.id, + channelId = dto.channelId!!, + start = dto.startDate!!, + end = dto.endDate!!, + startHours = hoursBetween(start, dto.startDate!!), + endHours = hoursBetween(start, dto.endDate!!), + duration = dto.runTimeTicks!!.ticks, + name = dto.seriesName ?: dto.name, + subtitle = dto.episodeTitle.takeIf { dto.isSeries ?: false }, + seasonEpisode = + if (dto.indexNumber != null && dto.parentIndexNumber != null) { + SeasonEpisode(dto.parentIndexNumber!!, dto.indexNumber!!) + } else { + null + }, + isRecording = dto.timerId.isNotNullOrBlank(), + isSeriesRecording = dto.seriesTimerId.isNotNullOrBlank(), + ) + }.filter { it.startHours >= 0 && it.endHours >= 0 } // TODO shouldn't need to filter client side + + val programsByChannel = programs.groupBy { it.channelId } + val emptyChannels = channels.filter { programsByChannel[it.id].orEmpty().isEmpty() } + val fake = mutableListOf() + val finalProgramsByChannel = + programsByChannel.toMutableMap().apply { + emptyChannels.forEach { channel -> + val fakePrograms = + (0..