Fix story display size logic.
This commit is contained in:
parent
e552b5160f
commit
d61e33fdf3
3 changed files with 36 additions and 7 deletions
|
@ -1,7 +1,5 @@
|
||||||
package org.thoughtcrime.securesms.stories.viewer.page
|
package org.thoughtcrime.securesms.stories.viewer.page
|
||||||
|
|
||||||
import android.content.res.Resources
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the size of our display, we render the story overlay / crop in one of 3 ways.
|
* Given the size of our display, we render the story overlay / crop in one of 3 ways.
|
||||||
*/
|
*/
|
||||||
|
@ -24,13 +22,13 @@ enum class StoryDisplay {
|
||||||
private const val LARGE_AR = 9 / 18f
|
private const val LARGE_AR = 9 / 18f
|
||||||
private const val SMALL_AR = 9 / 16f
|
private const val SMALL_AR = 9 / 16f
|
||||||
|
|
||||||
fun getStoryDisplay(resources: Resources): StoryDisplay {
|
fun getStoryDisplay(screenWidth: Float, screenHeight: Float): StoryDisplay {
|
||||||
val aspectRatio = resources.displayMetrics.widthPixels.toFloat() / resources.displayMetrics.heightPixels
|
val aspectRatio = screenWidth / screenHeight
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
aspectRatio >= LANDSCAPE -> MEDIUM
|
aspectRatio >= LANDSCAPE -> MEDIUM
|
||||||
aspectRatio >= LARGE_AR -> LARGE
|
aspectRatio <= LARGE_AR -> LARGE
|
||||||
aspectRatio <= SMALL_AR -> SMALL
|
aspectRatio >= SMALL_AR -> SMALL
|
||||||
else -> MEDIUM
|
else -> MEDIUM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,7 @@ class StoryViewerPageFragment :
|
||||||
val constraintSet = ConstraintSet()
|
val constraintSet = ConstraintSet()
|
||||||
constraintSet.clone(requireView() as ConstraintLayout)
|
constraintSet.clone(requireView() as ConstraintLayout)
|
||||||
|
|
||||||
when (StoryDisplay.getStoryDisplay(resources)) {
|
when (StoryDisplay.getStoryDisplay(resources.displayMetrics.widthPixels.toFloat(), resources.displayMetrics.heightPixels.toFloat())) {
|
||||||
StoryDisplay.LARGE -> {
|
StoryDisplay.LARGE -> {
|
||||||
constraintSet.connect(viewsAndReplies.id, ConstraintSet.TOP, cardWrapper.id, ConstraintSet.BOTTOM)
|
constraintSet.connect(viewsAndReplies.id, ConstraintSet.TOP, cardWrapper.id, ConstraintSet.BOTTOM)
|
||||||
constraintSet.connect(viewsAndReplies.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
|
constraintSet.connect(viewsAndReplies.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.thoughtcrime.securesms.stories.viewer.page
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.Parameterized
|
||||||
|
|
||||||
|
@RunWith(Parameterized::class)
|
||||||
|
class StoryDisplayTest(
|
||||||
|
private val width: Float,
|
||||||
|
private val height: Float,
|
||||||
|
private val storyDisplay: StoryDisplay
|
||||||
|
) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Given an aspect ratio, when I getStoryDisplay, then I expect correct size`() {
|
||||||
|
assertEquals(storyDisplay, StoryDisplay.getStoryDisplay(width, height))
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
@Parameterized.Parameters(name = "{index}: displaySize({0}, {1}) = {2}")
|
||||||
|
fun data(): Iterable<Array<Any>> = arrayListOf(
|
||||||
|
arrayOf(9f, 20.1f, StoryDisplay.LARGE),
|
||||||
|
arrayOf(4f, 3f, StoryDisplay.MEDIUM),
|
||||||
|
arrayOf(9, 18f, StoryDisplay.LARGE),
|
||||||
|
arrayOf(9, 17f, StoryDisplay.MEDIUM),
|
||||||
|
arrayOf(9, 16f, StoryDisplay.SMALL)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue