B4A Library Observable

Observables are primitive types (boolean, byte, double, float, integer, long, short), strings, objects or collections (map, list, record) that trigger events when they are modified. They can also automatically update the views with which they are bound.

Example 1: You have associated an ObservableString with all the OK buttons of your application. By changing the value of this Observable (e.g. ofConfirmButton.Value = "OK"), you change at the same time the label of all OK buttons, regardless of the activity in which they are declared.

Example 2: In your application, you want to perform a task each time a list is modified by your code (e.g. saving the content to a file), regardless of the activity or sub in which that list is modified. By using an ObservableList, it becomes easy to perform the task according to the triggered event (Added, Cleared, Removed, Sorted, Updated).

Example 3: You have linked an ObservableField to a field in a database table. By changing the ID of this Observable, you get the value of the field corresponding to this ID and you trigger an Updated event. By changing the Observable value, you update the field in the database and trigger an Updated event.

Please note that this library is not based on the Observable class of Java. Its code is entirely written from scratch.

It exists a version for B4J here.
 

Attachments

  • Observable v1.1.zip
    60.6 KB · Views: 537
Last edited:

fredo

Well-Known Member
Licensed User
Longtime User
Wonderful. Just wow. Finally.
Now I might start the next App with a MVVM approach.

03-07-_2018_16-44-35.jpg
 

Lello1964

Well-Known Member
Licensed User
Longtime User
for example a db editing:
add new record, edit & save, erase, move top,next,prev,bottom..
 

Informatix

Expert
Licensed User
Longtime User
for example a db editing:
add new record, edit & save, erase, move top,next,prev,bottom..
Did you see the DBFields demo? You can extend it with other queries (with INSERT or DELETE statement), however the additional work is more related to SQL than to the Observable library. In all cases, you have to notify the observers by setting the ID of ObservableFields. For example, if you add a DELETE button, you have to change the ID of ObservableFields after performing the removal query to display the previous or next record. If you add an INSERT button, you have to set the new ID to display the new record when the query is done.
This lets me think I could add a new class to my library. Stay tuned...
 

Informatix

Expert
Licensed User
Longtime User
A new version is available. It adds three new classes (ObservableRecord, ObservableRecordSelection, ObservableShort) and a new demo (DBFields method #3) using an ObservableRecord.
I don't think that querying/updating a SQlite database can be simpler than doing it with the new ObservableRecord. It can be bound to multiple views (one by field).
 

Guenter Becker

Active Member
Licensed User
Do'nt recognized that but I think that it is not bad to have another example. Any problem with this?
 
Top