feat: remove commits list

This commit is contained in:
rushiiMachine 2024-01-13 17:48:05 -08:00
parent 5339459ac8
commit b47a1b4488
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
9 changed files with 2 additions and 259 deletions

View file

@ -7,7 +7,6 @@ import com.aliucord.manager.network.utils.transform
class GithubRepository(
private val service: AliucordGithubService,
) {
suspend fun getCommits(page: Int = 0) = service.getCommits(page)
suspend fun getContributors() = service.getContributors()
.transform { it.sortedByDescending(GithubUser::contributions) }

View file

@ -1,24 +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 Commit(
@SerialName("html_url")
val htmlUrl: String,
val sha: String,
val commit: Commit,
val author: Author?,
) {
@Serializable
data class Author(@SerialName("login") val name: String)
@Serializable
data class Commit(val message: String)
}

View file

@ -18,7 +18,6 @@ class AliucordGithubService(
}
}
suspend fun getCommits(page: Int = 0) = github.getCommits(ORG, MAIN_REPO, page)
suspend fun getManagerReleases() = github.getReleases(ORG, MANAGER_REPO)
suspend fun getContributors() = github.getContributors(ORG, MAIN_REPO)

View file

@ -1,8 +1,8 @@
package com.aliucord.manager.network.service
import com.aliucord.manager.network.dto.*
import com.aliucord.manager.network.dto.GithubRelease
import com.aliucord.manager.network.dto.GithubUser
import com.aliucord.manager.network.utils.ApiResponse
import io.ktor.client.request.parameter
import io.ktor.client.request.url
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -10,15 +10,6 @@ import kotlinx.coroutines.withContext
class GithubService(
private val http: HttpService,
) {
suspend fun getCommits(owner: String, repo: String, page: Int = 0): ApiResponse<List<Commit>> {
return withContext(Dispatchers.IO) {
http.request {
url("https://api.github.com/repos/$owner/$repo/commits")
parameter("page", page)
}
}
}
suspend fun getContributors(owner: String, repo: String): ApiResponse<List<GithubUser>> {
return withContext(Dispatchers.IO) {
http.request {
@ -34,12 +25,4 @@ class GithubService(
}
}
}
suspend fun getLatestRelease(owner: String, repo: String): ApiResponse<GithubRelease> {
return withContext(Dispatchers.IO) {
http.request {
url("https://api.github.com/repos/$owner/$repo/releases/latest")
}
}
}
}

View file

@ -1,177 +0,0 @@
package com.aliucord.manager.ui.components.home
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.paging.LoadState
import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.items
import coil.compose.AsyncImage
import com.aliucord.manager.R
import com.aliucord.manager.network.dto.Commit
import com.aliucord.manager.ui.components.LoadFailure
import com.aliucord.manager.ui.util.annotatingStringResource
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.Flow
@Composable
fun CommitList(
commits: Flow<PagingData<Commit>>,
onRetry: () -> Unit,
) {
ElevatedCard(
modifier = Modifier.padding(bottom = 16.dp)
) {
Column(
modifier = Modifier
.weight(1f, true)
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
val lazyPagingItems = commits.collectAsLazyPagingItems()
Text(
modifier = Modifier.padding(20.dp, 20.dp, 20.dp),
text = stringResource(R.string.commits),
style = MaterialTheme.typography.titleLarge.copy(fontSize = 23.sp),
color = MaterialTheme.colorScheme.primary
)
LazyColumn(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = PaddingValues(bottom = 12.dp)
) {
when (lazyPagingItems.loadState.refresh) {
LoadState.Loading -> item {
CircularProgressIndicator(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
.wrapContentWidth(Alignment.CenterHorizontally)
)
}
is LoadState.Error -> item {
Box(
modifier = Modifier
.fillParentMaxSize()
.padding(bottom = 50.dp),
contentAlignment = Alignment.Center
) {
LoadFailure(onRetry = {
lazyPagingItems.retry()
onRetry()
})
}
}
is LoadState.NotLoading -> {
items(lazyPagingItems) { commit ->
if (commit != null) {
CommitItem(commit)
}
}
}
}
when (lazyPagingItems.loadState.append) {
LoadState.Loading -> item {
CircularProgressIndicator(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.wrapContentWidth(Alignment.CenterHorizontally)
)
}
is LoadState.Error -> item {
LoadFailure(onRetry = {
lazyPagingItems.retry()
})
}
else -> {}
}
}
}
}
}
@Composable
fun CommitItem(
commit: Commit,
) {
val uriHandler = LocalUriHandler.current
Column(
modifier = Modifier
.fillMaxWidth()
.clickable {
uriHandler.openUri(commit.htmlUrl)
}
.padding(horizontal = 20.dp, vertical = 5.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
commit.commit.message.split("\n").first(),
style = MaterialTheme.typography.bodyMedium
)
if (commit.author != null) Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
AsyncImage(
modifier = Modifier
.size(20.dp)
.clip(CircleShape),
model = "https://github.com/${commit.author.name}.png",
contentDescription = commit.author.name
)
Text(
annotatingStringResource(
R.string.contributors_commit_title,
persistentListOf(
commit.author.name,
commit.sha.take(8),
)
) {
when (it) {
"name" -> SpanStyle(
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface
)
"middle" -> SpanStyle(
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
)
"commit" -> SpanStyle(
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.primary
)
else -> null
}
},
style = MaterialTheme.typography.bodySmall
)
}
}
}

View file

@ -4,7 +4,6 @@ import android.app.Application
import android.content.pm.PackageManager
import android.util.Log
import androidx.compose.runtime.*
import androidx.paging.*
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import com.aliucord.manager.BuildConfig
@ -12,7 +11,6 @@ import com.aliucord.manager.R
import com.aliucord.manager.domain.manager.PreferencesManager
import com.aliucord.manager.domain.repository.GithubRepository
import com.aliucord.manager.installer.util.uninstallApk
import com.aliucord.manager.network.dto.Commit
import com.aliucord.manager.network.utils.fold
import com.aliucord.manager.ui.util.DiscordVersion
import com.aliucord.manager.util.getPackageVersion
@ -30,32 +28,6 @@ class HomeModel(
var installedVersion by mutableStateOf<DiscordVersion>(DiscordVersion.None)
private set
val commits = Pager(PagingConfig(pageSize = 30)) {
object : PagingSource<Int, Commit>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Commit> {
val page = params.key ?: 0
return github.getCommits(page).fold(
success = { commits ->
val prevKey = if (page > 0) page - 1 else null
val nextKey = if (commits.isNotEmpty()) page + 1 else null
LoadResult.Page(
data = commits,
prevKey = prevKey,
nextKey = nextKey
)
},
fail = { LoadResult.Error(it) }
)
}
override fun getRefreshKey(state: PagingState<Int, Commit>) = state.anchorPosition?.let {
state.closestPageToPosition(it)?.prevKey?.plus(1) ?: state.closestPageToPosition(it)?.nextKey?.minus(1)
}
}
}.flow.cachedIn(screenModelScope)
init {
screenModelScope.launch(Dispatchers.IO) {
_fetchInstalledVersion()

View file

@ -23,7 +23,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import com.aliucord.manager.BuildConfig
import com.aliucord.manager.R
import com.aliucord.manager.ui.components.dialogs.InstallerDialog
import com.aliucord.manager.ui.components.home.CommitList
import com.aliucord.manager.ui.components.home.InfoCard
import com.aliucord.manager.ui.screens.about.AboutScreen
import com.aliucord.manager.ui.screens.install.InstallScreen
@ -73,11 +72,6 @@ class HomeScreen : Screen {
onLaunchClick = model::launchAliucord,
onUninstallClick = model::uninstallAliucord
)
CommitList(
commits = model.commits,
onRetry = { model.fetchSupportedVersion() }
)
}
}
}

View file

@ -32,7 +32,6 @@ inline fun <T> Iterable<T>.joinToAnnotatedString(
* (assuming `annotation_name` is not changed between translations),
* when rendering [annotationHandler] will be called on each `annotation_name` and expected to return a target style on it.
*/
@Suppress("NOTHING_TO_INLINE")
@Composable
inline fun annotatingStringResource(
@StringRes id: Int,

View file

@ -29,7 +29,6 @@ accompanist-systemUiController = { module = "com.google.accompanist:accompanist-
androidx-activity = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "androidx-splashscreen" }
androidx-paging = "androidx.paging:paging-compose:1.0.0-alpha17" # TODO: remove paging
# Compose
compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" }
@ -79,7 +78,6 @@ androidx = [
"androidx-core",
"androidx-activity",
"androidx-splashscreen",
"androidx-paging",
]
compose = [
"compose-runtime",