mirror of
https://github.com/revanced/revanced-manager-compose-old.git
synced 2025-04-29 22:14:28 +02:00
fix: contributors loading lag
This commit is contained in:
parent
45829d00bb
commit
73e61a7055
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user