diff --git a/app/src/main/kotlin/com/aliucord/manager/network/models/Contributor.kt b/app/src/main/kotlin/com/aliucord/manager/network/models/Contributor.kt index 46c761f5..24a03f5d 100644 --- a/app/src/main/kotlin/com/aliucord/manager/network/models/Contributor.kt +++ b/app/src/main/kotlin/com/aliucord/manager/network/models/Contributor.kt @@ -19,5 +19,8 @@ data class Contributor( data class Repository( val name: String, val commits: Int, - ) + ) { + val repository: String + get() = name.substringAfterLast("/") + } } diff --git a/app/src/main/kotlin/com/aliucord/manager/network/services/AliucordGithubService.kt b/app/src/main/kotlin/com/aliucord/manager/network/services/AliucordGithubService.kt index 5df0933e..6bc965f5 100644 --- a/app/src/main/kotlin/com/aliucord/manager/network/services/AliucordGithubService.kt +++ b/app/src/main/kotlin/com/aliucord/manager/network/services/AliucordGithubService.kt @@ -1,11 +1,10 @@ package com.aliucord.manager.network.services -import com.aliucord.manager.network.models.BuildInfo -import com.aliucord.manager.network.models.GithubRelease +import com.aliucord.manager.di.cacheControl +import com.aliucord.manager.network.models.* import com.aliucord.manager.network.utils.ApiResponse -import io.ktor.client.request.header import io.ktor.client.request.url -import io.ktor.http.HttpHeaders +import io.ktor.http.CacheControl class AliucordGithubService( private val http: HttpService, @@ -18,7 +17,7 @@ class AliucordGithubService( url(DATA_JSON_URL) if (force) { - header(HttpHeaders.CacheControl, "no-cache") + cacheControl(CacheControl.NoCache(null)) } } @@ -28,14 +27,24 @@ class AliucordGithubService( suspend fun getManagerReleases(): ApiResponse> { return http.request { url("https://api.github.com/repos/$ORG/$MANAGER_REPO/releases") - header(HttpHeaders.CacheControl, "public, max-age=60, s-maxage=60") + cacheControl(CacheControl.MaxAge(maxAgeSeconds = 60)) } } + /** + * Fetches all the contributors with a 24h local cache. + */ + suspend fun getContributors(): ApiResponse> = http.request { + url(CONTRIBUTORS_JSON_URL) + cacheControl(CacheControl.MaxAge(maxAgeSeconds = 60 * 60 * 24)) + } + companion object { const val ORG = "Aliucord" const val MANAGER_REPO = "Manager" const val DATA_JSON_URL = "https://builds.aliucord.com/data.json" + + private const val CONTRIBUTORS_JSON_URL = "https://builds.aliucord.com/contributors.json" } } diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/components/Contributors.kt b/app/src/main/kotlin/com/aliucord/manager/ui/components/Contributors.kt index 3ddf44f5..c2c2a4ce 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/components/Contributors.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/components/Contributors.kt @@ -66,7 +66,7 @@ fun ContributorCommitsItem( ) Text( - text = user.repositories.joinToString { it.name }, + text = user.repositories.joinToString { it.repository }, fontStyle = FontStyle.Italic, style = MaterialTheme.typography.bodySmall .copy(color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)), diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutModel.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutModel.kt index 75db4296..c34a8dfd 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutModel.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutModel.kt @@ -2,15 +2,13 @@ package com.aliucord.manager.ui.screens.about import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.screenModelScope -import com.aliucord.manager.network.models.Contributor -import com.aliucord.manager.network.services.HttpService +import com.aliucord.manager.network.services.AliucordGithubService import com.aliucord.manager.network.utils.fold import com.aliucord.manager.ui.util.toUnsafeImmutable import com.aliucord.manager.util.launchIO -import io.ktor.client.request.url class AboutModel( - private val http: HttpService, + private val aliucordGithubService: AliucordGithubService, ) : StateScreenModel(AboutScreenState.Loading) { init { fetchContributors() @@ -19,15 +17,13 @@ class AboutModel( fun fetchContributors() = screenModelScope.launchIO { mutableState.value = AboutScreenState.Loading - val response = http.request> { url(CONTRIBUTORS_API_URL) } + val response = aliucordGithubService.getContributors() mutableState.value = response.fold( - success = { AboutScreenState.Loaded(it.toUnsafeImmutable()) }, + success = { contributors -> + AboutScreenState.Loaded(contributors.toUnsafeImmutable()) + }, fail = { AboutScreenState.Failure }, ) } - - companion object { - private const val CONTRIBUTORS_API_URL = "https://api.rushii.dev/aliucord/contributors" - } }