Make the source manager surface suspend (#3869)
Assisted-by: Claude:claude-opus-5
This commit is contained in:
@@ -44,7 +44,7 @@ fun SourceIcon(
|
||||
source: Source,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val icon = source.icon
|
||||
val icon = produceState<ImageBitmap?>(initialValue = null, source.id) { value = source.icon() }.value
|
||||
|
||||
when {
|
||||
source.isStub && icon == null -> {
|
||||
|
||||
@@ -38,6 +38,8 @@ import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -170,12 +172,12 @@ fun DuplicateMangaDialog(
|
||||
@Composable
|
||||
private fun DuplicateMangaListItem(
|
||||
duplicate: MangaWithChapterCount,
|
||||
getSource: () -> Source,
|
||||
getSource: suspend () -> Source,
|
||||
onDismissRequest: () -> Unit,
|
||||
onOpenManga: () -> Unit,
|
||||
onMigrate: () -> Unit,
|
||||
) {
|
||||
val source = getSource()
|
||||
val source by produceState<Source?>(initialValue = null) { value = getSource() }
|
||||
val manga = duplicate.manga
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -277,7 +279,7 @@ private fun DuplicateMangaListItem(
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = source.name,
|
||||
text = source?.name.orEmpty(),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
|
||||
+3
-1
@@ -25,6 +25,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -105,11 +106,12 @@ object SettingsTrackingScreen : SearchableSettings {
|
||||
}
|
||||
}
|
||||
|
||||
val installedSources by produceState(initialValue = emptyList()) { value = sourceManager.getAll() }
|
||||
val enhancedTrackers = trackerManager.trackers
|
||||
.filter { it is EnhancedTracker }
|
||||
.partition { service ->
|
||||
val acceptedSources = (service as EnhancedTracker).getAcceptedSources()
|
||||
sourceManager.getAll().any { it::class.qualifiedName in acceptedSources }
|
||||
installedSources.any { it::class.qualifiedName in acceptedSources }
|
||||
}
|
||||
var enhancedTrackerInfo = stringResource(MR.strings.enhanced_tracking_info)
|
||||
if (enhancedTrackers.second.isNotEmpty()) {
|
||||
|
||||
+6
-2
@@ -20,6 +20,7 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import dev.zacsweers.metro.AppScope
|
||||
@@ -41,6 +42,7 @@ import eu.kanade.tachiyomi.util.system.workManager
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import tachiyomi.core.common.util.lang.launchIO
|
||||
import tachiyomi.i18n.MR
|
||||
import tachiyomi.presentation.core.components.LabeledCheckbox
|
||||
import tachiyomi.presentation.core.components.LazyColumnWithAction
|
||||
@@ -191,7 +193,9 @@ class RestoreBackupViewModel(
|
||||
}
|
||||
|
||||
init {
|
||||
validate(uri.toUri())
|
||||
viewModelScope.launchIO {
|
||||
validate(uri.toUri())
|
||||
}
|
||||
}
|
||||
|
||||
fun toggle(setter: (RestoreOptions, Boolean) -> RestoreOptions, enabled: Boolean) {
|
||||
@@ -210,7 +214,7 @@ class RestoreBackupViewModel(
|
||||
)
|
||||
}
|
||||
|
||||
private fun validate(uri: Uri) {
|
||||
private suspend fun validate(uri: Uri) {
|
||||
val results = try {
|
||||
backupFileValidator.validate(uri)
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user