-
Notifications
You must be signed in to change notification settings - Fork 17
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
Quick Editor - Alt text feature foundations #501
base: trunk
Are you sure you want to change the base?
Conversation
📲 You can test the changes from this Pull Request in Gravatar Demo by scanning the QR code below to install the corresponding build.
|
9d28fbf
to
fe57213
Compare
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AltTextSection.kt
Outdated
Show resolved
Hide resolved
fe57213
to
4dd4122
Compare
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.
I've left some comments/ideas that I think are worth discussing. Additionally, I think we need to handle the system back button to hide the Alt text section only, not the whole bottom sheet. There's no way to exit this state now without saving the new Alt text.
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AltTextSection.kt
Outdated
Show resolved
Hide resolved
if (uiState.mainSection is MainContentSection.AvatarsSectionUiState) { | ||
key(uiState.avatarUpdates) { | ||
ProfileCard( | ||
profile = uiState.profile, | ||
modifier = Modifier.padding(horizontal = 16.dp), | ||
) | ||
} |
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.
❓ Have you considered creating a new page for the Alt text
functionality? We could use nested graphs for this. Although it might look more time-consuming, I think it could lead to:
- Simplified UI code. There wouldn't be a need for several checks like this to show/hide section.
- Potentially simpler integration with the
Close/Cancel
button from theTopBar
. This is a very top-level component, so having a nested destination would simplify working with it as it's closer.
If you prefer to keep it like this, maybe we should wrap the whole AvatarPicker (card and the section) and only do one of those checks (if section) in one place. This would also simplify any type of enter/exit animations I think.
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.
I'll take a look at the nested graphs. Thanks for the suggestion.
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.
I've done a lot of refactoring in this PR using a nested graph. As you mentioned, the code looks cleaner (at least in my opinion).
Potentially simpler integration with the Close/Cancel button from the TopBar.
This still will cause some "problems" so we'll need to figure out how to solve this. One option could be to move the TopBar inside each section, but I haven't thought deeply about this.
Anyway, let me know what you think about the current approach.
I think we can still do another step and create a different ViewModel for the AltText section. Extracting the code related to the AltText should be "easy", the problem here is that we'll need to also make a way to sync the data between them. We can iterate over this in the following PRs.
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.
I think we can still do another step and create a different ViewModel for the AltText section. Extracting the code related to the AltText should be "easy", the problem here is that we'll need to also make a way to sync the data between them. We can iterate over this in the following PRs.
I think we should do that. I left a comment related to that.
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.
Working on it ⚙️
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.
I've extracted the AltText related code to it's own ViewModel. The AvatarPickerViewModel
handles only the rating changes so I've also refactored that code to remove all the unnecessary stuff.
we'll need to also make a way to sync the data between them
This PR doesn't accomplish that part. I think we should work on that in a different PR. For the moment, the AltText won't be updated in the local data models (it's updated in the backend) until the bottomsheet is closed and reopened again. (Which forces the data to be loaded from the server). #516
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AltTextSection.kt
Outdated
Show resolved
Hide resolved
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AltTextSection.kt
Outdated
Show resolved
Hide resolved
9bc1b80
to
2f1ddaf
Compare
We have an issue to limit the number of characters #502, when we implement that feature, I would say this won't be a huge problem, but we'll see. |
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/alttext/AltTextSection.kt
Outdated
Show resolved
Hide resolved
2f1ddaf
to
e2ae454
Compare
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.
That looks better now I think! I've left a few comments that are worth addressing first.
I noticed that the Avatar in the profile card refreshes after coming back from the AltText section. I believe it's not directly related to this PR, but something that we should take a look at.
...atar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/GravatarQuickEditorPage.kt
Outdated
Show resolved
Hide resolved
...atar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/GravatarQuickEditorPage.kt
Outdated
Show resolved
Hide resolved
...atar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/GravatarQuickEditorPage.kt
Outdated
Show resolved
Hide resolved
val editorViewModel: AvatarPickerViewModel = viewModel( | ||
factory = AvatarPickerViewModelFactory( | ||
gravatarQuickEditorParams = gravatarQuickEditorParams, | ||
handleExpiredSession = true, | ||
), | ||
) |
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.
AvatarPickerViewModel
service QE relaunches. You can see that when you close/open the QE, there's no initial loading.
I wonder if this would be problematic for apps that provide the token. In a scenario where the user changes but the ViewModel survives and persists the previous data.
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.
My suggestion would be to opt for a separate ViewModel anyway. So maybe it's not worth thinking about how to fix that.
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/alttext/AltTextSection.kt
Outdated
Show resolved
Hide resolved
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/alttext/AltTextSection.kt
Outdated
Show resolved
Hide resolved
I created an issue for the Avatar reload - #514 |
In the Figma file the height is fixed to 50.dp
4e29afe
to
3f3eb15
Compare
gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/alttext/AltTextPage.kt
Fixed
Show fixed
Hide fixed
} | ||
} | ||
|
||
private fun updateAvatar(avatarId: String, rating: Avatar.Rating? = null, altText: String? = null) { | ||
private fun updateAvatarRating(avatarId: String, rating: Avatar.Rating? = null) { |
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.
The AvatarPicker modifies only the Rating
so there is no need for the generic method that allow the altText
update. I've remove/renamed all the related code.
3f3eb15
to
29c3a14
Compare
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.
Thanks for all the updates! Tested it and all worked fine!
altText = altText, | ||
avatarUrl = avatarUrl, | ||
onBackPressed = { navController.popBackStack() }, | ||
modifier = Modifier.padding(16.dp), |
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.
❓ All other pages define their own paddings, rather than it being set here. Is there a reason you did it here?
_uiState.update { currentState -> | ||
currentState.copy( | ||
altText = newAltText, | ||
isSaveButtonEnabled = newAltText != altText, |
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.
When the newAltTest
is empty the API call returns 200, but it doesn't update it. Looks like it quietly fails. Should we disable the save button in such cases?
Closes #497
Description
This PR implements the foundations of the
Alt Text
feature. It doesn't include all of the functionality, as some parts still need to be implemented/improved. See sub-issuesI'm opening this PR for two reasons:
The basic functionality, which is changing the alternative text for an image, is implemented.
You should be able to see the confirmation toast and the error toast when something fails.
Testing Steps
Save
is enabled when the value is different from the original alt text