mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-25 14:45:59 +03:00
Show the tracker name when showing error toast
This commit is contained in:
parent
2245658363
commit
7df10b076c
6 changed files with 47 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Model.State>(State()) {
|
||||
|
||||
init {
|
||||
// Refresh data
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
val trackItems = getTracks.await(mangaId).mapToTrackItem()
|
||||
val insertTrack = Injekt.get<InsertTrack>()
|
||||
val getMangaWithChapters = Injekt.get<GetMangaWithChapters>()
|
||||
val syncTwoWayService = Injekt.get<SyncChaptersWithTrackServiceTwoWay>()
|
||||
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<Application>().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<InsertTrack>()
|
||||
val getMangaWithChapters = Injekt.get<GetMangaWithChapters>()
|
||||
val syncTwoWayService = Injekt.get<SyncChaptersWithTrackServiceTwoWay>()
|
||||
val context = Injekt.get<Application>()
|
||||
|
||||
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<eu.kanade.domain.track.model.Track>.mapToTrackItem(): List<TrackItem> {
|
||||
val dbTracks = map { it.toDbTrack() }
|
||||
val loggedServices = Injekt.get<TrackManager>().services.filter { it.isLogged }
|
||||
|
|
|
@ -713,6 +713,7 @@
|
|||
<string name="myanimelist_relogin">Please login to MAL again</string>
|
||||
<string name="source_unsupported">Source is not supported</string>
|
||||
<string name="error_no_match">No match found</string>
|
||||
<string name="track_error">%1$s error: %2$s</string>
|
||||
<string name="track_remove_date_conf_title">Remove date?</string>
|
||||
<string name="track_remove_start_date_conf_text">This will remove your previously selected start date from %s</string>
|
||||
<string name="track_remove_finish_date_conf_text">This will remove your previously selected finish date from %s</string>
|
||||
|
|
Loading…
Reference in a new issue