오윤석

auth api 연결

......@@ -95,4 +95,22 @@ public class Api {
}
}.start();
}
static public void auth(String doorId, final Callback callback) {
JsonObject params = new JsonObject();
params.addProperty("door_id", doorId);
callApi("GET", "/api/auth", params, new Callback() {
@Override
public void callbackMethod(Object obj) {
ApiResult apiResult = (ApiResult) obj;
if(apiResult.isSuccess()) {
JsonObject resp = (JsonObject) apiResult.getData();
if(resp.get("is_available").getAsBoolean()) {
callback.callbackMethod(true);
}
}
callback.callbackMethod(false);
}
});
}
}
......
......@@ -18,6 +18,7 @@ import android.widget.Toast;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.sunnni.smartdoorlock.R;
import com.sunnni.smartdoorlock.api.Api;
public class SplashActivity extends AppCompatActivity {
......@@ -67,13 +68,18 @@ public class SplashActivity extends AppCompatActivity {
if("".equals(text)){
Toast.makeText(getApplicationContext(),"고유번호를 입력해주세요.",Toast.LENGTH_SHORT).show();
} else {
// TODO : API 연결
if("123456".equals(text)) {
Api.auth(text, new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
Boolean success = (Boolean) obj;
if(success) {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
} else {
Toast.makeText(getApplicationContext(),"고유번호를 확인해주세요.",Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
......