Skip to content
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

Merged
merged 4 commits into from Mar 13, 2024

Conversation

tinsukE
Copy link
Contributor

@tinsukE tinsukE commented Mar 11, 2024

Cancel the auto-hide behavior in case the toolbar menu items are interacted with.

Improves #505, #507

Cancel the auto-hide behavior in case the toolbar menu items are interacted with.
Copy link
Contributor

@nikclayton nikclayton left a 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:

  1. Create a ViewMediaActivityViewModel, that contains the state of the toolbar's visibility (as a MutableStateFlow internally, externally presented as a StateFlow)
  2. 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.
  3. 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.

@tinsukE tinsukE force-pushed the 505-hide-image-toolbar-menu-item branch from c018bf3 to 799ffda Compare March 12, 2024 09:49
@tinsukE tinsukE force-pushed the 505-hide-image-toolbar-menu-item branch from 799ffda to c34c4e8 Compare March 12, 2024 10:07
@tinsukE
Copy link
Contributor Author

tinsukE commented Mar 12, 2024

@nikclayton I took a stab at the proposed ViewModel refactoring: tinsukE#2

I could keep the PRs separate or add that commit to this one.

@nikclayton
Copy link
Contributor

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.

In hindsight, understanding the whole class hierarchy could've given me a better insight on how to make the changes.

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
@tinsukE
Copy link
Contributor Author

tinsukE commented Mar 13, 2024

@nikclayton I addressed the comments on the refactor PR and merged it here.

It now seems good to merge to me!

- Rename variable for clarity
- Override the MenuProvider functions, and call super.onCreateMenu() so
  other menu items (like "Send error report") are shown
- Document the onPrepareMenu behaviour and link to relevant Google bug
@nikclayton
Copy link
Contributor

@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

@tinsukE
Copy link
Contributor Author

tinsukE commented Mar 13, 2024

Alright, it looks good!

I see the clarity brought by the rename and flag value inversion, but why make the MenuProvider change?

@nikclayton
Copy link
Contributor

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).

@nikclayton nikclayton merged commit 5be93ac into pachli:main Mar 13, 2024
6 checks passed
@tinsukE tinsukE deleted the 505-hide-image-toolbar-menu-item branch March 13, 2024 19:24
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.

None yet

2 participants