Multiple crash fixes.

This commit is contained in:
Amine Bou 2018-01-01 07:02:19 +01:00
parent dcf620af87
commit 3437004082
4 changed files with 74 additions and 60 deletions

View File

@ -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,10 +76,12 @@ class AddSourceActivity : AppCompatActivity() {
) {
val spoutsKV = HashMap<String, String>()
spoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) {
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<*>) {
mSpoutsValue = null

View File

@ -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()

View File

@ -174,12 +174,12 @@ class ArticleFragment : Fragment() {
call: Call<ParsedContent>,
response: Response<ParsedContent>
) {
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,7 +189,6 @@ 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
@ -209,6 +208,15 @@ class ArticleFragment : Fragment() {
} 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)
}
}
override fun onFailure(

View File

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity"
tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -21,16 +24,14 @@
</android.support.design.widget.AppBarLayout>
<android.support.constraint.ConstraintLayout
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
@ -119,19 +120,20 @@
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
app:layout_constraintVertical_bias="0.0"/>
</android.support.constraint.ConstraintLayout>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progress"
app:layout_constraintTop_toTopOf="parent"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="visible"/>
</android.support.constraint.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent"
tools:visibility="gone" />
</LinearLayout>
</ScrollView>