4

In RoboBinding there is the annotation DependsOnStateOf. When using it in a PresentationModel like this:

@PresentationModel
class GreetingPresentationModel {
    String firstname;
    String lastname;
    //getters and setters for both
    @DependsOnStateOf("firstname")
    public boolean isLastnameInputEnabled() {
        return !TextUtils.isEmpty(firstname);
    }
}

This doesn't work. The following binding will be always false and doesn't change.

bind:enabled="{lastnameInputEnabled}"

What's wrong?

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91

1 Answers1

0

Looking into the RoboBinding AndroidMVVM example, it is crucial to implement HasPresentationModelChangeSupport using PresentationModelChangeSupport and make setters call firePropertyChange:

@PresentationModel
public class GreetingPresentationModel implements HasPresentationModelChangeSupport {
    PresentationModelChangeSupport changeSupport;

    @Override
    public PresentationModelChangeSupport getPresentationModelChangeSupport() {
        return changeSupport;
    }

    public GreetingPresentationModel() {
        changeSupport = new PresentationModelChangeSupport(this);
    }
    // Rest of the code here
    // Then change each setter, e.g.
    public void setFirstname(String firstname) {
        this.firstname = firstname;
        changeSupport.firePropertyChange("firstname");
    }
}
  • 2
    you can add RoboBinding aspectJ support to avoid manually writing firePropertyChange code. It will auto weave in firePropertyChange code for you. – Cheng Jul 24 '15 at 21:34
  • @Cheng is there a way we can do this or firePropertyChange() from within an ItemPresentationModel ? – beerBear Aug 10 '16 at 09:49
  • @Cheng btw much thanks for the work you're doing for RoboBinding :) – beerBear Aug 10 '16 at 10:04
  • @beerBear You can do all that PresentationModel can do in ItemPresentationModel. ItemPresentationModel is a conceptual extension of PresentationModel. – Cheng Aug 12 '16 at 02:08