Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class GlobalOptions(

val DRAW_PAGE_BORDER = pref("DRAW_PAGE_BORDER", true)

val SYNC_X_SCROLL = pref("SYNC_X_SCROLL", false)

fun <T> subscribe(pref: Preference<T>) {
registeredPreferences.put(pref.key, pref)?.also {
errorInDebug("Pref with key ${pref.key} already registered: $pref ")
Expand Down Expand Up @@ -330,6 +332,8 @@ class GlobalOptions(

const val TEST_FLAG: String = "ORION_VIEWER_TEST_FLAG"

const val SYNC_X_SCROLL: String = "SYNC_X_SCROLL"

const val ENABLE_TOUCH_MOVE: String = "ENABLE_TOUCH_MOVE"

const val ENABLE_MOVE_ON_PINCH_ZOOM: String = "ENABLE_MOVE_ON_PINCH_ZOOM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {

var isSinglePageMode = false

var syncXScroll = controller.activity.globalOptions.SYNC_X_SCROLL

private var activePage = -1

val sceneRect = Rect(0, 0, scene.width, scene.height)
Expand Down Expand Up @@ -163,7 +165,7 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {

activePages.forEach {
val layoutData = it.layoutData
if (layoutData.containsY(yPos)) {
if (syncXScroll.value || layoutData.containsY(yPos)) {
val leftDelta = layoutData.globalLeft - sceneRect.left
val righDelta = sceneRect.right - layoutData.globalRight
if (layoutData.wholePageRect.width() < sceneRect.width()) {
Expand Down Expand Up @@ -372,8 +374,13 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {
}

var first = true
var firstXPos = 0f
activePages.forEach {
if (it.isOnScreen) {
if (first)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change in doScrollAndDoRendering is clear, but this one is not. Could you please elaborate it?

@zhmylove zhmylove Jan 4, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that orion-viewer does something like prefetch of the pages: it loads around 3 extra pages to the direction of scrolling and changes in doScrollAndDoRendering properly sync their X-position.

The problem was with other pages being loaded during scrolling. I failed setting their X-position in uploadPrevPage and uploadNextPage, nor inside addPageInPosition — those functions just ignored it and new pages (4+ pages below) got improper position. So the only solution I came across is to synchronize X-position for all the pages being rendered in renderVisiblePages

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will think about it

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was with other pages being loaded during scrolling. I failed setting their X-position in uploadPrevPage and uploadNextPage, nor inside addPageInPosition — those functions just ignored it and new pages (4+ pages below) got improper position. So the only solution I came across is to synchronize X-position for all the pages being rendered in renderVisiblePages

@zhmylove Sorry for long delay in response. It's interesting cause there should be a code that ignores passed value and/or passes default one. Do you have any change to restore from history described above approach and share it via another PR?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I did check my repos and it seems I have no history even in reflog :(

firstXPos = it.layoutData.position.x
else if (syncXScroll.value)
it.layoutData.position.x = firstXPos
renderPage(it, canvas, scene, first)
first = false
}
Expand Down
1 change: 1 addition & 0 deletions orion-viewer/src/main/res/values-ru/pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<string name="pref_close_page_option_dialog_on_apply">Закрывать диалог параметров страницы при применении настроек</string>
<string name="pref_swap_prev_next_keys">Обменять клавиши местами</string>
<string name="pref_swap_prev_next_keys_on_90_degree_rotation">Обменять действия клавиш вперед/назад в портретном режиме</string>
<string name="pref_sync_x_scroll">Общая позиция по горизонтали</string>
<string name="pref_dictionary">Словарь</string>
<string name="pref_dictionary_desc">Словарь: %s</string>
<string name="pref_e_ink_optimization">E-ink</string>
Expand Down
1 change: 1 addition & 0 deletions orion-viewer/src/main/res/values/pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<string name="pref_close_page_option_dialog_on_apply">Close page option dialog on apply button click</string>
<string name="pref_swap_prev_next_keys">Swap prev/next keys</string>
<string name="pref_swap_prev_next_keys_on_90_degree_rotation">Swap prev/next keys in landscape mode</string>
<string name="pref_sync_x_scroll">Sync horizontal scroll</string>
<string name="pref_dictionary">Dictionary</string>
<string name="pref_dictionary_desc">Dictionary: %s</string>
<string name="pref_e_ink_optimization">E-ink</string>
Expand Down
7 changes: 7 additions & 0 deletions orion-viewer/src/main/res/xml/user_pref_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
android:summary="@string/pref_swap_prev_next_keys_on_90_degree_rotation"
android:title="@string/pref_swap_prev_next_keys"
app:iconSpaceReserved="false" />

<CheckBoxPreference
android:defaultValue="false"
android:key="SYNC_X_SCROLL"
android:summary="@string/pref_sync_x_scroll"
android:title="@string/pref_sync_x_scroll"
app:iconSpaceReserved="false" />
</PreferenceCategory>

<PreferenceCategory
Expand Down