-
-
Notifications
You must be signed in to change notification settings - Fork 321
Use view binding to get rid of findViewById #3890
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
base: main
Are you sure you want to change the base?
Conversation
d81cad4 to
5f52963
Compare
|
Nice work! This is something I also wanted to do at some point. I'll have a look at running the emulator in CI, but for now you can add the test case to the repo and execute it locally. |
|
Added the test, and it even found something ;-) Unfortunately it doesn't seem possible to exempt single views from being included in the binding. |
|
@mueller-ma This conflicts with #3898, I guess check that one first? I'll rebase and undraft this one afterwards. |
Only exception is WidgetAdapter due to its internal complexity. Signed-off-by: Danny Baumann <[email protected]>
Signed-off-by: Danny Baumann <[email protected]>
Also fix the one incompatible layout spotted by the unit test. Signed-off-by: Danny Baumann <[email protected]>
d3dab3f to
dc05bd2
Compare
mobile/src/main/java/org/openhab/habdroid/ui/preference/widgets/UrlInputPreference.kt
Show resolved
Hide resolved
mobile/src/main/java/org/openhab/habdroid/ui/preference/widgets/ItemAndTogglePreference.kt
Show resolved
Hide resolved
Signed-off-by: Danny Baumann <[email protected]>
Using findViewById is somewhat error prone due to the lack of a direct relationship between the XML description and the usage in code. View binding automatically generates code for creating that relationship.
I've sat on this for quite some time now, for two reasons:
WidgetAdapter, which caused that class to even grow (other code paths became smaller due to less internal member variables andfindViewByIdcalls)For the latter point, writing a unit test should be easy in theory (have a list of widget-layout-binding to compact-widget-layout-binding, inflate the former, bind the latter to the root view of the former), but this needs to be an instrumented Android unit test, and I'm not sure if and how this can be run in GH actions.
@mueller-ma Please let me know your thoughts on this.
TODO:
PrimaryServerPreferencecurrently crashes on bind