From 7df10b076c555e403b30f6db34f7b1d7c41aee77 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 9 Jan 2023 23:27:11 -0500 Subject: [PATCH] Show the tracker name when showing error toast --- .../more/settings/screen/AboutScreen.kt | 1 - .../more/settings/screen/LicensesScreen.kt | 3 +- .../settings/screen/SettingsMainScreen.kt | 1 + .../settings/screen/SettingsSearchScreen.kt | 1 + .../ui/manga/track/TrackInfoDialog.kt | 62 +++++++++++++------ i18n/src/main/res/values/strings.xml | 1 + 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt index 8fcf2290f..01f763afd 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt @@ -25,7 +25,6 @@ import eu.kanade.presentation.components.LinkIcon import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.ScrollbarLazyColumn import eu.kanade.presentation.more.LogoHeader -import eu.kanade.presentation.more.about.LicensesScreen import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget import eu.kanade.presentation.util.LocalBackPress import eu.kanade.tachiyomi.BuildConfig diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt index 823b28125..09cbfc658 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/LicensesScreen.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.more.about +package eu.kanade.presentation.more.settings.screen import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme @@ -15,6 +15,7 @@ import eu.kanade.presentation.components.Scaffold import eu.kanade.tachiyomi.R class LicensesScreen : Screen { + @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt index d4a7e85b4..63b048625 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt @@ -54,6 +54,7 @@ import eu.kanade.presentation.util.LocalBackPress import eu.kanade.tachiyomi.R object SettingsMainScreen : Screen { + @Composable override fun Content() { Content(twoPane = false) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt index 5fde03572..7dd1543ea 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt @@ -59,6 +59,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.isLTR class SettingsSearchScreen : Screen { + @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt index 5f26e7300..8be920a43 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt @@ -84,6 +84,7 @@ data class TrackInfoDialogHomeScreen( private val mangaTitle: String, private val sourceId: Long, ) : Screen { + @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow @@ -174,27 +175,8 @@ data class TrackInfoDialogHomeScreen( ) : StateScreenModel(State()) { init { - // Refresh data coroutineScope.launch { - try { - val trackItems = getTracks.await(mangaId).mapToTrackItem() - val insertTrack = Injekt.get() - val getMangaWithChapters = Injekt.get() - val syncTwoWayService = Injekt.get() - trackItems.forEach { - val track = it.track ?: return@forEach - val domainTrack = it.service.refresh(track).toDomainTrack() ?: return@forEach - insertTrack.await(domainTrack) - - if (it.service is EnhancedTrackService) { - val allChapters = getMangaWithChapters.awaitChapters(mangaId) - syncTwoWayService.await(allChapters, domainTrack, it.service) - } - } - } catch (e: Exception) { - logcat(LogPriority.ERROR, e) { "Failed to refresh track data mangaId=$mangaId" } - withUIContext { Injekt.get().toast(e.message) } - } + refreshTrackers() } coroutineScope.launch { @@ -223,6 +205,46 @@ data class TrackInfoDialogHomeScreen( coroutineScope.launchNonCancellable { deleteTrack.await(mangaId, serviceId) } } + private suspend fun refreshTrackers() { + val insertTrack = Injekt.get() + val getMangaWithChapters = Injekt.get() + val syncTwoWayService = Injekt.get() + val context = Injekt.get() + + try { + val trackItems = getTracks.await(mangaId).mapToTrackItem() + for (trackItem in trackItems) { + try { + val track = trackItem.track ?: continue + val domainTrack = trackItem.service.refresh(track).toDomainTrack() ?: continue + insertTrack.await(domainTrack) + + if (trackItem.service is EnhancedTrackService) { + val allChapters = getMangaWithChapters.awaitChapters(mangaId) + syncTwoWayService.await(allChapters, domainTrack, trackItem.service) + } + } catch (e: Exception) { + logcat( + LogPriority.ERROR, + e, + ) { "Failed to refresh track data mangaId=$mangaId for service ${trackItem.service.id}" } + withUIContext { + context.toast( + context.getString( + R.string.track_error, + context.getString(trackItem.service.nameRes()), + e.message, + ), + ) + } + } + } + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) { "Failed to refresh track data mangaId=$mangaId" } + withUIContext { context.toast(e.message) } + } + } + private fun List.mapToTrackItem(): List { val dbTracks = map { it.toDbTrack() } val loggedServices = Injekt.get().services.filter { it.isLogged } diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 6014e6aba..1b054b386 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -713,6 +713,7 @@ Please login to MAL again Source is not supported No match found + %1$s error: %2$s Remove date? This will remove your previously selected start date from %s This will remove your previously selected finish date from %s