diff --git a/CHANGELOG.md b/CHANGELOG.md index 1438b47..f597783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Toolbar in reader activity. +- Marking items as read on scroll (with settings to enable/disable). + **1.5.4.22** - You can now scroll through the loaded articles ! diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index f5887d1..27131bf 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -41,6 +41,7 @@ class ReaderActivity : AppCompatActivity() { val debugReadingItems = sharedPref.getBoolean("read_debug", false) val userIdentifier = sharedPref.getString("unique_id", "") + val markOnScroll = sharedPref.getBoolean("mark_on_scroll", false) val api = SelfossApi( this, @@ -59,50 +60,50 @@ class ReaderActivity : AppCompatActivity() { pager.setPageTransformer(true, DepthPageTransformer()) (indicator as CircleIndicator).setViewPager(pager) - pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { - var isLastItem = false + if (markOnScroll) { + pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { + var isLastItem = false - override fun onPageSelected(position: Int) { - isLastItem = (position === (allItems.size - 1)) - } - - override fun onPageScrollStateChanged(state: Int) { - if (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem)) { - api.markItem(allItems[pager.currentItem].id).enqueue( - object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (!response.succeeded() && debugReadingItems) { - val message = - "message: ${response.message()} " + - "response isSuccess: ${response.isSuccessful} " + - "response code: ${response.code()} " + - "response message: ${response.message()} " + - "response errorBody: ${response.errorBody()?.string()} " + - "body success: ${response.body()?.success} " + - "body isSuccess: ${response.body()?.isSuccess}" - Crashlytics.setUserIdentifier(userIdentifier) - Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) - Crashlytics.logException(Exception("Was success, but did it work ?")) - } - } - - override fun onFailure(call: Call, t: Throwable) { - if (debugReadingItems) { - Crashlytics.setUserIdentifier(userIdentifier) - Crashlytics.log(100, "READ_DEBUG_ERROR", t.message) - Crashlytics.logException(t) - } - } - } - ) + override fun onPageSelected(position: Int) { + isLastItem = (position === (allItems.size - 1)) } - } - }) + override fun onPageScrollStateChanged(state: Int) { + if (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem)) { + api.markItem(allItems[pager.currentItem].id).enqueue( + object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (!response.succeeded() && debugReadingItems) { + val message = + "message: ${response.message()} " + + "response isSuccess: ${response.isSuccessful} " + + "response code: ${response.code()} " + + "response message: ${response.message()} " + + "response errorBody: ${response.errorBody()?.string()} " + + "body success: ${response.body()?.success} " + + "body isSuccess: ${response.body()?.isSuccess}" + Crashlytics.setUserIdentifier(userIdentifier) + Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) + Crashlytics.logException(Exception("Was success, but did it work ?")) + } + } + override fun onFailure(call: Call, t: Throwable) { + if (debugReadingItems) { + Crashlytics.setUserIdentifier(userIdentifier) + Crashlytics.log(100, "READ_DEBUG_ERROR", t.message) + Crashlytics.logException(t) + } + } + } + ) + } + } + }) + } } override fun onPause() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 56b4ebf..2c428b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -161,4 +161,5 @@ Read more Open in browser Share + Mark articles as read when scrolling between articles. \ No newline at end of file diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index f007212..ac8b78c 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -81,5 +81,9 @@ android:summaryOff="@string/pref_switch_actions_tap_off" android:summaryOn="@string/pref_switch_actions_tap_on" android:title="@string/pref_switch_actions_tap_title" /> +