Skip to content

Questions and Answers

Anton Kapitonov edited this page Sep 5, 2017 · 7 revisions

Do I have my Activity to extend ReampAppCompatActivity?

Reamp provides a couple of handy classes such as ReampAppCompatActivity, ReampFragment (from the support library) to use as a base class for your Activities and Fragments, but you don't have to extend them if you don't want to. In general, your activity, fragment, or custom view should implement ReampView interface and connect itself to a presenter through MvpDelegate class, just like ReampAppCompatActivity, ReampFragment do.

Do I have to call sendStateModel() when I change stateModel content?

Yes, Reamp does not track changes to your stateModel object. You should call sendStateModel() manually to notify the view that the state has been changed. Also, you can design your StateModel class to automatically call sendStateModel() when you change a StateModel field. Or invent your own way, it's up to you.

When is onStateChanged() first called?

When you connect your view to a presenter through MvpDelegate.connect(). If you use ReampAppCompatActivity or ReampFragment it is called within onStart()

How do I get strings from the resources inside a presenter?

We try to keep presenters aside from view's responsibilities. If you want to show a message then just create a constant for the message inside a StateModel class and let your view decide what string resource it wants to show for this message.

class MyState extends SerializableStateModel {
    public enum Message {
        OK(R.string.ok),
        CANCEL(R.string.cancel),
        ERROR(R.string.error);

        public final int resId;

        Message(int resId) {
            this.resId = resId;
        }
    }
    public Message message;
}

// MyPresenter
getStateModel().message = MyState.Message.OK;
sendStateModel();

// MyActivity
public void onStateChanged(MyState stateModel) {
    messageView.setText(stateModel.message.resId);
}