Added setting to enable/disable the mark on swipe.

This commit is contained in:
Amine Bou 2017-12-05 21:40:54 +01:00
parent 297f797b97
commit 9458b1834b
4 changed files with 48 additions and 40 deletions

View File

@ -10,6 +10,8 @@
- Toolbar in reader activity. - Toolbar in reader activity.
- Marking items as read on scroll (with settings to enable/disable).
**1.5.4.22** **1.5.4.22**
- You can now scroll through the loaded articles ! - You can now scroll through the loaded articles !

View File

@ -41,6 +41,7 @@ class ReaderActivity : AppCompatActivity() {
val debugReadingItems = sharedPref.getBoolean("read_debug", false) val debugReadingItems = sharedPref.getBoolean("read_debug", false)
val userIdentifier = sharedPref.getString("unique_id", "") val userIdentifier = sharedPref.getString("unique_id", "")
val markOnScroll = sharedPref.getBoolean("mark_on_scroll", false)
val api = SelfossApi( val api = SelfossApi(
this, this,
@ -59,50 +60,50 @@ class ReaderActivity : AppCompatActivity() {
pager.setPageTransformer(true, DepthPageTransformer()) pager.setPageTransformer(true, DepthPageTransformer())
(indicator as CircleIndicator).setViewPager(pager) (indicator as CircleIndicator).setViewPager(pager)
pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { if (markOnScroll) {
var isLastItem = false pager.addOnPageChangeListener(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) {
if (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem)) {
api.markItem(allItems[pager.currentItem].id).enqueue(
object : Callback<SuccessResponse> {
override fun onResponse(
call: Call<SuccessResponse>,
response: Response<SuccessResponse>
) {
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<SuccessResponse>, t: Throwable) {
if (debugReadingItems) {
Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "READ_DEBUG_ERROR", t.message)
Crashlytics.logException(t)
}
}
}
)
} }
}
})
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<SuccessResponse> {
override fun onResponse(
call: Call<SuccessResponse>,
response: Response<SuccessResponse>
) {
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<SuccessResponse>, t: Throwable) {
if (debugReadingItems) {
Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "READ_DEBUG_ERROR", t.message)
Crashlytics.logException(t)
}
}
}
)
}
}
})
}
} }
override fun onPause() { override fun onPause() {

View File

@ -161,4 +161,5 @@
<string name="reader_action_more">Read more</string> <string name="reader_action_more">Read more</string>
<string name="reader_action_open">Open in browser</string> <string name="reader_action_open">Open in browser</string>
<string name="reader_action_share">Share</string> <string name="reader_action_share">Share</string>
<string name="pref_switch_actions_pager_scroll">Mark articles as read when scrolling between articles.</string>
</resources> </resources>

View File

@ -81,5 +81,9 @@
android:summaryOff="@string/pref_switch_actions_tap_off" android:summaryOff="@string/pref_switch_actions_tap_off"
android:summaryOn="@string/pref_switch_actions_tap_on" android:summaryOn="@string/pref_switch_actions_tap_on"
android:title="@string/pref_switch_actions_tap_title" /> android:title="@string/pref_switch_actions_tap_title" />
<SwitchPreference
android:defaultValue="false"
android:key="mark_on_scroll"
android:title="@string/pref_switch_actions_pager_scroll" />
</PreferenceScreen> </PreferenceScreen>