Skip to content

Commit

Permalink
#282 Implement setting for swithcing swipe mode (chapter / page / none)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Jan 3, 2025
1 parent 83c492d commit 81232ee
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ import android.view.ViewConfiguration

import net.bible.android.control.event.ABEventBus
import net.bible.android.view.util.TouchOwner
import net.bible.service.common.BibleViewSwipeMode
import net.bible.service.common.CommonUtils
import kotlin.math.abs

/** Listen for side swipes to change chapter. This listener class seems to work better that subclassing WebView.
*
* @author Martin Denham [mjdenham at gmail dot com]
*/
class BibleGestureListener(private val mainBibleActivity: MainBibleActivity) : SimpleOnGestureListener() {
class BibleGestureListener(
private val mainBibleActivity: MainBibleActivity,
val bibleView: BibleView
) : SimpleOnGestureListener() {
private val scaledMinimumDistance: Int = CommonUtils.convertDipsToPx(DISTANCE_DIP)
private val scaledMinimumFullScreenScrollDistance: Int = CommonUtils.convertDipsToPx(SCROLL_DIP)

Expand Down Expand Up @@ -87,10 +91,17 @@ class BibleGestureListener(private val mainBibleActivity: MainBibleActivity) : S
goNext = !goNext

if (goNext) {
mainBibleActivity.next()
when(CommonUtils.settings.bibleViewSwipeMode) {
BibleViewSwipeMode.CHAPTER -> mainBibleActivity.next()
BibleViewSwipeMode.PAGE -> bibleView.volumeDownPressed()
BibleViewSwipeMode.NONE -> {}
}
} else {
// left to right swipe
mainBibleActivity.previous()
when(CommonUtils.settings.bibleViewSwipeMode) {
BibleViewSwipeMode.CHAPTER -> mainBibleActivity.previous()
BibleViewSwipeMode.PAGE -> bibleView.volumeUpPressed()
BibleViewSwipeMode.NONE -> {}
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class BibleView(val mainBibleActivity: MainBibleActivity,
private val maxHorizontalScroll: Int
get() = computeHorizontalScrollRange() - computeHorizontalScrollExtent()

private val gestureListener = BibleGestureListener(mainBibleActivity)
private val gestureListener = BibleGestureListener(mainBibleActivity, this)

private var toBeDestroyed = false

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/net/bible/service/common/CommonUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import net.bible.android.view.activity.base.ActivityBase
import net.bible.android.view.activity.base.CurrentActivityHolder
import net.bible.android.view.activity.base.Dialogs
import net.bible.android.view.activity.download.DownloadActivity
import net.bible.android.view.activity.page.BibleView
import net.bible.android.view.activity.page.Selection
import net.bible.android.view.activity.page.buyDevelopmentLink
import net.bible.service.cloudsync.CloudSync
Expand Down Expand Up @@ -261,6 +262,8 @@ open class CommonUtilsBase {
@Inject lateinit var bibleTraverser: BibleTraverser
}

enum class BibleViewSwipeMode {CHAPTER, PAGE, NONE}

class Ref<T>(var value: T? = null)

/**
Expand Down Expand Up @@ -433,6 +436,7 @@ object CommonUtils : CommonUtilsBase() {
val disableAnimations: Boolean get() = getBoolean("disable_animations", false)
val fontSizeMultiplier: Int get() = getInt("font_size_multiplier", 100)
val fontSizeMultiplierFloat: Float get() = getInt("font_size_multiplier", 100) / 100F
val bibleViewSwipeMode: BibleViewSwipeMode get() = BibleViewSwipeMode.valueOf(getString("bible_view_swipe_mode", "CHAPTER")!!)
}

private var _settings: AndBibleSettings? = null
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@
</string-array>
<!-- Bible/commentary toolbar button press actions -->

<string-array name="prefs_bible_view_swipe_mode_values">
<item>CHAPTER</item>
<item>PAGE</item>
<item>NONE</item>
</string-array>

<string-array name="prefs_bible_view_swipe_mode_descriptions">
<item>@string/prefs_swipe_mode_chapter</item>
<item>@string/prefs_swipe_mode_page</item>
<item>@string/prefs_swipe_mode_none</item>
</string-array>

<!-- Screen colors: automatic night mode, day, night -->
<string-array name="prefs_night_mode_descriptions">
<string-array name="prefs_night_mode_descriptions">
<item>@string/prefs_night_mode_manual</item>
<item>@string/prefs_night_mode_automatic</item>
</string-array>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,4 +1239,9 @@
<string name="pref_font_size_multiplier_summary_1">Multiply text font sizes by this number.</string>
<string name="pref_font_size_multiplier_summary_2">Useful if you have a synchronized device that is used with larger font.</string>
<string name="current_value">Current value: %s</string>
<string name="prefs_bible_view_swipe_mode_title">Action for swipe left / right gesture</string>
<string name="prefs_bible_view_swipe_mode_summary">Swipe left / right gesture can be used to go to next page / chapter.</string>
<string name="prefs_swipe_mode_chapter">Chapter</string>
<string name="prefs_swipe_mode_page">Page</string>
<string name="prefs_swipe_mode_none">Disabled</string>
</resources>
8 changes: 7 additions & 1 deletion app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@
android:defaultValue="false"
android:icon="@drawable/ic_bookmark_24dp"
/>

<ListPreference android:key="bible_view_swipe_mode"
android:title="@string/prefs_bible_view_swipe_mode_title"
android:summary="@string/prefs_bible_view_swipe_mode_summary"
android:entries="@array/prefs_bible_view_swipe_mode_descriptions"
android:entryValues="@array/prefs_bible_view_swipe_mode_values"
android:icon="@drawable/ic_full_screen_by_scrolling_24dp"
android:defaultValue="CHAPTER"/>
<ListPreference android:key="night_mode_pref3"
android:title="@string/prefs_night_mode_title"
android:summary="@string/prefs_night_mode_summary"
Expand Down

0 comments on commit 81232ee

Please sign in to comment.