Last active
October 22, 2018 19:55
-
-
Save LuiguiBalarezo/a5f99c19bdfefbfc9d0919065005994b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zeta.scriptgo.zentinela.apiservice; | |
import android.content.Context; | |
import android.util.Log; | |
import com.zeta.scriptgo.zentinela.Async.AsyncLogin; | |
import com.zeta.scriptgo.zentinela.HttpCallBacks.HttpCallBack; | |
import com.zeta.scriptgo.zentinela.HttpCallBacks.HttpInterfaceCallBack; | |
import com.zeta.scriptgo.zentinela.Utils.ObjectResult; | |
import com.zeta.scriptgo.zentinela.base.BaseService; | |
import com.zeta.scriptgo.zentinela.constans.ConstansHelps; | |
import com.studioidan.httpagent.HttpAgent; | |
import com.studioidan.httpagent.StringCallback; | |
import com.zeta.scriptgo.zentinela.models.Usuario_M; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
/** | |
* Created by lbalarezo on 22/10/2018. | |
*/ | |
public class LoginService extends BaseService { | |
private boolean execute_login = false; | |
HttpAgent httpAgent_login; | |
private static LoginService dialoginstance = null; | |
private LoginService() { | |
} | |
public LoginService setContext(Context context) { | |
this.context = context; | |
return this; | |
} | |
public static LoginService getInstance() { | |
if (dialoginstance == null) { | |
dialoginstance = new LoginService(); | |
} | |
return dialoginstance; | |
} | |
public void validandoUsuario(String usuario, String clave, final HttpCallBack callback) { | |
this.callback = callback; | |
if (validateConnection()) { | |
if (!execute_login) { | |
execute_login = true; | |
callback.startprocess("Validando Usuario..."); | |
httpAgent_login = HttpAgent.post(ConstansHelps.URL_LOGIN) | |
.parallel(true) | |
.headers("Authorization", "Basic YWRtaW46P3V5YFZhNzAw", "Content-Type", "application/json") | |
.withBody("usuario", usuario, "clave", clave, "idapp", "3"); | |
httpAgent_login.goString(new StringCallback() { | |
@Override | |
protected void onDone(boolean success, String stringResults) { | |
execute_login = false; | |
callback.stopprocess(); | |
if (notEmpty(codehttpresponse)) { | |
new AsyncLogin(new AsyncLogin.CallBack() { | |
@Override | |
public void resultLogin(Usuario_M usuario_m) { | |
callback.responseStatus("Validacion Finalizada.", ConstansHelps.SUCCESS); | |
callback.successRealmObjectResult(usuario_m); | |
} | |
}).execute(objectResult.resultArray); | |
} | |
} | |
@Override | |
protected String getErrorMessage() { | |
setResponseStatus(super.getErrorMessage()); | |
return super.getErrorMessage(); | |
} | |
@Override | |
public void setResponseCode(int responseCode) { | |
codehttpresponse = responseCode; | |
super.setResponseCode(responseCode); | |
} | |
@Override | |
public void setStringResults(String stringResults) { | |
objectResult = getProcessStringResult(stringResults, ConstansHelps.ARRAY); | |
} | |
}); | |
} else { | |
runprocess("Usuario"); | |
} | |
} | |
} | |
@Override | |
public void cancelAll() { | |
super.cancelAll(); | |
cancel_login(); | |
} | |
public void cancel_login() { | |
if (httpAgent_login != null && execute_login == true) { | |
execute_login = false; | |
callback.cancel("Validacion Cancelada"); | |
httpAgent_login.cancel(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment