Search in sources :

Example 1 with GlobalStateVM

use of im.actor.core.viewmodel.GlobalStateVM in project actor-platform by actorapp.

the class JsBindingModule method getOnlineStatus.

public JsBindedValue<String> getOnlineStatus() {
    if (onlineState == null) {
        final GlobalStateVM vm = context().getConductor().getGlobalStateVM();
        onlineState = new JsBindedValue<>("online");
        vm.getIsConnecting().subscribe(new ValueChangedListener<Boolean>() {

            @Override
            public void onChanged(Boolean val, Value<Boolean> valueModel) {
                if (val) {
                    onlineState.changeValue("connecting");
                } else {
                    if (vm.getIsSyncing().get()) {
                        onlineState.changeValue("updating");
                    } else {
                        onlineState.changeValue("online");
                    }
                }
            }
        });
        vm.getIsSyncing().subscribe(new ValueChangedListener<Boolean>() {

            @Override
            public void onChanged(Boolean val, Value<Boolean> valueModel) {
                if (vm.getIsConnecting().get()) {
                    onlineState.changeValue("connecting");
                } else {
                    if (val) {
                        onlineState.changeValue("updating");
                    } else {
                        onlineState.changeValue("online");
                    }
                }
            }
        });
    }
    return onlineState;
}
Also used : GlobalStateVM(im.actor.core.viewmodel.GlobalStateVM)

Aggregations

GlobalStateVM (im.actor.core.viewmodel.GlobalStateVM)1