We have a lot of code like this:
mHandler.getOperation().observe(this, new Observer<Resource<IdpResponse>>() {
@Override
public void onChanged(Resource<IdpResponse> resource) {
if (resource.getState() == State.LOADING) {
getDialogHolder().showLoadingDialog(R.string.fui_progress_dialog_signing_in);
return;
}
getDialogHolder().dismissDialog();
if (resource.getState() == State.SUCCESS) {
// ...
} else if (resource.getState() == State.FAILURE) {
// ...
}
}
});
In particular the LOADING bits almost always look the same. We could make something like:
public class ResourceObserver<T> extends Observer<Resource<T>> {
@Override
public void onChanged(Resource<T> resource) {
if (resource.getState() == State.LOADING) {
onLoading()
} else {
onNotLoading(resource);
}
}
protected void onLoading() {
// .. Do standard stuf
}
protected abstract void onNotLoading(...);
}
We have a lot of code like this:
In particular the
LOADINGbits almost always look the same. We could make something like: