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