GrapheneOS / Camera

Modern camera app focused on privacy and security with QR & barcode scanning.
https://grapheneos.org/
MIT License
801 stars 87 forks source link

Fix in-app gallery resetting to the first image on orientation change #440

Open MHShetty opened 1 month ago

MHShetty commented 1 month ago

Changing the orientation in the in-app gallery currently causes the entire gallery activity to reset

This pull request would help resolve the issue described at #370

muhomorr commented 2 weeks ago

Activity is recreated after almost all configuration changes, not just after rotation. Proper solution for this is to use a ViewModel or to save activity state in onSaveInstanceState().

The proposed solution doesn't work in my testing even for orientation changes, not clear why.

muhomorr commented 1 week ago

Special handling of lastCapturedItem should be skipped when lastViewedMediaPosition is not 0, otherwise decoding of item at lastViewedMediaPosition will be delayed until decoding of lastCapturedItem is complete.

MHShetty commented 1 week ago

Special handling of lastCapturedItem should be skipped when lastViewedMediaPosition is not 0, otherwise decoding of item at lastViewedMediaPosition will be delayed until decoding of lastCapturedItem is complete.

Yes, loading the first item would be un-necessary in this case. Thanks a lot for reviewing this PR!

muhomorr commented 1 week ago

Item position is not guaranteed to be stable after the item list is re-fetched, missed that initially. A stable item identifier should be saved in onSaveInstanceState, not its position.

MHShetty commented 5 days ago

Hi @muhomorr,

I have updated the code to use CapturedItem based comparison to identify the position of the slider over just saving the position to address this issue. Thank you for mentioning this out!

Regards, Mohit