New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve Image Viewer toolbar auto-hide #521
feat: Improve Image Viewer toolbar auto-hide #521
Conversation
Cancel the auto-hide behavior in case the toolbar menu items are interacted with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well as the menu comments, how do you feel about a slightly larger refactoring?
The existing mechanism for sharing the toolbar visibility isn't great.
I think the right way to do it (based on https://developer.android.com/guide/fragments/communicate#viewmodel) is roughly:
- Create a
ViewMediaActivityViewModel
, that contains the state of the toolbar's visibility (as aMutableStateFlow
internally, externally presented as aStateFlow
) - Have a method in the viewmodel that the activity can call to set a new state for the toolbar's visibility. In the viewmodel this sets a new value in to the state flow.
- Have
ViewMediaFragment
collect this state flow, and react to changes in the toolbar's visibility as appropriate.
I appreciate that's more work. If you can take that on, great. If not, I'm happy to build on this PR and do that implementation.
c018bf3
to
799ffda
Compare
799ffda
to
c34c4e8
Compare
@nikclayton I took a stab at the proposed I could keep the PRs separate or add that commit to this one. |
I really like the viewmodel refactoring in the second PR (I left a couple of comments there), so I think merging that in to this one would be good, as it cleans up some code that's otherwise a little confusing.
It doesn't help that the existing code is a mix of different styles and approaches. I'm slowly cleaning it up to make things more consistent and hopefully easier to understand, but it's taking quite a bit of time. And sometimes the only way to see what's wrong with a particular approach is to write the code and see how it can be cleaned up. I've lost count of the number of times I've started refactoring something to go in one direction, and then realise (because the refactoring made me understand the code better) that there was a cleaner way to do it. |
* refactor: Use ViewMediaViewModel instead of registering listeners * PR feedback: Avoid possible race condition when toggling toolbar visibility
@nikclayton I addressed the comments on the refactor PR and merged it here. It now seems good to merge to me! |
Yep. I made a couple of small changes in df5d66e (it didn't seem worth the effort of going through another round of review) that I discovered after running the code locally. I filed https://issuetracker.google.com/issues/329322653 for the surprising onPrepareMenu behaviour too. Assuming this goes cleanly through CI I'll merge it shortly. Thanks for your work on this |
Alright, it looks good! I see the clarity brought by the rename and flag value inversion, but why make the |
Menus are added elsewhere using MenuProvider. If you don't do that here then they're ignored (e.g., the "Report error" menu was missing). |
Cancel the auto-hide behavior in case the toolbar menu items are interacted with.
Improves #505, #507