Skip to content

Commit

Permalink
feat: new programme guide.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed May 5, 2024
1 parent 5651531 commit 3e0a338
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface ProgrammeDao {

@Query(
"""
SELECT MIN(start) AS startEdge, MAX(`end`) AS endEdge
SELECT MIN(start) AS start_edge, MAX(`end`) AS end_edge
FROM programmes
WHERE epg_url in (:epgUrls)
AND channel_id = :channelId
Expand Down
15 changes: 10 additions & 5 deletions data/src/main/java/com/m3u/data/database/model/Programme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ data class Programme(
val id: Int = 0
)

@Keep
data class ProgrammeRange(
val startEdge: Long,
val endEdge: Long
@ColumnInfo("start_edge")
val start: Long,
@ColumnInfo("end_edge")
val end: Long
) {
fun isEmpty(): Boolean = length() <= 0
fun length(): Long = endEdge - startEdge
fun isEmpty(): Boolean = end - start <= 0
fun count(unit: Long = 1L): Int = (end - start).floorDiv(unit).toInt()

companion object {
const val HOUR_LENGTH = 3600000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ class StreamViewModel @Inject constructor(
)
}

it.length() < 12 * 3600000L -> {
with(Instant.fromEpochMilliseconds(it.startEdge)) {
it.count(ProgrammeRange.HOUR_LENGTH) < 12 -> {
with(Instant.fromEpochMilliseconds(it.start)) {
ProgrammeRange(
this.toEpochMilliseconds(),
this.plus(24.hours).toEpochMilliseconds()
Expand Down
Loading

0 comments on commit 3e0a338

Please sign in to comment.