mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Refresh programs for series recordings
This commit is contained in:
parent
fd853acdd5
commit
0438b889b6
3 changed files with 94 additions and 87 deletions
|
|
@ -1,7 +0,0 @@
|
||||||
package com.github.damontecres.wholphin.ui.detail.livetv
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ChannelRow() {
|
|
||||||
}
|
|
||||||
|
|
@ -48,6 +48,7 @@ class LiveTvViewModel
|
||||||
|
|
||||||
val start =
|
val start =
|
||||||
LocalDateTime.now().truncatedTo(ChronoUnit.HOURS)
|
LocalDateTime.now().truncatedTo(ChronoUnit.HOURS)
|
||||||
|
private lateinit var channelsIdToIndex: Map<UUID, Int>
|
||||||
|
|
||||||
val channels = MutableLiveData<List<TvChannel>>()
|
val channels = MutableLiveData<List<TvChannel>>()
|
||||||
val programs = MutableLiveData<List<TvProgram>>()
|
val programs = MutableLiveData<List<TvProgram>>()
|
||||||
|
|
@ -75,20 +76,27 @@ class LiveTvViewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Timber.d("Got ${channels.size} channels")
|
Timber.d("Got ${channels.size} channels")
|
||||||
val channelsIdToIndex =
|
channelsIdToIndex =
|
||||||
channels.withIndex().associateBy({ it.value.id }, { it.index })
|
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 maxStartDate = start.plusHours(MAX_HOURS).minusMinutes(1)
|
||||||
val minEndDate = start.plusMinutes(1L)
|
val minEndDate = start.plusMinutes(1L)
|
||||||
val request =
|
val request =
|
||||||
GetProgramsDto(
|
GetProgramsDto(
|
||||||
maxStartDate = maxStartDate,
|
maxStartDate = maxStartDate,
|
||||||
minEndDate = minEndDate,
|
minEndDate = minEndDate,
|
||||||
// maxEndDate = start.plusHours(25),
|
|
||||||
channelIds = channels.map { it.id },
|
channelIds = channels.map { it.id },
|
||||||
sortBy = listOf(ItemSortBy.START_DATE),
|
sortBy = listOf(ItemSortBy.START_DATE),
|
||||||
)
|
)
|
||||||
// val pager = ApiRequestPager(api, request, GetProgramsDtoHandler, viewModelScope).init()
|
|
||||||
// (0..<pager.size).forEach { pager.getBlocking(it) }
|
|
||||||
val programs =
|
val programs =
|
||||||
GetProgramsDtoHandler
|
GetProgramsDtoHandler
|
||||||
.execute(api, request)
|
.execute(api, request)
|
||||||
|
|
@ -149,14 +157,10 @@ class LiveTvViewModel
|
||||||
{ it.start },
|
{ it.start },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
Timber.d("Got ${programs.size} programs & ${fake.size} fake programs")
|
Timber.d("Got ${programs.size} programs & ${fake.size} fake programs")
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
this@LiveTvViewModel.channels.value = channels
|
|
||||||
this@LiveTvViewModel.programs.value = finalProgramList
|
this@LiveTvViewModel.programs.value = finalProgramList
|
||||||
this@LiveTvViewModel.programsByChannel.value = finalProgramsByChannel
|
this@LiveTvViewModel.programsByChannel.value = finalProgramsByChannel
|
||||||
loading.value = LoadingState.Success
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,6 +176,13 @@ class LiveTvViewModel
|
||||||
fetchedItem.value = result
|
fetchedItem.value = result
|
||||||
fetchingItem.value = LoadingState.Success
|
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)) {
|
viewModelScope.launch(ExceptionHandler(autoToast = true)) {
|
||||||
if (series) {
|
if (series) {
|
||||||
api.liveTvApi.cancelSeriesTimer(timerId)
|
api.liveTvApi.cancelSeriesTimer(timerId)
|
||||||
|
fetchPrograms(channels.value.orEmpty())
|
||||||
} else {
|
} else {
|
||||||
api.liveTvApi.cancelTimer(timerId)
|
api.liveTvApi.cancelTimer(timerId)
|
||||||
}
|
|
||||||
refreshProgram(programIndex, programId)
|
refreshProgram(programIndex, programId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun record(
|
fun record(
|
||||||
programIndex: Int,
|
programIndex: Int,
|
||||||
|
|
@ -202,6 +214,7 @@ class LiveTvViewModel
|
||||||
val d by api.liveTvApi.getDefaultTimer(programId.toServerString())
|
val d by api.liveTvApi.getDefaultTimer(programId.toServerString())
|
||||||
if (series) {
|
if (series) {
|
||||||
api.liveTvApi.createSeriesTimer(d)
|
api.liveTvApi.createSeriesTimer(d)
|
||||||
|
fetchPrograms(channels.value.orEmpty())
|
||||||
} else {
|
} else {
|
||||||
val payload =
|
val payload =
|
||||||
TimerInfoDto(
|
TimerInfoDto(
|
||||||
|
|
@ -227,10 +240,10 @@ class LiveTvViewModel
|
||||||
keepUntil = d.keepUntil,
|
keepUntil = d.keepUntil,
|
||||||
)
|
)
|
||||||
api.liveTvApi.createTimer(payload)
|
api.liveTvApi.createTimer(payload)
|
||||||
}
|
|
||||||
refreshProgram(programIndex, programId)
|
refreshProgram(programIndex, programId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun refreshProgram(
|
suspend fun refreshProgram(
|
||||||
programIndex: Int,
|
programIndex: Int,
|
||||||
|
|
|
||||||
|
|
@ -559,12 +559,13 @@ fun TvGuideGrid(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (program.isSeriesRecording) {
|
if (program.isSeriesRecording) {
|
||||||
|
val color = if (program.isRecording) Color.Red else Color.Gray
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.size(16.dp)
|
.size(16.dp)
|
||||||
.background(Color.Red.copy(alpha = .5f), shape = CircleShape)
|
.background(color.copy(alpha = .5f), shape = CircleShape)
|
||||||
.align(Alignment.BottomEnd),
|
.align(Alignment.BottomEnd),
|
||||||
)
|
)
|
||||||
Box(
|
Box(
|
||||||
|
|
@ -572,7 +573,7 @@ fun TvGuideGrid(
|
||||||
Modifier
|
Modifier
|
||||||
.padding(start = 4.dp, top = 4.dp, bottom = 4.dp, end = 10.dp)
|
.padding(start = 4.dp, top = 4.dp, bottom = 4.dp, end = 10.dp)
|
||||||
.size(16.dp)
|
.size(16.dp)
|
||||||
.background(Color.Red, shape = CircleShape)
|
.background(color, shape = CircleShape)
|
||||||
.align(Alignment.BottomEnd),
|
.align(Alignment.BottomEnd),
|
||||||
)
|
)
|
||||||
} else if (program.isRecording) {
|
} else if (program.isRecording) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue