diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrationListScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrationListScreen.kt index 01b6ee9d66..d0f1e3d8b3 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrationListScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrationListScreen.kt @@ -51,6 +51,9 @@ fun MigrationListScreen( onMigrationItemClick: (Manga) -> Unit, openMigrationDialog: (Boolean) -> Unit, skipManga: (Long) -> Unit, + // KMK --> + cancelManga: (Long) -> Unit, + // KMK <-- searchManually: (MigratingManga) -> Unit, migrateNow: (Long) -> Unit, copyNow: (Long) -> Unit, @@ -138,6 +141,9 @@ fun MigrationListScreen( .weight(0.2f), result = result, skipManga = { skipManga(migrationItem.manga.id) }, + // KMK --> + cancelManga = { cancelManga(migrationItem.manga.id) }, + // KMK <-- searchManually = { searchManually(migrationItem) }, migrateNow = { migrateNow(migrationItem.manga.id) diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/MigrationActionIcon.kt b/app/src/main/java/eu/kanade/presentation/browse/components/MigrationActionIcon.kt index e41c4eb195..2ea286bf5a 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/MigrationActionIcon.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/MigrationActionIcon.kt @@ -27,6 +27,9 @@ fun MigrationActionIcon( modifier: Modifier, result: MigratingManga.SearchResult, skipManga: () -> Unit, + // KMK --> + cancelManga: () -> Unit, + // KMK <-- searchManually: () -> Unit, migrateNow: () -> Unit, copyNow: () -> Unit, @@ -36,7 +39,9 @@ fun MigrationActionIcon( Box(modifier) { if (result is MigratingManga.SearchResult.Searching) { - IconButton(onClick = skipManga) { + // KMK --> + IconButton(onClick = cancelManga) { + // KMK <-- Icon( imageVector = Icons.Outlined.Close, contentDescription = stringResource(SYMR.strings.action_stop), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigratingManga.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigratingManga.kt index 8791145c92..765085a904 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigratingManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigratingManga.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.migration.advanced.process import android.content.Context import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.flow.MutableStateFlow @@ -20,6 +21,10 @@ class MigratingManga( ) { val migrationScope = CoroutineScope(parentContext + SupervisorJob() + Dispatchers.Default) + // KMK --> + lateinit var searchingJob: Deferred + // KMK <-- + val searchResult = MutableStateFlow(SearchResult.Searching) // diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreen.kt index 806e45e38e..d51400ad20 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreen.kt @@ -106,6 +106,9 @@ class MigrationListScreen(private val config: MigrationProcedureConfig) : Screen }, openMigrationDialog = screenModel::openMigrateDialog, skipManga = { screenModel.removeManga(it) }, + // KMK --> + cancelManga = { screenModel.cancelManga(it) }, + // KMK <-- searchManually = { migrationItem -> val sources = screenModel.getMigrationSources() val validSources = if (sources.size == 1) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreenModel.kt index d59b2ae876..1e54939e2c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/advanced/process/MigrationListScreenModel.kt @@ -180,7 +180,9 @@ class MigrationListScreenModel( val mangaSource = sourceManager.getOrStub(mangaObj.source) val result = try { - manga.migrationScope.async { + // KMK --> + manga.searchingJob = manga.migrationScope.async { + // KMK <-- val validSources = if (sources.size == 1) { sources } else { @@ -288,7 +290,10 @@ class MigrationListScreenModel( null } - }.await() + } + // KMK --> + manga.searchingJob.await() + // KMK <-- } catch (e: CancellationException) { // Ignore canceled migrations continue @@ -434,6 +439,7 @@ class MigrationListScreenModel( updateManga.awaitAll(listOfNotNull(mangaUpdate, prevMangaUpdate)) } + /** Set a manga picked from manual search to be used as migration target */ fun useMangaForMigration(context: Context, newMangaId: Long, selectedMangaId: Long) { val migratingManga = migratingItems.value.orEmpty().find { it.manga.id == selectedMangaId } ?: return @@ -545,6 +551,19 @@ class MigrationListScreenModel( } } + // KMK --> + /** Cancel searching without remove it from list so user can perform manual search */ + fun cancelManga(mangaId: Long) { + screenModelScope.launchIO { + val item = migratingItems.value.orEmpty().find { it.manga.id == mangaId } + ?: return@launchIO + item.searchingJob.cancel() + item.searchResult.value = SearchResult.NotFound + sourceFinished() + } + } + // KMK <-- + fun removeManga(mangaId: Long) { screenModelScope.launchIO { val item = migratingItems.value.orEmpty().find { it.manga.id == mangaId }