Make sure some toasts are used in the main thread

This commit is contained in:
Jobobby04 2021-02-24 17:26:08 -05:00
parent 1b09eecfce
commit 9694c8310c
3 changed files with 22 additions and 12 deletions

View File

@ -56,10 +56,12 @@ class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartS
router.replaceTopController(transaction) router.replaceTopController(transaction)
} }
} else { } else {
if (results is SmartSearchPresenter.SearchResults.NotFound) { withUIContext {
applicationContext?.toast("Couldn't find the manga in the source!") if (results is SmartSearchPresenter.SearchResults.NotFound) {
} else { applicationContext?.toast("Couldn't find the manga in the source!")
applicationContext?.toast("Error performing automatic search!") } else {
applicationContext?.toast("Error performing automatic search!")
}
} }
val transaction = BrowseSourceController(source, smartSearchConfig.origTitle, smartSearchConfig).withFadeTransaction() val transaction = BrowseSourceController(source, smartSearchConfig.origTitle, smartSearchConfig).withFadeTransaction()

View File

@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.MangaDex import eu.kanade.tachiyomi.source.online.all.MangaDex
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import exh.source.getMainSource import exh.source.getMainSource
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -79,7 +80,9 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
val twoFactor = binding.twoFactorEdit.text?.toString() val twoFactor = binding.twoFactorEdit.text?.toString()
if (username.isNullOrBlank() || password.isNullOrBlank() || (binding.twoFactorCheck.isChecked && twoFactor.isNullOrBlank())) { if (username.isNullOrBlank() || password.isNullOrBlank() || (binding.twoFactorCheck.isChecked && twoFactor.isNullOrBlank())) {
errorResult() errorResult()
binding.root.context.toast(R.string.fields_cannot_be_blank) launchUI {
binding.root.context.toast(R.string.fields_cannot_be_blank)
}
return return
} }
@ -98,13 +101,15 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
if (result) { if (result) {
dialog?.dismiss() dialog?.dismiss()
preferences.setTrackCredentials(service, username, password) preferences.setTrackCredentials(service, username, password)
binding.root.context.toast(R.string.login_success) launchUI {
binding.root.context.toast(R.string.login_success)
}
} else { } else {
errorResult() errorResult()
} }
} catch (error: Exception) { } catch (error: Exception) {
errorResult() errorResult()
error.message?.let { binding.root.context.toast(it) } error.message?.let { launchUI { binding.root.context.toast(it) } }
} }
} }
} }

View File

@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.MangaDex import eu.kanade.tachiyomi.source.online.all.MangaDex
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.lang.launchNow import eu.kanade.tachiyomi.util.lang.launchNow
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.withIOContext import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import exh.source.getMainSource import exh.source.getMainSource
@ -53,13 +54,15 @@ class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
activity?.toast(R.string.logout_success) activity?.toast(R.string.logout_success)
(targetController as? Listener)?.siteLogoutDialogClosed(source) (targetController as? Listener)?.siteLogoutDialogClosed(source)
} else { } else {
if (exception != null) { launchUI {
activity?.toast(exception.message) if (exception != null) {
} else { activity?.toast(exception.message)
activity?.toast(R.string.unknown_error) } else {
activity?.toast(R.string.unknown_error)
}
} }
} }
} else activity?.toast("Mangadex not enabled") } else launchUI { activity?.toast("Mangadex not enabled") }
} }
} }
} }