From bc4fd7bb408078881f664f30a1ae2a8d7719ecd7 Mon Sep 17 00:00:00 2001 From: jmir1 Date: Fri, 26 Nov 2021 00:35:52 +0100 Subject: [PATCH] show error messages when playing anime --- .../tachiyomi/ui/anime/AnimeController.kt | 20 ++++-- .../tachiyomi/ui/player/EpisodeLoader.kt | 13 +--- .../tachiyomi/ui/player/PlayerActivity.kt | 66 ++++++++----------- 3 files changed, 46 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt index 027d01f158..6798c3c081 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt @@ -1043,10 +1043,14 @@ class AnimeController : } if (!useInternal) launchIO { - val video = EpisodeLoader.getLink(episode, anime!!, source!!).awaitSingle() + val video = try { + EpisodeLoader.getLink(episode, anime!!, source!!).awaitSingle() + } catch (e: Exception) { + return@launchIO makeErrorToast(context, e) + } if (video != null) { val videoUri = video.uri - val videoUrl = Uri.parse(video.videoUrl) + val videoUrl = Uri.parse(video.videoUrl ?: return@launchIO makeErrorToast(context, Exception("video URL is null."))) currentExtEpisode = episode val pkgName = preferences.externalPlayerPreference() @@ -1055,15 +1059,23 @@ class AnimeController : } else videoUri ?: videoUrl val extIntent = getExternalIntent(pkgName, uri, episode, video, context) - try { startActivityForResult(extIntent, REQUEST_EXTERNAL) } catch (t: Throwable) { launchUI { context.toast("Cannot open episode") } } + try { + startActivityForResult(extIntent, REQUEST_EXTERNAL) + } catch (e: Exception) { + makeErrorToast(context, e) + } } else { - launchUI { context.toast("Cannot open episode") } + makeErrorToast(context, Exception("Couldn't find any video links.")) } } else { startActivity(intent) } } + private fun makeErrorToast(context: Context, e: Exception?) { + launchUI { context.toast(e?.message ?: "Cannot open episode") } + } + private fun getExternalIntent(pkgName: String?, uri: Uri, episode: Episode, video: Video, context: Context): Intent { return if (pkgName.isNullOrEmpty()) { Intent(Intent.ACTION_VIEW).apply { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/EpisodeLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/EpisodeLoader.kt index 2c3a1bd409..24651f7fb2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/EpisodeLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/EpisodeLoader.kt @@ -39,16 +39,13 @@ class EpisodeLoader { val isDownloaded = downloadManager.isEpisodeDownloaded(episode, anime, true) return when { isDownloaded -> isDownloaded(episode, anime, source, downloadManager).map { - if (it.isEmpty()) null - else it.first() + it.firstOrNull() } source is AnimeHttpSource -> isHttp(episode, source).map { - if (it.isEmpty()) null - else it.first() + it.firstOrNull() } source is LocalAnimeSource -> isLocal(episode).map { - if (it.isEmpty()) null - else it.first() + it.firstOrNull() } else -> error("source not supported") } @@ -56,10 +53,6 @@ class EpisodeLoader { private fun isHttp(episode: Episode, source: AnimeHttpSource): Observable> { return source.fetchVideoList(episode) - .onErrorReturn { - errorMessage = it.message ?: "error getting links" - emptyList() - } .flatMapIterable { it } .flatMap { source.fetchUrlFromVideo(it) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt index 4740f06c60..d2c6310a17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt @@ -77,9 +77,7 @@ import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.widget.listener.SimpleSeekBarListener import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.runBlocking import logcat.LogPriority -import rx.Observable import rx.schedulers.Schedulers import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -101,7 +99,6 @@ class PlayerActivity : AppCompatActivity() { private val cacheSize = 100L * 1024L * 1024L // 100 MB private lateinit var simpleCache: SimpleCache private lateinit var cacheFactory: CacheDataSource.Factory - private var message: String? = null private lateinit var mediaSourceFactory: MediaSourceFactory private lateinit var playerView: DoubleTapPlayerView private lateinit var youTubeDoubleTap: YouTubeOverlay @@ -120,7 +117,6 @@ class PlayerActivity : AppCompatActivity() { private val defaultUserAgentString = WebSettings.getDefaultUserAgent(this) private lateinit var uri: String private var videos = emptyList