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() { class AddSourceActivity : AppCompatActivity() {
private var mSpoutsValue: String? = null private var mSpoutsValue: String? = null
private lateinit var api: SelfossApi
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -37,8 +38,6 @@ class AddSourceActivity : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
var api: SelfossApi? = null
try { try {
val prefs = PreferenceManager.getDefaultSharedPreferences(this) val prefs = PreferenceManager.getDefaultSharedPreferences(this)
api = SelfossApi( api = SelfossApi(
@ -56,7 +55,10 @@ class AddSourceActivity : AppCompatActivity() {
saveBtn.setOnClickListener { saveBtn.setOnClickListener {
handleSaveSource(tags, nameInput.text.toString(), sourceUri.text.toString(), api!!) handleSaveSource(tags, nameInput.text.toString(), sourceUri.text.toString(), api!!)
} }
}
override fun onResume() {
super.onResume()
val config = Config(this) val config = Config(this)
if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) { if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) {
@ -74,9 +76,11 @@ class AddSourceActivity : AppCompatActivity() {
) { ) {
val spoutsKV = HashMap<String, String>() val spoutsKV = HashMap<String, String>()
spoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { 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) {
val spoutName = (view as TextView).text.toString() if (view != null) {
mSpoutsValue = spoutsKV[spoutName] val spoutName = (view as TextView).text.toString()
mSpoutsValue = spoutsKV[spoutName]
}
} }
override fun onNothingSelected(adapterView: AdapterView<*>) { override fun onNothingSelected(adapterView: AdapterView<*>) {

View File

@ -193,7 +193,7 @@ class ReaderActivity : AppCompatActivity() {
inflater.inflate(R.menu.reader_menu, menu) inflater.inflate(R.menu.reader_menu, menu)
toolbarMenu = menu toolbarMenu = menu
if (allItems[currentItem].starred) { if (!allItems.isEmpty() && allItems[currentItem].starred) {
canRemoveFromFavorite() canRemoveFromFavorite()
} else { } else {
canFavorite() canFavorite()

View File

@ -174,12 +174,12 @@ class ArticleFragment : Fragment() {
call: Call<ParsedContent>, call: Call<ParsedContent>,
response: Response<ParsedContent> response: Response<ParsedContent>
) { ) {
if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { try {
rootView.source.text = response.body()!!.domain if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) {
rootView.titleView.text = response.body()!!.title rootView.source.text = response.body()!!.domain
url = response.body()!!.url rootView.titleView.text = response.body()!!.title
url = response.body()!!.url
if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) {
if (!useWebview) { if (!useWebview) {
htmlToTextview( htmlToTextview(
response.body()!!.content, response.body()!!.content,
@ -189,25 +189,33 @@ class ArticleFragment : Fragment() {
} else { } else {
htmlToWebview(response.body()!!.content, prefs) htmlToWebview(response.body()!!.content, prefs)
} }
}
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) { if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) {
rootView.imageView.visibility = View.VISIBLE rootView.imageView.visibility = View.VISIBLE
Glide Glide
.with(activity!!.baseContext) .with(activity!!.baseContext)
.asBitmap() .asBitmap()
.load(response.body()!!.lead_image_url) .load(response.body()!!.lead_image_url)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(rootView.imageView) .into(rootView.imageView)
} else {
rootView.imageView.visibility = View.GONE
}
rootView.nestedScrollView.scrollTo(0, 0)
rootView.progressBar.visibility = View.GONE
} else { } else {
rootView.imageView.visibility = View.GONE openInBrowserAfterFailing(customTabsIntent)
} }
} catch (e: Exception) {
rootView.nestedScrollView.scrollTo(0, 0) Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
Crashlytics.log(
rootView.progressBar.visibility = View.GONE 100,
} else { "MERCURY_CONTENT_EXCEPTION",
openInBrowserAfterFailing(customTabsIntent) "Fatal Exception on mercury response"
)
Crashlytics.logException(e)
} }
} }

View File

@ -1,36 +1,37 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity" tools:context="apps.amine.bou.readerforselfoss.AddSourceActivity">
android:orientation="vertical"> <LinearLayout
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent" 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_height="match_parent"
android:layout_width="match_parent"> android:orientation="vertical">
<android.support.constraint.ConstraintLayout
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent" 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_height="match_parent"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
@ -119,19 +120,20 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
app:layout_constraintVertical_bias="0.0"/> app:layout_constraintVertical_bias="0.0"/>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
<ProgressBar <ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progress" 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_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent"
android:visibility="visible"/> tools:visibility="gone" />
</android.support.constraint.ConstraintLayout> </LinearLayout>
</ScrollView>
</LinearLayout>