Add profile pictures from files#3086
Conversation
fire-light42
left a comment
There was a problem hiding this comment.
Thank you for you contribution! Great job on the new feature!
Overall good code, but there are some minor nitpicks.
| val activity = context.getActivity() as? ComponentActivity ?: return | ||
| var launcher: ActivityResultLauncher<Array<String>>? = null | ||
| try { | ||
| launcher = activity.activityResultRegistry.register( |
There was a problem hiding this comment.
Please use registerForActivityResult instead, to get a safer and lifecyle-aware file picking. It may be more difficult, but it removes the dirty getActivity() and having to unregister.
| onError = { _, _ -> showToast(R.string.edit_profile_image_error_invalid) } | ||
| ).build()) | ||
| } | ||
| launcher.launch(arrayOf("image/png", "image/jpeg")) |
There was a problem hiding this comment.
This should be "image/*" to support all types of images.
| onSuccess = { _, _ -> | ||
| currentEditAccount = currentEditAccount.copy(customImage = url) | ||
| binding.accountImage.loadImage(url) | ||
| callback(url) |
There was a problem hiding this comment.
Elegant solution, very nice!
| AlertDialog.Builder(context) | ||
| .setTitle(R.string.edit_profile_image_title) | ||
| .setItems(arrayOf( | ||
| context.getString(R.string.player_load_subtitles), |
There was a problem hiding this comment.
Please add another string in strings.xml, which references player_load_subtitles (like action_open_play). This makes it easier to prevent mistakes in the future, for example if player_load_subtitles is changed to something like "Load subtitle from file".
| if (!dialog.isShowing) return@pickProfileImage | ||
| currentEditAccount = currentEditAccount.copy(customImage = image) | ||
| binding.accountImage.loadImage(image) | ||
| showToast(R.string.edit_profile_image_success, Toast.LENGTH_SHORT) |
There was a problem hiding this comment.
This toast should be moved to pickProfileImage for consistency.
|
Addressed the requested Activity Result API, image/* MIME, string alias, and toast placement changes in f59858c. I kept internal file copying out of scope as noted optional; persisted document permissions and the existing fallback remain in place. Ready for re-review when convenient. |
What does this change?
Adds a file option to the profile image editor while preserving the existing URL flow.
Selected PNG and JPEG documents must decode successfully before preview, and read access is persisted using the existing document-import pattern. The shared picker works from both account-entry points, and restored images without an available URI grant fall back to the default avatar.
The edit icon also gains a content description and explicit D-pad focus navigation while retaining its existing touch background.
Closes #3079
Testing
:app:compileStableDebugKotlin:app:testStableDebugUnitTest(8 tests, 0 failures):app:lintStableDebug(0 errors):app:assembleStableDebuggit diff --checkLimitations
AI disclosure
AI-assisted: implementation and review used OpenAI Codex; the listed checks were run on the submitted code.