Fixes #144. Added some logs as I'm not sure if it's a good solution.
This commit is contained in:
parent
0107c3d7e2
commit
eab9df8ed9
@ -25,8 +25,6 @@ import retrofit2.Response
|
|||||||
|
|
||||||
class ReaderActivity : AppCompatActivity() {
|
class ReaderActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var allItems: ArrayList<Item>
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
Scoop.getInstance().apply(this)
|
Scoop.getInstance().apply(this)
|
||||||
@ -43,6 +41,18 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
val userIdentifier = sharedPref.getString("unique_id", "")
|
val userIdentifier = sharedPref.getString("unique_id", "")
|
||||||
val markOnScroll = sharedPref.getBoolean("mark_on_scroll", false)
|
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(
|
val api = SelfossApi(
|
||||||
this,
|
this,
|
||||||
this@ReaderActivity,
|
this@ReaderActivity,
|
||||||
@ -50,7 +60,6 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
sharedPref.getBoolean("should_log_everything", false)
|
sharedPref.getBoolean("should_log_everything", false)
|
||||||
)
|
)
|
||||||
|
|
||||||
allItems = intent.getParcelableArrayListExtra<Item>("allItems")
|
|
||||||
val currentItem = intent.getIntExtra("currentItem", 0)
|
val currentItem = intent.getIntExtra("currentItem", 0)
|
||||||
|
|
||||||
var adapter = ScreenSlidePagerAdapter(supportFragmentManager)
|
var adapter = ScreenSlidePagerAdapter(supportFragmentManager)
|
||||||
@ -61,48 +70,61 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
(indicator as CircleIndicator).setViewPager(pager)
|
(indicator as CircleIndicator).setViewPager(pager)
|
||||||
|
|
||||||
if (markOnScroll) {
|
if (markOnScroll) {
|
||||||
pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
|
pager.addOnPageChangeListener(
|
||||||
var isLastItem = false
|
object : ViewPager.SimpleOnPageChangeListener() {
|
||||||
|
var isLastItem = false
|
||||||
|
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
isLastItem = (position === (allItems.size - 1))
|
isLastItem = (position === (allItems.size - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
if (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem)) {
|
if (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem)) {
|
||||||
api.markItem(allItems[pager.currentItem].id).enqueue(
|
api.markItem(allItems[pager.currentItem].id).enqueue(
|
||||||
object : Callback<SuccessResponse> {
|
object : Callback<SuccessResponse> {
|
||||||
override fun onResponse(
|
override fun onResponse(
|
||||||
call: Call<SuccessResponse>,
|
call: Call<SuccessResponse>,
|
||||||
response: Response<SuccessResponse>
|
response: Response<SuccessResponse>
|
||||||
) {
|
) {
|
||||||
if (!response.succeeded() && debugReadingItems) {
|
if (!response.succeeded() && debugReadingItems) {
|
||||||
val message =
|
val message =
|
||||||
"message: ${response.message()} " +
|
"message: ${response.message()} " +
|
||||||
"response isSuccess: ${response.isSuccessful} " +
|
"response isSuccess: ${response.isSuccessful} " +
|
||||||
"response code: ${response.code()} " +
|
"response code: ${response.code()} " +
|
||||||
"response message: ${response.message()} " +
|
"response message: ${response.message()} " +
|
||||||
"response errorBody: ${response.errorBody()?.string()} " +
|
"response errorBody: ${response.errorBody()?.string()} " +
|
||||||
"body success: ${response.body()?.success} " +
|
"body success: ${response.body()?.success} " +
|
||||||
"body isSuccess: ${response.body()?.isSuccess}"
|
"body isSuccess: ${response.body()?.isSuccess}"
|
||||||
Crashlytics.setUserIdentifier(userIdentifier)
|
Crashlytics.setUserIdentifier(userIdentifier)
|
||||||
Crashlytics.log(100, "READ_DEBUG_SUCCESS", message)
|
Crashlytics.log(
|
||||||
Crashlytics.logException(Exception("Was success, but did it work ?"))
|
100,
|
||||||
|
"READ_DEBUG_SUCCESS",
|
||||||
|
message
|
||||||
|
)
|
||||||
|
Crashlytics.logException(Exception("Was success, but did it work ?"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(
|
||||||
|
call: Call<SuccessResponse>,
|
||||||
|
t: Throwable
|
||||||
|
) {
|
||||||
|
if (debugReadingItems) {
|
||||||
|
Crashlytics.setUserIdentifier(userIdentifier)
|
||||||
|
Crashlytics.log(
|
||||||
|
100,
|
||||||
|
"READ_DEBUG_ERROR",
|
||||||
|
t.message
|
||||||
|
)
|
||||||
|
Crashlytics.logException(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
}
|
||||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
}
|
||||||
if (debugReadingItems) {
|
|
||||||
Crashlytics.setUserIdentifier(userIdentifier)
|
|
||||||
Crashlytics.log(100, "READ_DEBUG_ERROR", t.message)
|
|
||||||
Crashlytics.logException(t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +133,11 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
pager.clearOnPageChangeListeners()
|
pager.clearOnPageChangeListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
allItems = ArrayList()
|
||||||
|
}
|
||||||
|
|
||||||
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
|
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
|
||||||
override fun getCount(): Int {
|
override fun getCount(): Int {
|
||||||
return allItems.size
|
return allItems.size
|
||||||
@ -130,4 +157,8 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var allItems: ArrayList<Item> = ArrayList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ fun Context.openItemUrlInternally(
|
|||||||
app: Activity
|
app: Activity
|
||||||
) {
|
) {
|
||||||
if (articleViewer) {
|
if (articleViewer) {
|
||||||
|
ReaderActivity.allItems = allItems
|
||||||
val intent = Intent(this, ReaderActivity::class.java)
|
val intent = Intent(this, ReaderActivity::class.java)
|
||||||
intent.putParcelableArrayListExtra("allItems", allItems)
|
|
||||||
intent.putExtra("currentItem", currentItem)
|
intent.putExtra("currentItem", currentItem)
|
||||||
app.startActivity(intent)
|
app.startActivity(intent)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user