Skip to content

Instantly share code, notes, and snippets.

@billkainkoom
Created September 15, 2019 20:19
Show Gist options
  • Save billkainkoom/ee6a6fb9a0833531c591614fa89a8ec5 to your computer and use it in GitHub Desktop.
Save billkainkoom/ee6a6fb9a0833531c591614fa89a8ec5 to your computer and use it in GitHub Desktop.

Ogya Forms

There are hardly any android apps built without forms. It can be daunting especially when you have forms all over the place. Usually they lead to never ending xml files or really long xml files. And then there is the case where the form contains other elements which are not inputs eg info cards, images etc. Most at times we will just repeat the form code in all xmls that they are needed in or probably use the include tag (but there is no for-loop for (not that I know of though.)). We have already achieved component reuse by Componentization in Ogya. All we needed to do was to

1. Add a component that can accept input.

https://gist.github.com/6e0a960d9266a2b001f3be9e67d2e232

I see the confusion in type and inputType. So lets break that down.

type This just toggles between date,time and input. Basically they are all inputs but time gives you the opportunity to select from the android TimePicker, date also does the same but gives you a DatePicker instead. Both type time and date gives you an un-editable input. Type input allows you to use the keyboard as the input source.

2. Decide the keyboard type based on the input.

https://gist.github.com/e9280e514f7f8f639191472429676d27

As you can see the inputType parameter expects the android textInput type. Pass any of these and you will get its respective keyboard.

https://gist.github.com/a8dbd6364705d0590821fe0dafc447c4

3. Add a watcher to track value changes of input element.

https://gist.github.com/048776281b3550ed20183ea22b36556f

This means you can pass any layout you prefer. Just make sure of the following.

  1. The layout has an EditText with tag "input". If absent the watcher wont recognize any changes since its only watching for changes on an EditText with tag input.

  2. Your component's signature is https://gist.github.com/5ba8eafc66fa42fb09df635727b90cd9

ListableAdapter has been extended with one more function : retrieveFormValues https://gist.github.com/94a12e404f747ae40d2c1b2c652a5e04

And you use it like this: https://gist.github.com/ad4280b2da123377979f680667344ff0

And that's it!

https://gist.github.com/b72d6c98acccae890f48669307e6e856

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment