fix: contributors loading lag

This commit is contained in:
Canny 2022-12-23 22:09:19 +03:00
parent 45829d00bb
commit 73e61a7055
No known key found for this signature in database
GPG Key ID: 395CCB0AA979F27B

View File

@ -1,7 +1,6 @@
package app.revanced.manager.ui.viewmodel
import android.app.Application
import android.util.Log
import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@ -9,7 +8,9 @@ import app.revanced.manager.domain.repository.ReVancedRepositoryImpl
import app.revanced.manager.network.dto.ReVancedContributor
import app.revanced.manager.network.utils.getOrNull
import app.revanced.manager.util.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class ContributorsViewModel(
private val app: Application, private val reVancedAPI: ReVancedRepositoryImpl
@ -20,48 +21,25 @@ class ContributorsViewModel(
val managerContributorsList = mutableStateListOf<ReVancedContributor>()
val integrationsContributorsList = mutableStateListOf<ReVancedContributor>()
private fun loadContributors() {
viewModelScope.launch {
val contributors = reVancedAPI.getContributors().getOrNull() ?: return@launch
contributors.repositories.forEach { repo ->
when (repo.name) {
ghCli -> {
repo.contributors.sortedByDescending {
it.username
}
cliContributorsList.addAll(repo.contributors)
}
ghPatcher -> {
repo.contributors.sortedByDescending {
it.username
}
patcherContributorsList.addAll(repo.contributors)
}
ghPatches -> {
repo.contributors.sortedByDescending {
it.username
}
patchesContributorsList.addAll(repo.contributors)
}
ghIntegrations -> {
repo.contributors.sortedByDescending {
it.username
}
integrationsContributorsList.addAll(repo.contributors)
}
ghManager -> {
repo.contributors.sortedByDescending {
it.username
}
managerContributorsList.addAll(repo.contributors)
}
}
private suspend fun loadContributors() = withContext(Dispatchers.IO) {
val contributors = reVancedAPI.getContributors().getOrNull() ?: return@withContext
contributors.repositories.forEach { repo ->
val list = when (repo.name) {
ghCli -> cliContributorsList
ghPatcher -> patcherContributorsList
ghPatches -> patchesContributorsList
ghIntegrations -> integrationsContributorsList
ghManager -> managerContributorsList
else -> return@forEach
}
withContext(Dispatchers.Main) {
list.addAll(repo.contributors)
}
}
}
fun openUserProfile(username: String) {
app.openUrl("https://github.com/${username}")
app.openUrl("https://github.com/$username")
}
init {