Android binding framework: a deception

Data binding is a wonderful feature for user interface developement. It ease the development process, help to clean the code, and do a lot of the job for you.

A quick insight of the gain

You have a form screen, we will take the android materiel design sample:

Drawing

Before databinding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

TextView tv;
User user = DataManager.getActiveUser();

public void onCreate(){
[...]
tv = findViewById(R.id.name);
tv.setText(user.name);
}

public void validate(){
String name = tv.getText().toString();
}

We have to get each views by id or by annotations libraries. We use them by calling the getters and setters when we need

With Binding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{user.name}" />

User user = DataManager.getActiveUser();

public void onCreate(){
[...]
binding.setUser(user);
}

public void validate(){
String name = user.getName();
}

Notice the removable of the id, an information that has now become irrelevant. Things are automatics. The data (should) be a direct image of what is in the screen.
If the Java code change the name, it is immediatly set in the TextView without setText(),.
If the user tap some characters, the model is updated without tv.getText();

Other cool stuff you can do

You want to bind the color or the text to a custom rules (red if too short, green if ok)?
You can do it without multiple lines of java code.

You want to link the progress of a ProgressBar to the advance of a media object?
Just do it in one line of XML.

You want to set a view’s visibility according to your data, nothing easier:

1
android:visibility="@{user.hasAccount ? View.VISIBLE : View.GONE}"

The deception

When google announced the beta of Android binding it was a wonderful news.
When they released the guide, it was wonderful too. A lot of features were availables (converters, expressions, collection support, …)

But, using the android databinding framework has proven to be quite a deception after working with Qt or Windows store sdk:

Not as straightforward as concurrents

A library to include, ViewModels to be declared in each layout, different layout root, other generated class to import, a different way to inflate fragment’s layout.
It is expectable since DataBinding is not included as part as Android SDK. But we see the difference compared to a language designed with binding in mind.

Verbose viewmodel

Android binding require you to change your model, making it extend a specific class from the binding API, or worst, transform all your members into an observable instead of a simple type (Observable instead of String).

This is not acceptable for a clean structure, as well as for Gson auto deserializing. So the solution is exposing every attributes of the model inside the viewModel, which is sooo verbose.

Where the ** is the 2-ways binding?

There is no 2-way binding. Some hacks are available, but it is not a good long term solution for a complex project.
Good bye auto-handled form (the typical always annoying screen to implement), where databinding is nothing else than a saviour.

Manger au Japon

Petit déjeuner:
Saumon grillé, bol de riz, soupe et petits accompagnements pour bien démarrer la journée

Katsudon:
Porc pané dans une omelette, posée dans un bol de riz tapissé d’oignons. Toujours bon.

Tonkotsu Ramen:
Sans doute la meilleure soupe de nouilles au monde, et de mon point de vue le meilleur plat du Japon. Des os de porc ont été mijotés dans cette mixture, auquels ils ajoutent entre autre de l’ail brun et autres légumes avant d’y cuire les nouilles
Le service vient avec ail à volonté!

Okonomiyaki:
Si le plat est bon, l’intérêt se porte plus dans la fabrication que dans la dégustation.


Soba:
Nouilles Soba, à tremper dans de la sauce soja au wasabi. On peut boire le jus de cuisson des nouilles. Très simple mais bon.

Curry:
Si la sauce n’est pas aussi bonne qu’un curry indien, la viande panée rattrape bien le tout.

Haricots blancs confits:
S’il fallait donner la plus grosse différence culinaire entre les cuisines françaises et japonaises, ce serait la relation avec les haricots. Ici c’est utilisé comme le chocolat en france.

Chirachi
Censé être meilleur à Hokkaido, l’hiver ne doit sans doute pas être la meilleure saison pour déguster des fruits de mer crus.

Tempura:
Une merveille, de la panure partout autour de champignons, crevettes, légumes,….

Crêpes de canard chinoises:
Ne pas aller dans les restau chinois au Japon. Il nous a fallu négocier pour avoir de la viande et pas seulement de la peau dans ce plat déjà trop cher de crêpes de canard.

Moulin à sésame:

Open thé:
Le thé est en libre service, comme le pain peut l’être en France.

Pizza Bread

A full-fat meal you can bring in your role-play table, everybody will have sufficient food for exploring donjons all night.

Ingredients:

  • Chorizo
  • Using different cheeses is better for the taste :
    .. Mozarella for the texture
    ..
    Hard cheese for the taste (Comté, Beaufort, Gruyère, Cantal, …)
    ..* Cheddar (Has a strong taste for a cheap price)

  • Bread base, follow one of the multiple receipe to make your bread:
    https://www.meilleurduchef.com/cgi/mdc/l/fr/recette/boule-pain.html

Receipe:

  1. Make your bread, stop before cooking it
  2. Find a high tin with a small surface, add some flour at the bottom
  3. Put one layer of bread, one of cheese and one of chorizo
  4. Do it two or three time and finish by a layer of bread
  5. For a more tasty looking, spread the yellow of egg on the top, with some cheese chips
  6. Cook it like bread (230°) until the subtle smell of the cheese brings your neighbour into your house with his fork in hands.