오윤석

원격 잠금해제 연결

1 package com.sunnni.smartdoorlock.api; 1 package com.sunnni.smartdoorlock.api;
2 2
3 +import android.os.Build;
3 import android.os.Handler; 4 import android.os.Handler;
4 import android.util.Log; 5 import android.util.Log;
5 6
...@@ -156,4 +157,21 @@ public class Api { ...@@ -156,4 +157,21 @@ public class Api {
156 } 157 }
157 }); 158 });
158 } 159 }
160 +
161 + static public void requestRemote(final Callback callback) {
162 + JsonObject params = new JsonObject();
163 + params.addProperty("device_name", Build.MODEL);
164 +
165 + callApi("POST", "/api/remote", params, new Callback() {
166 + @Override
167 + public void callbackMethod(Object obj) {
168 + ApiResult apiResult = (ApiResult) obj;
169 + if(apiResult.isSuccess()) {
170 + callback.callbackMethod(new Boolean(true));
171 + } else {
172 + callback.callbackMethod(null);
173 + }
174 + }
175 + });
176 + }
159 } 177 }
......
...@@ -22,6 +22,7 @@ import android.widget.Toast; ...@@ -22,6 +22,7 @@ import android.widget.Toast;
22 22
23 import com.google.android.material.navigation.NavigationView; 23 import com.google.android.material.navigation.NavigationView;
24 import com.sunnni.smartdoorlock.R; 24 import com.sunnni.smartdoorlock.R;
25 +import com.sunnni.smartdoorlock.api.Api;
25 26
26 import java.util.Objects; 27 import java.util.Objects;
27 28
...@@ -220,9 +221,18 @@ public class MainActivity extends AppCompatActivity { ...@@ -220,9 +221,18 @@ public class MainActivity extends AppCompatActivity {
220 builder.setPositiveButton("열기", new DialogInterface.OnClickListener() { 221 builder.setPositiveButton("열기", new DialogInterface.OnClickListener() {
221 @Override 222 @Override
222 public void onClick(DialogInterface dialog, int which) { 223 public void onClick(DialogInterface dialog, int which) {
223 - // 원격 해제 구현 부분 224 + Api.requestRemote(new Api.Callback() {
225 + @Override
226 + public void callbackMethod(Object obj) {
227 + if(obj == null) {
228 + Toast.makeText(getApplicationContext(),"연결 상태가 불안정합니다.",Toast.LENGTH_SHORT).show();
229 + return;
230 + } else {
224 Toast.makeText(MainActivity.this, "도어락이 열렸습니다.", Toast.LENGTH_SHORT).show(); 231 Toast.makeText(MainActivity.this, "도어락이 열렸습니다.", Toast.LENGTH_SHORT).show();
225 } 232 }
233 + }
234 + });
235 + }
226 }); 236 });
227 builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { 237 builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
228 @Override 238 @Override
......