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
Added Compose Previews for NFC, Onboarding & Companion Views #4239
Conversation
* Compose Preview created for ChooseEntityView * Nfc view previews added * Added onboarding previews * Fixed ktlint errors * Author Test ---------
wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt
Outdated
Show resolved
Hide resolved
wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/io/homeassistant/companion/android/onboarding/manual/ManualSetupView.kt
Show resolved
Hide resolved
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.
Looks good to me, thanks for the contribution!
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.
Functionally this looks good! A couple of small suggestions to clean up the code and for consistency.
(Also, unless there is a merge conflict or requested, you don't need to rebase/merge the latest commits to the branch.)
@Composable | ||
fun DiscoveryView( | ||
onboardingViewModel: OnboardingViewModel, | ||
manualSetupClicked: () -> Unit, | ||
instanceClicked: (instance: HomeAssistantInstance) -> Unit | ||
) { | ||
DiscoveryView(foundInstances = onboardingViewModel.foundInstances, manualSetupClicked = manualSetupClicked, instanceClicked = instanceClicked) | ||
} |
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.
Why keep this around? You can update the fragment to use the 'new'/updated function.
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.
@jpelgrom This is only for compose previews. Basically, if we use the second one we need to expand the parameters of un DiscoveryView(
onboardingViewModel: OnboardingViewModel,
manualSetupClicked: () -> Unit,
instanceClicked: (instance: HomeAssistantInstance) -> Unit
) {
to include everything that we use in onboardingViewModel
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.
@jpelgrom Read here real quick https://developer.android.com/jetpack/compose/tooling/previews#preview-viewmodel
"If you want to preview a composable that uses a ViewModel, you should create another composable with the parameters from ViewModel passed as arguments of the composable. This way, you don't need to preview the composable that uses the ViewModel."
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 understand this is required for the Compose previews. My point was: if this is what we need, why keep the other function that uses a ViewModel as well instead of switching it to use this new constructor? I see little to no advantage, and with these changes you need to update both functions anyway.
if we use the second one we need to expand the parameters of un DiscoveryView (...) to include everything that we use in onboardingViewModel
You don't, as you've already proven with the function you've added. For DiscoveryView
, you only need/use onboardingViewModel.foundInstances
.
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.
Please update this as requested (or give more arguments to convince why not :)) to proceed.
fun ManualSetupView( | ||
onboardingViewModel: OnboardingViewModel, | ||
connectedClicked: () -> Unit | ||
) { | ||
ManualSetupView(onboardingViewModel.manualUrl, onboardingViewModel::onManualUrlUpdated, onboardingViewModel.manualContinueEnabled, connectedClicked) | ||
} |
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.
Why keep this around? You can update the fragment to use the 'new'/updated function.
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.
See #4239 (comment)
app/src/main/java/io/homeassistant/companion/android/nfc/views/NfcWriteView.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/io/homeassistant/companion/android/nfc/views/NfcWriteView.kt
Outdated
Show resolved
Hide resolved
wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt
Outdated
Show resolved
Hide resolved
wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt
Outdated
Show resolved
Hide resolved
@Composable | ||
fun DiscoveryView( | ||
onboardingViewModel: OnboardingViewModel, | ||
manualSetupClicked: () -> Unit, | ||
instanceClicked: (instance: HomeAssistantInstance) -> Unit | ||
) { | ||
DiscoveryView(foundInstances = onboardingViewModel.foundInstances, manualSetupClicked = manualSetupClicked, instanceClicked = instanceClicked) | ||
} |
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.
Please update this as requested (or give more arguments to convince why not :)) to proceed.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Summary
Adding in more compose previews for new (and experienced) devs to remember what the screens look like at a glance. Allows for easier font sizing, style checking, etc
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes