From 299478e8403c2b93f1ad34b55dd3ca7a6484661a Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 2 Jul 2017 07:18:56 +0200 Subject: [PATCH] This should fix #35 --- .../amine/bou/readerforselfoss/ReaderActivity.kt | 15 ++++++++++----- .../bou/readerforselfoss/utils/LinksUtils.kt | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index d02ce21..ac11280 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -62,8 +62,13 @@ class ReaderActivity : DragDismissActivity() { if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { source.text = response.body()!!.domain title.text = response.body()!!.title - if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) - content.setHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true)) + if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) { + try { + content.setHtml(response.body()!!.content, HtmlHttpImageGetter(content, null, true)) + } catch (e: IndexOutOfBoundsException) { + openInBrowserAfterFailing() + } + } if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) Glide .with(applicationContext) @@ -84,12 +89,12 @@ class ReaderActivity : DragDismissActivity() { } hideProgressBar() - } else errorAfterMercuryCall() + } else openInBrowserAfterFailing() } - override fun onFailure(call: Call, t: Throwable) = errorAfterMercuryCall() + override fun onFailure(call: Call, t: Throwable) = openInBrowserAfterFailing() - private fun errorAfterMercuryCall() { + private fun openInBrowserAfterFailing() { CustomTabActivityHelper.openCustomTab(this@ReaderActivity, customTabsIntent, Uri.parse(url) ) { _, uri -> val intent = Intent(Intent.ACTION_VIEW, uri) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt index 752b8ae..dbc2d6b 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt @@ -51,10 +51,10 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent { } fun Context.openItemUrl(i: Item, - customTabsIntent: CustomTabsIntent, - internalBrowser: Boolean, - articleViewer: Boolean, - app: Activity) { + customTabsIntent: CustomTabsIntent, + internalBrowser: Boolean, + articleViewer: Boolean, + app: Activity) { if (!internalBrowser) { val intent = Intent(Intent.ACTION_VIEW) intent.data = Uri.parse(i.getLinkDecoded())