오윤석

auth api 연결

...@@ -95,4 +95,22 @@ public class Api { ...@@ -95,4 +95,22 @@ public class Api {
95 } 95 }
96 }.start(); 96 }.start();
97 } 97 }
98 +
99 + static public void auth(String doorId, final Callback callback) {
100 + JsonObject params = new JsonObject();
101 + params.addProperty("door_id", doorId);
102 + callApi("GET", "/api/auth", params, new Callback() {
103 + @Override
104 + public void callbackMethod(Object obj) {
105 + ApiResult apiResult = (ApiResult) obj;
106 + if(apiResult.isSuccess()) {
107 + JsonObject resp = (JsonObject) apiResult.getData();
108 + if(resp.get("is_available").getAsBoolean()) {
109 + callback.callbackMethod(true);
110 + }
111 + }
112 + callback.callbackMethod(false);
113 + }
114 + });
115 + }
98 } 116 }
......
...@@ -18,6 +18,7 @@ import android.widget.Toast; ...@@ -18,6 +18,7 @@ import android.widget.Toast;
18 import com.google.android.material.textfield.TextInputEditText; 18 import com.google.android.material.textfield.TextInputEditText;
19 import com.google.android.material.textfield.TextInputLayout; 19 import com.google.android.material.textfield.TextInputLayout;
20 import com.sunnni.smartdoorlock.R; 20 import com.sunnni.smartdoorlock.R;
21 +import com.sunnni.smartdoorlock.api.Api;
21 22
22 public class SplashActivity extends AppCompatActivity { 23 public class SplashActivity extends AppCompatActivity {
23 24
...@@ -67,12 +68,17 @@ public class SplashActivity extends AppCompatActivity { ...@@ -67,12 +68,17 @@ public class SplashActivity extends AppCompatActivity {
67 if("".equals(text)){ 68 if("".equals(text)){
68 Toast.makeText(getApplicationContext(),"고유번호를 입력해주세요.",Toast.LENGTH_SHORT).show(); 69 Toast.makeText(getApplicationContext(),"고유번호를 입력해주세요.",Toast.LENGTH_SHORT).show();
69 } else { 70 } else {
70 - // TODO : API 연결 71 + Api.auth(text, new Api.Callback() {
71 - if("123456".equals(text)) { 72 + @Override
72 - startActivity(new Intent(SplashActivity.this, MainActivity.class)); 73 + public void callbackMethod(Object obj) {
73 - } else { 74 + Boolean success = (Boolean) obj;
74 - Toast.makeText(getApplicationContext(),"고유번호를 확인해주세요.",Toast.LENGTH_SHORT).show(); 75 + if(success) {
75 - } 76 + startActivity(new Intent(SplashActivity.this, MainActivity.class));
77 + } else {
78 + Toast.makeText(getApplicationContext(),"고유번호를 확인해주세요.",Toast.LENGTH_SHORT).show();
79 + }
80 + }
81 + });
76 } 82 }
77 } 83 }
78 }); 84 });
......