Fix story display size logic.

fork-5.53.8
Alex Hart 2022-03-10 10:28:05 -04:00 zatwierdzone przez Cody Henthorne
rodzic e552b5160f
commit d61e33fdf3
3 zmienionych plików z 36 dodań i 7 usunięć

Wyświetl plik

@ -1,7 +1,5 @@
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.
*/
@ -24,13 +22,13 @@ enum class StoryDisplay {
private const val LARGE_AR = 9 / 18f
private const val SMALL_AR = 9 / 16f
fun getStoryDisplay(resources: Resources): StoryDisplay {
val aspectRatio = resources.displayMetrics.widthPixels.toFloat() / resources.displayMetrics.heightPixels
fun getStoryDisplay(screenWidth: Float, screenHeight: Float): StoryDisplay {
val aspectRatio = screenWidth / screenHeight
return when {
aspectRatio >= LANDSCAPE -> MEDIUM
aspectRatio >= LARGE_AR -> LARGE
aspectRatio <= SMALL_AR -> SMALL
aspectRatio <= LARGE_AR -> LARGE
aspectRatio >= SMALL_AR -> SMALL
else -> MEDIUM
}
}

Wyświetl plik

@ -318,7 +318,7 @@ class StoryViewerPageFragment :
val constraintSet = ConstraintSet()
constraintSet.clone(requireView() as ConstraintLayout)
when (StoryDisplay.getStoryDisplay(resources)) {
when (StoryDisplay.getStoryDisplay(resources.displayMetrics.widthPixels.toFloat(), resources.displayMetrics.heightPixels.toFloat())) {
StoryDisplay.LARGE -> {
constraintSet.connect(viewsAndReplies.id, ConstraintSet.TOP, cardWrapper.id, ConstraintSet.BOTTOM)
constraintSet.connect(viewsAndReplies.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)

Wyświetl plik

@ -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)
)
}
}