Skip to content

Conversation

Kota-Jagadeesh
Copy link
Collaborator

@Kota-Jagadeesh Kota-Jagadeesh commented Sep 27, 2025

Description (required)

Fixes #6404

This pull request addressses the crashes in the image upload flow of the app, specifically targeting issue #6404 (App crashes when switching between light and dark theme).
These changaes ensure proper handling of activity recreation and state restoration, improving stability during theme changes, rotation, and process death.

What changes did you make and why?

  1. UploadMediaPresenter.kt
    • Fixed IndexOutOfBoundsException in setUploadMediaDetails by adding validation for uploadItemIndex and uploadItems list size.
    • Prevents crashes when the list is empty during activity recreation.
  2. UploadMediaDetailFragment.kt
    • Prevented IndexOutOfBoundsException by safely handling saved state and indexOfFragment in onViewCreated.
    • this ensurer setUploadMediaDetails is only called with valid data.
  3. ImageFragment.kt
    • resolved UninitializedPropertyAccessException by safely initializing and accessing imageAdapter in onCreateView, onDestroy, and related methods.
    • Added initialization state checks to prevent null access.
  4. UploadActivity.kt
    • Fixed Unresolved reference: setImageToBeUploaded compilation error by replacing it with direct field assignments and deferred initializeFragment calls.
    • Ensures proper fragment setup during lifecycle changes.

Tests performed (required)

  • Tested on Android 14 on Redmi 13 note 5g (ProdDebug) build variant.
  • Verified smooth behavior during:
    • Theme switching (light ↔ dark).
    • Screen rotation.
    • Process death and restoration.
  • Confirmed no crashes in:
    • CustomSelectorActivity
    • ImageFragment
    • UploadActivity
    • UploadMediaDetailFragment
  • Verified Logcat logs show proper initialization and state handling, e.g.:
    • "Initialized imageAdapter"
    • "Set uploadMediaDetails for index X"

Additional Notes

  • Added Timber logging across all changed files to aid debugging and trace lifecycle events.

Note: Please ensure that you have read CONTRIBUTING.md if this is your first pull request.

@rohit9625
Copy link
Collaborator

Hmm, there are so many changes, I'll review it by tomorrow :)

@Kota-Jagadeesh
Copy link
Collaborator Author

Kota-Jagadeesh commented Oct 2, 2025

Hmm, there are so many changes, I'll review it by tomorrow :)

Hi @rohit9625 , just checking in - is this PR still under review, or would you like me to make any changes ?

@rohit9625
Copy link
Collaborator

rohit9625 commented Oct 4, 2025

Hmm, there are so many changes, I'll review it by tomorrow :)

Hi @rohit9625 , just checking in - is this PR still under review, or would you like me to make any changes ?

I didn't get time to review this, I wonder why there are so many changes to fix this tiny crash. Did you also refactor the code? I'll review this once done with 16KB compilation task :)

Meanwhile, please fix the tests.

@Kota-Jagadeesh
Copy link
Collaborator Author

Kota-Jagadeesh commented Oct 6, 2025

Hmm, there are so many changes, I'll review it by tomorrow :)

Hi @rohit9625 , just checking in - is this PR still under review, or would you like me to make any changes ?

I didn't get time to review this, I wonder why there are so many changes to fix this tiny crash. Did you also refactor the code? I'll review this once done with 16KB compilation task :)

Meanwhile, please fix the tests.

Thanks for the feedback! The multiple changes address the root causes of the crash across different components (UploadMediaPresenter, UploadMediaDetailFragment, ImageFragment, UploadActivity) to ensure tha robust state handling during theme chaenges and activity recreation. No refactoring was done; each change targets a specific issue (e.g., IndexOutOfBoundsException, UninitializedPropertyAccessException, and a compilation error) to prevent crashes comprehensively. I’ve included detailed loggingg to verify stability : )

@rohit9625
Copy link
Collaborator

I just tested your PR and can confirm that it resolves the issue. However, I need to take a closer look at the diffs to ensure that nothing unexpected happens in production.

Screen_recording_20251008_011411.mp4

Also, please update your PR description to match the default template and fix the unit tests, @Kota-Jagadeesh

@Kota-Jagadeesh
Copy link
Collaborator Author

@rohit9625 Fixed all the issues, Please review the PR : )

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great!
Would you mind just fixing the various typos in the comments you added?
By the way thanks for adding these comments. :-)

@Kota-Jagadeesh
Copy link
Collaborator Author

Works great! Would you mind just fixing the various typos in the comments you added? By the way thanks for adding these comments. :-)

Yeah, i'll update all the comments without any typo's

@Kota-Jagadeesh
Copy link
Collaborator Author

Fixed all the typos : )

Copy link

✅ Generated APK variants!

@nicolas-raoul nicolas-raoul merged commit 4c62136 into commons-app:main Oct 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: App crashes when trying to change theme while at Upload screen with multi-upload

3 participants