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 @@ -508,6 +508,11 @@ class PagerActivity : AppCompatActivity(), AudioBarListener, OnBookmarkTagsUpdat
}

val nonRestoringViewPager = findViewById<NonRestoringViewPager>(R.id.quran_pager)
ViewCompat.setOnApplyWindowInsetsListener(nonRestoringViewPager) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars())
view.updatePadding(bottom = insets.bottom)
windowInsets
}
nonRestoringViewPager.setIsDualPagesInLandscape(
QuranUtils.isDualPagesInLandscape(this, quranScreenInfo)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class QuranImagePageLayout(context: Context) : QuranPageLayout(context) {
override fun generateContentView(context: Context, isLandscape: Boolean): View {
imageView = HighlightingImageView(context).apply {
adjustViewBounds = true
setIsScrollable(isLandscape && shouldWrapWithScrollView(), isLandscape)
setIsScrollable(isScrollableLayout(context.resources), isLandscape)
}
return imageView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void initialize() {
viewPaddingLarge = resources.getDimensionPixelSize(R.dimen.page_margin_large);

LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
if (isLandscape && shouldWrapWithScrollView()) {
if (isScrollableLayout(resources)) {
scrollView = new ObservableScrollView(context);
scrollView.setFillViewport(true);
addView(scrollView, lp);
Expand Down Expand Up @@ -197,6 +197,13 @@ protected void onDraw(Canvas canvas) {

protected abstract View generateContentView(@NonNull Context context, boolean isLandscape);

protected boolean isScrollableLayout(@NonNull Resources resources) {
final Configuration config = resources.getConfiguration();
final boolean isLandscape = config.orientation == Configuration.ORIENTATION_LANDSCAPE;
final boolean isShortViewport = config.screenWidthDp > 0 && config.screenHeightDp > 0 && config.screenHeightDp < config.screenWidthDp * 1.4f;
return (isLandscape || isShortViewport) && shouldWrapWithScrollView();
}

protected boolean shouldWrapWithScrollView() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.quran.labs.androidquran.view

import android.content.Context
import android.content.res.Configuration
import androidx.test.core.app.ApplicationProvider
import com.quran.labs.androidquran.base.TestApplication
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@Config(application = TestApplication::class, sdk = [33])
@RunWith(RobolectricTestRunner::class)
class QuranPageLayoutTest {

@Test
fun fullScreenPortraitIsNotScrollable() {
val context = createContext(411, 915, Configuration.ORIENTATION_PORTRAIT)
val layout = QuranImagePageLayout(context)
assertFalse(layout.canScroll())
}

@Test
fun constrainedSplitScreenPortraitIsScrollable() {
val context = createContext(411, 420, Configuration.ORIENTATION_PORTRAIT)
val layout = QuranImagePageLayout(context)
assertTrue(layout.canScroll())
}

@Test
fun landscapeIsScrollable() {
val context = createContext(915, 411, Configuration.ORIENTATION_LANDSCAPE)
val layout = QuranImagePageLayout(context)
assertTrue(layout.canScroll())
}

@Test
fun tabletLayoutInConstrainedPortraitIsNotScrollable() {
val context = createContext(411, 420, Configuration.ORIENTATION_PORTRAIT)
val layout = QuranTabletImagePageLayout(context)
assertFalse(layout.canScroll())
}

private fun createContext(widthDp: Int, heightDp: Int, orientation: Int): Context {
val baseContext = ApplicationProvider.getApplicationContext<Context>()
val config = Configuration(baseContext.resources.configuration).apply {
screenWidthDp = widthDp
screenHeightDp = heightDp
this.orientation = orientation
}
return baseContext.createConfigurationContext(config)
}
}