Fixes #144. Added some logs as I'm not sure if it's a good solution.

This commit is contained in:
Amine Bou 2017-12-06 20:24:21 +01:00
parent 0107c3d7e2
commit eab9df8ed9
2 changed files with 73 additions and 42 deletions

View File

@ -25,8 +25,6 @@ import retrofit2.Response
class ReaderActivity : AppCompatActivity() {
private lateinit var allItems: ArrayList<Item>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Scoop.getInstance().apply(this)
@ -43,6 +41,18 @@ class ReaderActivity : AppCompatActivity() {
val userIdentifier = sharedPref.getString("unique_id", "")
val markOnScroll = sharedPref.getBoolean("mark_on_scroll", false)
if (allItems.isEmpty()) {
Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(
100,
"READER_ITEMS_EMPTY",
"Items empty when trying to open the Article Reader. Was (static) companion object field set ?"
)
Crashlytics.logException(Exception("Empty items on Reader Activity."))
finish()
}
val api = SelfossApi(
this,
this@ReaderActivity,
@ -50,7 +60,6 @@ class ReaderActivity : AppCompatActivity() {
sharedPref.getBoolean("should_log_everything", false)
)
allItems = intent.getParcelableArrayListExtra<Item>("allItems")
val currentItem = intent.getIntExtra("currentItem", 0)
var adapter = ScreenSlidePagerAdapter(supportFragmentManager)
@ -61,7 +70,8 @@ class ReaderActivity : AppCompatActivity() {
(indicator as CircleIndicator).setViewPager(pager)
if (markOnScroll) {
pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
pager.addOnPageChangeListener(
object : ViewPager.SimpleOnPageChangeListener() {
var isLastItem = false
override fun onPageSelected(position: Int) {
@ -86,15 +96,26 @@ class ReaderActivity : AppCompatActivity() {
"body success: ${response.body()?.success} " +
"body isSuccess: ${response.body()?.isSuccess}"
Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "READ_DEBUG_SUCCESS", message)
Crashlytics.log(
100,
"READ_DEBUG_SUCCESS",
message
)
Crashlytics.logException(Exception("Was success, but did it work ?"))
}
}
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
override fun onFailure(
call: Call<SuccessResponse>,
t: Throwable
) {
if (debugReadingItems) {
Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "READ_DEBUG_ERROR", t.message)
Crashlytics.log(
100,
"READ_DEBUG_ERROR",
t.message
)
Crashlytics.logException(t)
}
}
@ -102,7 +123,8 @@ class ReaderActivity : AppCompatActivity() {
)
}
}
})
}
)
}
}
@ -111,6 +133,11 @@ class ReaderActivity : AppCompatActivity() {
pager.clearOnPageChangeListeners()
}
override fun onStop() {
super.onStop()
allItems = ArrayList()
}
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
override fun getCount(): Int {
return allItems.size
@ -130,4 +157,8 @@ class ReaderActivity : AppCompatActivity() {
}
return super.onOptionsItemSelected(item)
}
companion object {
var allItems: ArrayList<Item> = ArrayList()
}
}

View File

@ -67,8 +67,8 @@ fun Context.openItemUrlInternally(
app: Activity
) {
if (articleViewer) {
ReaderActivity.allItems = allItems
val intent = Intent(this, ReaderActivity::class.java)
intent.putParcelableArrayListExtra("allItems", allItems)
intent.putExtra("currentItem", currentItem)
app.startActivity(intent)
} else {