Travis Griggs
09/16/2019, 8:09 PMTravis Griggs
09/16/2019, 8:18 PMinit
block that builds up all of the subview structure and hooks up actions for buttons and stuff.
What is the basic pattern for replacing all of that view construction code with my xml designed UI? Can I do this without rewriting the entire app and just restrict it to this corner of the app? If there’s a basic tutorial somewhere that would help me see the big picture here, that would be great. An explanation of the pieces as seen from iOS/Swift would be awesome too, since I’m pretty comfortable with storyboards, UIKit, outlets, etc.reline
09/16/2019, 8:22 PMSteve
09/16/2019, 8:32 PMTravis Griggs
09/16/2019, 8:54 PMCould not find method viewBinding() for arguments [build_epgt9mufy5of61p0aisu2b2dd$_run_closure1$_closure5@5c8457d7] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
reline
09/16/2019, 8:59 PMwasyl
09/16/2019, 9:20 PMclass file that defines a FlowVerificationSettingsPanel which is a subclass of ConstraintLayoutHow is this class used? Because you really want to substitute usages of this class by your new xml layout, do I understand correctly? What’s important is: how is instance of this class obtained, and roughly how the listeners are being hooked up. You can create an instance of your layout by writing
LayoutInflater.from(context).inflate(R.layout.viewId, parent, [true|false])
, where parent
is the view to which the original FlowVerificationSettingsPanel
was added. For example if it was added in another layout defined in Kotlin, you’d simply call this this LayoutInflater#inflate
there.wasyl
09/16/2019, 9:23 PMfindViewById
or by using Butterknife, Kotterknife, Kotlinx Android synthetic view extension, by using Databinding or the new ViewBinding if you’re on AGP 3.6-alpha10+ Ithink) and call appropriate methods like setOnClickListener
.
I personally strongly recommend looking into how you can incorporate DataBinding into the XML you have, for example by encapsulating view’s contract in a separate class. It helps a lot in terms of reducing boilerplate of finding views and setting proper listenersTravis Griggs
09/16/2019, 9:30 PMwasyl
09/16/2019, 9:43 PMTravis Griggs
09/16/2019, 9:43 PMwasyl
09/16/2019, 9:43 PMreline
09/16/2019, 9:45 PMwasyl
09/16/2019, 9:45 PMTravis Griggs
09/16/2019, 10:48 PMwasyl
09/16/2019, 10:53 PMTravis Griggs
09/16/2019, 11:03 PMwasyl
09/16/2019, 11:16 PMSteve
09/16/2019, 11:19 PMTravis Griggs
09/16/2019, 11:19 PMTravis Griggs
09/16/2019, 11:20 PMwasyl
09/16/2019, 11:39 PMIs there a camp that makes the most sense for a guy who’s pretty comfortable with Swift/iOS/UIKit to adhere to?No 😄 I mean, I don’t think you’ll find lots of similar patterns that touch the framework, because they’re too different in those places that matter — for example in iOS you can create view and push onto a stack manually (I suppose maybe Conductor would be interesting, then? I haven’t used it), on Android it’s one of the bigger points of discussion without clear winner. And overall I think most of the system has just different philosophy. But these are just observations from the iOS code I see written by colleagues, so perhaps someone with more experience will chime in.
wasyl
09/16/2019, 11:39 PMwasyl
09/16/2019, 11:42 PMPart of the thing is that, for the longest time, Google refused to have any kind of opinionDefinitely true, at some point developing new frameworks became popular. That said I feel like now even with Google’s opinion you get even more discussion, because now people will strongly feel Google’s way is right or wrong 😄
louiscad
09/17/2019, 6:56 AMrkeazor
09/17/2019, 10:28 AMrkeazor
09/17/2019, 10:35 AMTravis Griggs
09/17/2019, 6:02 PMSteve
09/17/2019, 6:10 PMwasyl
09/17/2019, 6:36 PMSteve
09/17/2019, 6:37 PMwasyl
09/17/2019, 6:46 PMlouiscad
09/17/2019, 10:34 PM<include/>
), no preview of things you do in code. Many arguments against xml linked in Splitties Views DSL README and in Countour (by Square/CashApp) README as well.louiscad
09/17/2019, 10:40 PMabove
, below
, before
and after
extensions as alternatives to bottomToTopOf
and all, along with lastChild
extension property. With these two things, layout code will be even more readable, but will also support reordering seamlessly. (This is currently in the develop branch)
It might be a matter of preferences. I'm happy with what I use, and I tried both (plus Anko).Steve
09/17/2019, 10:44 PMlouiscad
09/17/2019, 10:51 PMcompileDebugKotlin
Gradle task. Most of the time, it runs in less than 2 seconds and refreshes the xml preview automatically.