A cheap attempt at a native Bluesky client for Android

PostImageGallery: Respect image aspect ratio

When displaying a single image, respect its original aspect ratio instead of forcing it to be square.

This also updates the gallery viewer to use the full-size image URL when zoomed in.

+35 -18
+1 -1
app/src/main/java/industries/geesawra/monarch/GalleryViewer.kt
··· 58 58 ) 59 59 ) 60 60 ), 61 - model = imageUrls[page].url, 61 + model = imageUrls[page].fullSize, 62 62 contentDescription = imageUrls[page].alt, 63 63 modifier = Modifier 64 64 .fillMaxSize(),
+33 -16
app/src/main/java/industries/geesawra/monarch/PostImageGallery.kt
··· 31 31 32 32 data class Image( 33 33 val url: String, 34 + val fullSize: String = "", 34 35 val alt: String, 35 36 val width: Long? = null, 36 37 val height: Long? = null, ··· 64 65 65 66 when (imagesToDisplay.size) { 66 67 1 -> { 67 - Row( 68 - modifier = modifier 69 - .fillMaxWidth() 70 - ) { 71 - DeletableImageView( 72 - modifier = Modifier.weight(1f), 73 - image = imagesToDisplay[0], 74 - originalIndex = 0, 75 - onCrossClick = onCrossClick, 76 - onMediaClick = { galleryVisible.value = 0 }) 68 + val img = imagesToDisplay[0] 69 + 70 + val aspectRatio = if (img.width != null && img.height != null) { 71 + img.width.toFloat() / img.height.toFloat() 72 + } else { 73 + null 77 74 } 75 + 76 + DeletableImageView( 77 + image = img, 78 + originalIndex = 0, 79 + onCrossClick = onCrossClick, 80 + onMediaClick = { galleryVisible.value = 0 }, 81 + aspectRatio = aspectRatio 82 + ) 78 83 } 79 84 80 85 2 -> { ··· 195 200 private fun DeletableImageView( 196 201 modifier: Modifier = Modifier, 197 202 image: Image, 203 + aspectRatio: Float? = null, 198 204 originalIndex: Int, 199 205 onCrossClick: ((Int) -> Unit)? = null, 200 206 onMediaClick: (Int) -> Unit, 201 207 ) { 202 208 DeletableMediaView( 203 - modifier = modifier, 209 + modifier = run { 210 + if (aspectRatio != null) { 211 + modifier 212 + } else { 213 + modifier.aspectRatio(1f) 214 + } 215 + }, 204 216 originalIndex = originalIndex, 205 217 onCrossClick = onCrossClick, 206 218 onMediaClick = onMediaClick, ··· 212 224 .build(), 213 225 contentDescription = image.alt, 214 226 contentScale = ContentScale.Crop, 215 - modifier = Modifier 216 - .aspectRatio(1f) // Changed from fillMaxSize() to make it square 217 - .clip(RoundedCornerShape(12.dp)) 218 - .clickable { onMediaClick(originalIndex) } 227 + modifier = if (aspectRatio != null) { 228 + Modifier 229 + .aspectRatio(aspectRatio) 230 + .clip(RoundedCornerShape(12.dp)) 231 + .clickable { onMediaClick(originalIndex) } 232 + } else { 233 + Modifier 234 + .clip(RoundedCornerShape(12.dp)) 235 + .clickable { onMediaClick(originalIndex) } 236 + } 219 237 ) 220 238 } 221 239 } ··· 230 248 ) { 231 249 Box( 232 250 modifier = modifier 233 - .aspectRatio(1f) // Changed from fillMaxSize() to make it square 234 251 .clip(RoundedCornerShape(12.dp)) 235 252 .clickable { onMediaClick(originalIndex) } 236 253 ) {
+1 -1
app/src/main/java/industries/geesawra/monarch/SkeetView.kt
··· 231 231 private fun ImageView(img: List<ImagesViewImage>) { 232 232 OutlinedCard( 233 233 modifier = Modifier 234 - .fillMaxWidth() 235 234 .padding(top = 8.dp, bottom = 8.dp), 236 235 ) { 237 236 PostImageGallery( ··· 241 240 Image( 242 241 url = it.thumb.uri, 243 242 alt = it.alt, 243 + fullSize = it.fullsize.uri, 244 244 width = it.aspectRatio?.width, 245 245 height = it.aspectRatio?.height 246 246 )