Skip to content

Commit

Permalink
Fix fetch the release everytime.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jun 9, 2024
1 parent f675604 commit f2be41d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.m3u.data.repository.other
import com.m3u.data.api.dto.github.Release

interface OtherRepository {
suspend fun getRelease(): Release?
suspend fun release(): Release?
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ internal class OtherRepositoryImpl @Inject constructor(
delegate: Logger
) : OtherRepository {
private val logger = delegate.install(Profiles.REPOS_OTHER)
override suspend fun getRelease(): Release? {
if (publisher.snapshot) return null
private var releases: List<Release>? = null
override suspend fun release(): Release? {
if (releases == null) {
// cannot use lazy because the suspension
releases = logger.execute { githubApi.releases("oxyroid", "M3UAndroid") } ?: emptyList()
}
val versionName = publisher.versionName
val releases = logger
.execute { githubApi.releases("oxyroid", "M3UAndroid") }
?: emptyList()
if (releases.isEmpty()) return null
val i = releases.indexOf { it.name == versionName }
// if (i <= 0) return null
return releases.first()
val currentReleases = releases ?: emptyList()
if (currentReleases.isEmpty()) return null
val i = currentReleases.indexOf { it.name == versionName }
if (i <= 0 && !publisher.snapshot) return null
return currentReleases.first()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ForyouViewModel @Inject constructor(
)

private val newRelease: StateFlow<Release?> = flow {
emit(otherRepository.getRelease())
emit(otherRepository.release())
}
.stateIn(
scope = viewModelScope,
Expand Down

0 comments on commit f2be41d

Please sign in to comment.