Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.unej.sisterforlecturer.main.presensi;
- import android.app.Activity;
- import android.util.Log;
- import com.google.android.material.dialog.MaterialAlertDialogBuilder;
- import com.unej.sisterforlecturer.config.controller.CheckIpLocalController;
- import com.unej.sisterforlecturer.config.controller.NetworkController;
- import com.unej.sisterforlecturer.config.endpoint.ipp.IppublicEndpoint;
- import com.unej.sisterforlecturer.config.manager.SessionManager;
- import com.unej.sisterforlecturer.config.network.Network;
- import org.json.JSONObject;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import okhttp3.ResponseBody;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- public class GetIpPublicHandler {
- private final String TAG = GetIpPublicHandler.class.getSimpleName();
- private Activity activity;
- public String ippublic;
- public String idRuang, ipRuang, versi, lokasi, sts_presensi;
- private SessionManager sessionClass;
- private MaterialAlertDialogBuilder builder;
- public GetIpPublicHandler(Activity activity, String idRuang, String ipRuang, String versi, String lokasi, String sts_presensi) {
- this.activity = activity;
- this.idRuang = idRuang;
- this.ipRuang = ipRuang;
- this.versi = versi;
- this.lokasi = lokasi;
- this.sts_presensi = sts_presensi;
- this.sessionClass = new SessionManager(activity);
- }
- public void doGetIp() {
- IppublicEndpoint ippublicEndpoint = Network.ippublic().create(IppublicEndpoint.class);
- Call<ResponseBody> call = ippublicEndpoint.getIppublic();
- call.enqueue(new Callback<ResponseBody>() {
- @Override
- public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
- try {
- ResponseBody body = response.body();
- Log.e(TAG, "onResponse: " + body );
- if (body == null) {
- String lokasi = new SessionManager(activity).getLokasi_long()+","+new SessionManager(activity).getLokasi_lat();
- CheckIpLocalController controller = new CheckIpLocalController(activity, idRuang, "",versi, lokasi, sts_presensi);
- controller.execute();
- } else {
- JSONObject object = new JSONObject(body.string());
- String ip = object.getString("ip");
- Log.e(TAG, "onResponse: " + ip );
- if (!sts_presensi.equals("7")) {
- Log.e("TAG", "onPostExecute: qrcode");
- PresensiHandler presensiHandler = new PresensiHandler(activity);
- presensiHandler.versi = versi;
- presensiHandler.idruang = idRuang;
- presensiHandler.ippublik = ip;
- presensiHandler.token = sessionClass.getToken();
- presensiHandler.lokasi = lokasi;
- presensiHandler.presensi();
- } else {
- Log.e("TAG", "onPostExecute: testbio");
- SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date today = new Date(System.currentTimeMillis());
- BiometricHandler handler = new BiometricHandler(activity);
- handler.timelog = formatDate.format(today);
- handler.versi = versi;
- handler.lokasi = lokasi;
- handler.idRuang = idRuang;
- handler.ippublik = ip;
- if (!new NetworkController().isNetworkAvailable(activity)) {
- handler.offline_store_presensi();
- } else {
- handler.biometricPresensi();
- }
- }
- }
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- @Override
- public void onFailure(Call<ResponseBody> call, Throwable t) {
- Log.e(TAG, "onFailure: IPPUBLIC " + t.getMessage() );
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement