-
Notifications
You must be signed in to change notification settings - Fork 29
Conversation
import org.readium.r2.shared.publication.Link | ||
import org.readium.r2.shared.publication.Publication | ||
|
||
|
||
class R2PagerAdapter(val fm: FragmentManager, private val resources: List<Any>, private val title: String, private val type: Publication.TYPE, private val publicationPath: String = "") : R2FragmentPagerAdapter(fm) { | ||
class R2PagerAdapter(val fm: FragmentManager, val l: Lifecycle, private val resources: List<Any>, private val title: String, private val type: Publication.TYPE, private val publicationPath: String = "") : FragmentStateAdapter(fm, l) { | ||
|
||
private var currentFragment: Fragment? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really want to centralize this. There are instances of currentFragment
in several files, usually with quite a bit of casting to retrieve it. Just declare the currentFragment property and access the getter and setter to manage it.
@mickael-menu @aferditamuriqi I've tracked down the RTL issues to two things.
I want to try and keep the function names sensible while making the necessary fixes. So I'm thinking when |
Sounds about right. 👍 You could also expose fun goLeft(animated: Boolean = false, completion: () -> Unit = {}): Boolean
fun goRight(animated: Boolean = false, completion: () -> Unit = {}): Boolean There's a default implementation in r2-navigator-kotlin/r2-navigator/src/main/java/org/readium/r2/navigator/IR2Activity.kt Lines 89 to 107 in 71c4937
|
…the getCurrentFragment calls
@mickael-menu I changed the
|
… to first page of resource in RTL layouts
// This is a temporary fix to prevent the webview from snapping to the beginning | ||
// of the resource when paging between them in RTL layouts | ||
if (navigator.readingProgression == ReadingProgression.LTR) { | ||
this@R2BasicWebView.evaluateJavascript("scrollLeft();", null) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevenzeck What did you mean by temporary? Do you have any idea on how to fix this in a more permanent way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was temporary in that I was hoping there was a different problem, but I couldn't find one. I'll remove that part of the comment.
@@ -117,33 +117,33 @@ class EpubNavigatorFragment( | |||
|
|||
|
|||
if (publication.metadata.presentation.layout == EpubLayout.REFLOWABLE) { | |||
adapter = R2PagerAdapter(supportFragmentManager, resourcesSingle, publication.metadata.title, Publication.TYPE.EPUB) | |||
resourcePager.type = Publication.TYPE.EPUB | |||
resourcePager.isUserInputEnabled = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevenzeck Why did you need to switch off isUserInputEnabled
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the equivalent of onInterceptTouchEvent
/onTouchEvent
from the original ViewPager. We have to prevent the ViewPager from paging via user input and do it ourselves, otherwise it will go from resource to resource instead of page to page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I guess this is the reason FXL EPUB can't be interacted with. Since they are not paginated, maybe this can be done selectively only for reflowable. However I wonder why links are working in reflowable EPUBs despite isUserInputEnabled
?
// resourcePager.direction = publication.contentLayout.readingProgression | ||
resourcePager.layoutDirection = View.LAYOUT_DIRECTION_LTR | ||
|
||
if (publication.cssStyle == ReadingProgression.RTL.value) { | ||
resourcePager.direction = ReadingProgression.RTL | ||
resourcePager.layoutDirection = View.LAYOUT_DIRECTION_RTL | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publication.cssStyle
will soon be deprecated, so I think we can rely exclusively on publication.contentLayout.readingProgression
for now. Something along the line:
resourcePager.layoutDirection = when (publication.contentLayout.readingProgression) {
ReadingProgression.RTL -> View.Layout_DIRECTION_RTL
else -> View.Layout_DIRECTION_LTR
}
I'm not yet sure if TTB and BTT will need to be handled differently with the ViewPager2. But it's not used yet anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was wondering what TTB and BTT are exactly and how they would factor into this. Will make the change you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for vertical reading progression: top-to-bottom and bottom-to-top.
I wonder if we could not handle them with https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/ViewPager2#setorientation And then combining it with Layout_DIRECTION_RTL
, maybe it would be equivalent to BTT.
import org.readium.r2.shared.publication.Link | ||
import org.readium.r2.shared.publication.Publication | ||
|
||
|
||
class R2PagerAdapter(val fm: FragmentManager, private val resources: List<Any>, private val title: String, private val type: Publication.TYPE, private val publicationPath: String = "") : R2FragmentPagerAdapter(fm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevenzeck We can remove R2FragmentPagerAdapter.kt
since it's not used anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
// private var currentFragment: Fragment? = null | ||
// private var previousFragment: Fragment? = null | ||
// private var nextFragment: Fragment? = null | ||
// | ||
// fun getCurrentFragment(): Fragment? { | ||
// return currentFragment | ||
// } | ||
// | ||
// fun getPreviousFragment(): Fragment? { | ||
// return previousFragment | ||
// } | ||
// | ||
// fun getNextFragment(): Fragment? { | ||
// return nextFragment | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevenzeck Could you remove these as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
A few issues I noticed during my tests:
Apart from that, the paging across resources itself seems to be working pretty well. Thanks again @stevenzeck 👍 I'll do more exhaustive testing once we fix any pending issue and raised question. |
private val r2PagerAdapter: R2PagerAdapter | ||
get() = resourcePager.adapter as R2PagerAdapter | ||
|
||
private val currentFragment: R2EpubPageFragment? get() = | ||
r2PagerAdapter.mFragments.get(r2PagerAdapter.getItemId(resourcePager.currentItem)) as? R2EpubPageFragment | ||
val currentFragment: R2EpubPageFragment? get() = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevenzeck Could you set currentFragment
as internal
to keep the internals of EpubNavigatorFragment
private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
After talking with @mickael-menu in Slack, I think it's better to hold off on this PR until all of the old R2ViewPager code is deprecated (mFragments, getCurrentFragment, etc). I will continue making a few updates based on feedback and fixing the issues mentioned, and will keep the branch up to date as best as I can. |
We think this is due to a newly imported book not being cached yet.
I can recreate this on the alpha branch as well. I can look into.
I'm able to zoom in and out of the CBZ in the testapp (Cory Doctorow's). What content and device does it not work in?
I can recreate this. Will look into. It's also jumping back an old position if you rotate the screen.
A couple of things:
For this to work properly, I think it needs to get away from all of that logic. Let the ViewPager and adapter handle all of that.
I'm getting that stack trace for reflowables as well. The activity is recreated when orientation changes, and for some reason the webview isn't being initialized somewhere during that transition. I'm also sporadically seeing an error related to FragmentManager is already executing transactions. |
I'm using the same book, on a Pixel 3a. After further tests, actually I noticed that I can zoom in/out after double taping on the page, but it's not very smooth. It looks like there's a conflict between the swipe gesture and the pinch one.
We have similar issue on iOS and I thought about preventing the initial |
I'm able to do pinch and double tab for zooming in and out using my Pixel C. I'll try it on my Pixel 3 too. For the locator issue, there's a lot of code in the navigator where things are done out of order and done several times. Ultimately we need to:
|
Sounds like a good plan. I don't know how it is implemented currently in the EPUB navigator, how does it differ? And do you think it would be possible to implement it with the current R2ViewPager, and then merge it into the ViewPager2 PR? It could be useful also to reify a state machine to have a better control/view on the state of the navigator. |
Closing after the group decision in today's Agenda. The PR is quite obsolete now and we figured using As an alternative, we should be able to use a |
Closes readium/kotlin-toolkit#148. This is a draft PR. It should also be merged at the same time as readium/r2-testapp-kotlin#349.