Refresh programs for series recordings

This commit is contained in:
Damontecres 2025-10-21 13:46:36 -04:00
parent fd853acdd5
commit 0438b889b6
No known key found for this signature in database
3 changed files with 94 additions and 87 deletions

View file

@ -1,7 +0,0 @@
package com.github.damontecres.wholphin.ui.detail.livetv
import androidx.compose.runtime.Composable
@Composable
fun ChannelRow() {
}

View file

@ -48,6 +48,7 @@ class LiveTvViewModel
val start =
LocalDateTime.now().truncatedTo(ChronoUnit.HOURS)
private lateinit var channelsIdToIndex: Map<UUID, Int>
val channels = MutableLiveData<List<TvChannel>>()
val programs = MutableLiveData<List<TvProgram>>()
@ -75,20 +76,27 @@ class LiveTvViewModel
)
}
Timber.d("Got ${channels.size} channels")
val channelsIdToIndex =
channelsIdToIndex =
channels.withIndex().associateBy({ it.value.id }, { it.index })
fetchPrograms(channels)
withContext(Dispatchers.Main) {
this@LiveTvViewModel.channels.value = channels
loading.value = LoadingState.Success
}
}
}
private suspend fun fetchPrograms(channels: List<TvChannel>) {
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..<pager.size).forEach { pager.getBlocking(it) }
val programs =
GetProgramsDtoHandler
.execute(api, request)
@ -149,14 +157,10 @@ class LiveTvViewModel
{ it.start },
),
)
Timber.d("Got ${programs.size} programs & ${fake.size} fake programs")
withContext(Dispatchers.Main) {
this@LiveTvViewModel.channels.value = channels
this@LiveTvViewModel.programs.value = finalProgramList
this@LiveTvViewModel.programsByChannel.value = finalProgramsByChannel
loading.value = LoadingState.Success
}
}
}
@ -172,6 +176,13 @@ class LiveTvViewModel
fetchedItem.value = result
fetchingItem.value = LoadingState.Success
}
if (result.data.seriesTimerId != null) {
val items =
api.liveTvApi
.getPrograms(GetProgramsDto(seriesTimerId = result.data.seriesTimerId))
.content.items
Timber.v("items=$items")
}
}
}
@ -185,13 +196,14 @@ class LiveTvViewModel
viewModelScope.launch(ExceptionHandler(autoToast = true)) {
if (series) {
api.liveTvApi.cancelSeriesTimer(timerId)
fetchPrograms(channels.value.orEmpty())
} else {
api.liveTvApi.cancelTimer(timerId)
}
refreshProgram(programIndex, programId)
}
}
}
}
fun record(
programIndex: Int,
@ -202,6 +214,7 @@ class LiveTvViewModel
val d by api.liveTvApi.getDefaultTimer(programId.toServerString())
if (series) {
api.liveTvApi.createSeriesTimer(d)
fetchPrograms(channels.value.orEmpty())
} else {
val payload =
TimerInfoDto(
@ -227,10 +240,10 @@ class LiveTvViewModel
keepUntil = d.keepUntil,
)
api.liveTvApi.createTimer(payload)
}
refreshProgram(programIndex, programId)
}
}
}
suspend fun refreshProgram(
programIndex: Int,

View file

@ -559,12 +559,13 @@ fun TvGuideGrid(
}
}
if (program.isSeriesRecording) {
val color = if (program.isRecording) Color.Red else Color.Gray
Box(
modifier =
Modifier
.padding(4.dp)
.size(16.dp)
.background(Color.Red.copy(alpha = .5f), shape = CircleShape)
.background(color.copy(alpha = .5f), shape = CircleShape)
.align(Alignment.BottomEnd),
)
Box(
@ -572,7 +573,7 @@ fun TvGuideGrid(
Modifier
.padding(start = 4.dp, top = 4.dp, bottom = 4.dp, end = 10.dp)
.size(16.dp)
.background(Color.Red, shape = CircleShape)
.background(color, shape = CircleShape)
.align(Alignment.BottomEnd),
)
} else if (program.isRecording) {