Repository navigation
fix(avatar): decode and save the remote avatar off the main thread - #6863
Conversation
PickImage.handleAvatar decoded the thumbnail stream and wrote the PNG inside the Retrofit callback, which runs on the main thread. Do both in the activity's lifecycleScope on Dispatchers.IO and launch the picker back on the main thread. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
rapterjet2004
left a comment
There was a problem hiding this comment.
Thanks, moving the decode and the PNG write off the main thread looks right, and returning instead of crashing on response.body()!! is an improvement.
One change before this goes in: failures are now completely silent. An error response (null body), a thumbnail that doesn't decode, a failed PNG write, and onFailure (still // unused atm) all end with nothing happening. From the user's side, they pick a file and nothing happens. Please show an error to the user in these cases, e.g. a toast with R.string.nc_common_error_sorry on the main thread, and log the cause.
Small optional nit: the response body is never closed. Reading it inside body.use { BitmapFactory.decodeStream(it.byteStream()) } would fix that (pre-existing).
A response without a body, a thumbnail that does not decode, a failed PNG write and onFailure all ended silently, so picking a file did nothing from the user's side. Log the cause and show R.string.nc_common_error_sorry on the main thread. Close the response body after decoding. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8916c517-e56d-446f-ae75-e6ba65c9c75b
📒 Files selected for processing (2)
app/src/main/java/com/nextcloud/talk/utils/PickImage.ktapp/src/test/java/com/nextcloud/talk/utils/PickImageTest.kt
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
…stroyed If the activity is destroyed between onResponse and the coroutine start, lifecycleScope.launch never runs the block, so the body returned by Retrofit stayed open. Close it from the job's completion handler; closing twice is safe. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
|
Thanks for the review. Pushed 8e4c6f9 and a0d9a78:
|
…tests Without @config the runner picks the target SDK (36) and has to download a second android-all jar. On CI that download failed with an SSLException, so the class failed with initializationError before any test ran. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
rapterjet2004
left a comment
There was a problem hiding this comment.
Thanks, all failure paths now tell the user, and launchClosing covering the case where the activity is destroyed before the coroutine starts is a nice catch. Tiny optional nit: decodeAvatarToFile logs with a hardcoded "PickImage" tag instead of a shared TAG constant.
|
Thanks! Follow-up for the |
PickImage.handleAvatar decoded the thumbnail stream and wrote the PNG
inside the Retrofit callback, which runs on the main thread. Do both in
the activity's lifecycleScope on Dispatchers.IO and launch the picker
back on the main thread.
🤖 Generated with Claude Code