A cheap attempt at a native Bluesky client for Android
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bluesky: compress images to the lexicon specified size before uploading

geesawra 273670be 88e49b8b

+17 -1
+17 -1
app/src/main/java/industries/geesawra/monarch/datalayer/Bluesky.kt
··· 473 473 } 474 474 475 475 suspend fun uploadImages(images: List<Uri>): Result<List<Blob>> { 476 + val maxImageSize = 1000000 477 + 476 478 return runCatching { 477 479 create().onFailure { 478 480 return Result.failure(LoginException(it.message)) ··· 480 482 481 483 val uploadedBlobs = mutableListOf<Blob>() 482 484 485 + val compressor = ImageCompressor(context) 486 + 483 487 images.forEach { 484 488 context.contentResolver.openInputStream(it)?.use { inputStream -> 485 - val byteArray = inputStream.readBytes() 489 + val byteArray = run { 490 + inputStream.mark(0) 491 + 492 + val c = compressor.compressImage(it, maxImageSize.toLong()) 493 + 494 + c?.let { 495 + return@run c 496 + } 497 + 498 + inputStream.reset() 499 + return@run inputStream.readBytes() 500 + } 501 + 486 502 val blob = client!!.uploadBlob(byteArray) 487 503 when (blob) { 488 504 is AtpResponse.Failure<*> -> return Result.failure(Exception("Failed uploading image: ${blob.error}"))