-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve media displayed in widgets [VideoWidget + ExVideoWidget] #6925
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
Conversation
|
@seadowg Not long ago, we merged the first PR towards #6234 - a refactoring of the Barcode and File widgets (#6534). Although that wasn’t too recent, the pull request had been open for quite a while and was originally created when we thought adopting Jetpack Compose wouldn’t be possible anytime soon. Things have changed since then, and we’ve now started using Jetpack Compose. I was eager to work with Jetpack Compose, and I’m really happy that it’s now feasible. The ongoing widget rework (#6234 and #6084) will introduce many changes, and I don’t think continuing to use the old view system makes sense. On the contrary, this is a great opportunity to implement everything with Jetpack Compose. Here’s what I’ve done so far here:
I hope you’ll like this direction as much as I do. Although it might take a bit more time to build everything this way compared to the old Android views, I’m confident it’s the right move and will pay off in the long run. The PR is actually ready for review, but I’m keeping it as a draft for now to give you a chance to get familiar with the idea first. |
I just wanted to clarify this quickly! So basically, if we were building a widget from scratch you'd still create a Also, do you think we should add a Composable that shows a different "answer" Composable based on the answer data? Obviously the widgets know exactly which kind of data they deal with, but the hierarchy will probably need something like that. It might be nice to prove that out now.
I do like it! I am though wondering if, to minimize the amount of work we have to do to get to having components that can be shared with the hierarchy, we should just create Composables for the "answers" in the media widgets and hold off on reworking the rest of each widget's UI for now? So here for this example we'd just create and use the |
Correct. It’s great that we can do it this way because it lets us introduce Jetpack Compose step by step. Otherwise, we’d have to rewrite the entire widget architecture, which we’d probably never do since it would be too big of a task.
That’s also correct, and that’s why I mentioned that PR in my comment. It’s a step back, but considering that we’ll probably be reworking many widgets (maybe even all of them), it still makes sense.
Not based on the answer data, because for example, the
I understand that I was also torn between those two solutions, but the temptation to rewrite the entire widget using Jetpack Compose turned out to be too strong 😃. I’ll keep that in mind, so if doing the same for other widgets turns out to be too time-consuming, I can always limit it to the answer view. |
Good point: question type is the important thing really. And like everything in Compose, that would just end up being another
Agreed. Doesn't need to be a rule, just something to keep in mind. |
b7581fc to
689cacd
Compare
seadowg
left a comment
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 got some initial thoughts on the Compose code that's probably worth discussing before reviewing any further: I imagine it might lead to structure changes.
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswer.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswer.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswer.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswer.kt
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetContent.kt
Outdated
Show resolved
Hide resolved
seadowg
left a comment
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.
Just some more Compose structural things to discuss!
collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswerFactory.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswerFactory.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswerFactory.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswerFactory.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswerViewModel.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswerViewModel.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswerViewModel.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswerFactory.kt
Outdated
Show resolved
Hide resolved
seadowg
left a comment
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.
a6a2fe0 to
ddf5a3e
Compare
seadowg
left a comment
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.
Just a couple of tweaks it would be cool to make here, but looks great!
One thought to discuss: I think as we move forward with Compose we should try and push as much testing as reasonable into the component ("unit") level. I think not reworking all of that here and keeping the testing structure as-is was the right call for this change though.
androidtest/src/main/java/org/odk/collect/androidtest/NodeInteractionExtensions.kt
Outdated
Show resolved
Hide resolved
| ) | ||
| } | ||
|
|
||
| widgetAnswer() |
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.
One quick tweak that we could make here and in VideoWidgetContent: you could place this call in a Box (or some other simple container) that adds the margin so that can be a concern of the layout code here rather than in the passed Composable declaration.
collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswer.kt
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswer.kt
Show resolved
Hide resolved
|
It seems that the preview image isn't generated on older devices- on Android 8.1 and 7.1.1 there's the preview but it is gray (no picture). |
This should work fine now. |
|
Tested with success Verified on Android 16, 11, 10 Verified cases:
|
|
Tested with success Verified on Android 10, 8.1, 7.1.1 |
Work towards #6234
Why is this the best possible solution? Were any other approaches considered?
As discussed in the comments, using Jetpack Compose appears to be the right approach for refactoring here.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
We need to test the whole Video and ExVideo widgets for regression, plus their new way of displaying the answer.
Do we need any specific form for testing your changes? If so, please attach one.
No.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
./gradlew connectedAndroidTest(or./gradlew testLab) and confirmed all checks still passDateFormatsTest