diff --git a/app/src/main/kotlin/com/aliucord/manager/network/dto/GithubUser.kt b/app/src/main/kotlin/com/aliucord/manager/network/dto/GithubUser.kt deleted file mode 100644 index 04c09a0..0000000 --- a/app/src/main/kotlin/com/aliucord/manager/network/dto/GithubUser.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2022 Juby210 & zt - * Licensed under the Open Software License version 3.0 - */ - -package com.aliucord.manager.network.dto - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class GithubUser( - @SerialName("login") - val name: String, - val contributions: Int, -) 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 new file mode 100644 index 0000000..25646ec --- /dev/null +++ b/app/src/main/kotlin/com/aliucord/manager/network/models/Contributor.kt @@ -0,0 +1,12 @@ +package com.aliucord.manager.network.models + +import androidx.compose.runtime.Immutable +import kotlinx.serialization.Serializable + +@Immutable +@Serializable +data class Contributor( + val username: String, + val avatarUrl: String, + val contributions: Int, +) 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 f464648..c8d846c 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 @@ -19,11 +19,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import coil3.compose.AsyncImage import com.aliucord.manager.R -import com.aliucord.manager.network.dto.GithubUser +import com.aliucord.manager.network.models.Contributor @Composable fun ContributorCommitsItem( - user: GithubUser, + user: Contributor, modifier: Modifier = Modifier, ) { val uriHandler = LocalUriHandler.current @@ -31,7 +31,7 @@ fun ContributorCommitsItem( Row( modifier = modifier .clickable { - uriHandler.openUri("https://github.com/${user.name}") + uriHandler.openUri("https://github.com/${user.username}") } .padding(horizontal = 16.dp, vertical = 10.dp) .fillMaxWidth(), @@ -39,8 +39,8 @@ fun ContributorCommitsItem( verticalAlignment = Alignment.CenterVertically ) { AsyncImage( - model = "https://github.com/${user.name}.png", - contentDescription = user.name, + model = user.avatarUrl, + contentDescription = user.username, Modifier .size(45.dp) .clip(CircleShape) @@ -48,7 +48,7 @@ fun ContributorCommitsItem( Column { Text( - text = user.name, + text = user.username, style = MaterialTheme.typography.bodyLarge ) Text( 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 1d01066..c9e3b1b 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 @@ -3,31 +3,36 @@ package com.aliucord.manager.ui.screens.about import androidx.compose.runtime.* import cafe.adriel.voyager.core.model.ScreenModel import cafe.adriel.voyager.core.model.screenModelScope -import com.aliucord.manager.domain.repository.GithubRepository -import com.aliucord.manager.network.dto.GithubUser +import com.aliucord.manager.network.models.Contributor +import com.aliucord.manager.network.services.HttpService import com.aliucord.manager.network.utils.fold -import kotlinx.coroutines.launch +import com.aliucord.manager.util.launchBlock +import io.ktor.client.request.url class AboutModel( - private val githubRepository: GithubRepository, + private val http: HttpService, ) : ScreenModel { - val contributors = mutableStateListOf() + val contributors = mutableStateListOf() var fetchError by mutableStateOf(false) init { fetchContributors() } - fun fetchContributors() { - screenModelScope.launch { - githubRepository.getContributors().fold( - success = { - contributors.clear() - contributors.addAll(it) - fetchError = false - }, - fail = { fetchError = true }, - ) - } + fun fetchContributors() = screenModelScope.launchBlock { + val response = http.request> { url(CONTRIBUTORS_API_URL) } + + response.fold( + success = { + contributors.clear() + contributors.addAll(it) + fetchError = false + }, + fail = { fetchError = true }, + ) + } + + companion object { + private const val CONTRIBUTORS_API_URL = "https://api.rushii.dev/aliucord/contributors" } } diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutScreen.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutScreen.kt index 8665847..337ba32 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutScreen.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/about/AboutScreen.kt @@ -77,7 +77,7 @@ class AboutScreen : Screen, Parcelable { } if (model.contributors.isNotEmpty()) { - items(model.contributors, key = { "user-${it.name}" }) { user -> + items(model.contributors, key = { it.username }) { user -> ContributorCommitsItem(user) } } else {