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,9 +76,11 @@ class AddSourceActivity : AppCompatActivity() {
) {
val spoutsKV = HashMap<String, String>()
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<*>) {

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>
) {
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)
}
}

View File

@ -1,36 +1,37 @@
<?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"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ToolBarStyle"
app:popupTheme="?attr/toolbarPopupTheme" />
</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:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ToolBarStyle"
app:popupTheme="?attr/toolbarPopupTheme" />
</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"
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"/>
app:layout_constraintTop_toTopOf="parent"
tools:visibility="gone" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>