feat(About): use new contributors API
This commit is contained in:
parent
531a319b8a
commit
d06e8c75f1
5 changed files with 40 additions and 39 deletions
|
|
@ -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,
|
||||
)
|
||||
|
|
@ -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,
|
||||
)
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<GithubUser>()
|
||||
val contributors = mutableStateListOf<Contributor>()
|
||||
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<List<Contributor>> { 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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue