From 343700408287d44a94569aa27ded06f667d3a5c0 Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Mon, 1 Jan 2018 07:02:19 +0100 Subject: [PATCH] Multiple crash fixes. --- .../bou/readerforselfoss/AddSourceActivity.kt | 14 ++-- .../bou/readerforselfoss/ReaderActivity.kt | 2 +- .../fragments/ArticleFragment.kt | 50 ++++++++------ .../main/res/layout/activity_add_source.xml | 68 ++++++++++--------- 4 files changed, 74 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt index b32b22d..50c8e2f 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -27,6 +27,7 @@ import retrofit2.Response class AddSourceActivity : AppCompatActivity() { private var mSpoutsValue: String? = null + private lateinit var api: SelfossApi override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -37,8 +38,6 @@ class AddSourceActivity : AppCompatActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) - var api: SelfossApi? = null - try { val prefs = PreferenceManager.getDefaultSharedPreferences(this) api = SelfossApi( @@ -56,7 +55,10 @@ class AddSourceActivity : AppCompatActivity() { saveBtn.setOnClickListener { handleSaveSource(tags, nameInput.text.toString(), sourceUri.text.toString(), api!!) } + } + override fun onResume() { + super.onResume() val config = Config(this) if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) { @@ -74,9 +76,11 @@ class AddSourceActivity : AppCompatActivity() { ) { val spoutsKV = HashMap() spoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) { - val spoutName = (view as TextView).text.toString() - mSpoutsValue = spoutsKV[spoutName] + override fun onItemSelected(adapterView: AdapterView<*>, view: View?, i: Int, l: Long) { + if (view != null) { + val spoutName = (view as TextView).text.toString() + mSpoutsValue = spoutsKV[spoutName] + } } override fun onNothingSelected(adapterView: AdapterView<*>) { 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 253f21c..a67416b 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -193,7 +193,7 @@ class ReaderActivity : AppCompatActivity() { inflater.inflate(R.menu.reader_menu, menu) toolbarMenu = menu - if (allItems[currentItem].starred) { + if (!allItems.isEmpty() && allItems[currentItem].starred) { canRemoveFromFavorite() } else { canFavorite() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt index a76e5d5..6775c1a 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt @@ -174,12 +174,12 @@ class ArticleFragment : Fragment() { call: Call, response: Response ) { - if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { - rootView.source.text = response.body()!!.domain - rootView.titleView.text = response.body()!!.title - url = response.body()!!.url + try { + if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { + rootView.source.text = response.body()!!.domain + rootView.titleView.text = response.body()!!.title + url = response.body()!!.url - if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) { if (!useWebview) { htmlToTextview( response.body()!!.content, @@ -189,25 +189,33 @@ class ArticleFragment : Fragment() { } else { htmlToWebview(response.body()!!.content, prefs) } - } - if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) { - rootView.imageView.visibility = View.VISIBLE - Glide - .with(activity!!.baseContext) - .asBitmap() - .load(response.body()!!.lead_image_url) - .apply(RequestOptions.fitCenterTransform()) - .into(rootView.imageView) + if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) { + rootView.imageView.visibility = View.VISIBLE + Glide + .with(activity!!.baseContext) + .asBitmap() + .load(response.body()!!.lead_image_url) + .apply(RequestOptions.fitCenterTransform()) + .into(rootView.imageView) + } else { + rootView.imageView.visibility = View.GONE + } + + rootView.nestedScrollView.scrollTo(0, 0) + + rootView.progressBar.visibility = View.GONE } else { - rootView.imageView.visibility = View.GONE + openInBrowserAfterFailing(customTabsIntent) } - - rootView.nestedScrollView.scrollTo(0, 0) - - rootView.progressBar.visibility = View.GONE - } else { - openInBrowserAfterFailing(customTabsIntent) + } catch (e: Exception) { + Crashlytics.setUserIdentifier(prefs.getString("unique_id", "")) + Crashlytics.log( + 100, + "MERCURY_CONTENT_EXCEPTION", + "Fatal Exception on mercury response" + ) + Crashlytics.logException(e) } } diff --git a/app/src/main/res/layout/activity_add_source.xml b/app/src/main/res/layout/activity_add_source.xml index 6760986..bb8ef0f 100644 --- a/app/src/main/res/layout/activity_add_source.xml +++ b/app/src/main/res/layout/activity_add_source.xml @@ -1,36 +1,37 @@ - - + - - - - - - - - + + + + + + + + + + + + app:layout_constraintTop_toTopOf="parent" + tools:visibility="gone" /> - - - \ No newline at end of file + + \ No newline at end of file