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
|
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 ->
|
||||||
when (repo.name) {
|
val list = when (repo.name) {
|
||||||
ghCli -> {
|
ghCli -> cliContributorsList
|
||||||
repo.contributors.sortedByDescending {
|
ghPatcher -> patcherContributorsList
|
||||||
it.username
|
ghPatches -> patchesContributorsList
|
||||||
}
|
ghIntegrations -> integrationsContributorsList
|
||||||
cliContributorsList.addAll(repo.contributors)
|
ghManager -> managerContributorsList
|
||||||
}
|
else -> return@forEach
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
list.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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user