Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Login presenter
package com.myapp.core.mvp.home.login;
public class LoginPresenter extends BasePresenter<LoginContract.LoginView> implements LoginContract.ViewAction {
private APIManager apiManager;
private PreferenceService preference;
private INetworkManager networkManager;
private Repository<Login> eventRepository;
public LoginPresenter(APIManager apiManager, PreferenceService preference,
INetworkManager networkManager, Repository<Login> eventRepository) {
this.apiManager = apiManager;
this.preference = preference;
this.networkManager = networkManager;
this.eventRepository = eventRepository;
}
@Override
public void onUserLogin(@NonNull Login login) {
if (!isViewAttached()) return;
getView().showMessageLayout(false);
if (networkManager.isConnected()) {
getView().showProgress();
apiManager.loginUser(login, new RemoteCallback<LoginResponse>() {
@Override
public void onSuccess(LoginResponse response) {
if (!isViewAttached()) return;
getView().hideProgress();
if (response.getSuccess() == HttpsURLConnection.HTTP_OK) {
getView().onLoginSuccess();
} else {
getView().showError("Status " + response.getSuccess());
}
}
@Override
public void onUnauthorized() {
getView().hideProgress();
getView().showUnauthorizedError();
}
@Override
public void onFailed(Throwable throwable) {
getView().hideProgress();
getView().showError(throwable.getMessage());
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment