오윤석

원격 잠금해제 연결

package com.sunnni.smartdoorlock.api;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
......@@ -156,4 +157,21 @@ public class Api {
}
});
}
static public void requestRemote(final Callback callback) {
JsonObject params = new JsonObject();
params.addProperty("device_name", Build.MODEL);
callApi("POST", "/api/remote", params, new Callback() {
@Override
public void callbackMethod(Object obj) {
ApiResult apiResult = (ApiResult) obj;
if(apiResult.isSuccess()) {
callback.callbackMethod(new Boolean(true));
} else {
callback.callbackMethod(null);
}
}
});
}
}
......
......@@ -22,6 +22,7 @@ import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
import com.sunnni.smartdoorlock.R;
import com.sunnni.smartdoorlock.api.Api;
import java.util.Objects;
......@@ -220,9 +221,18 @@ public class MainActivity extends AppCompatActivity {
builder.setPositiveButton("열기", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 원격 해제 구현 부분
Api.requestRemote(new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
if(obj == null) {
Toast.makeText(getApplicationContext(),"연결 상태가 불안정합니다.",Toast.LENGTH_SHORT).show();
return;
} else {
Toast.makeText(MainActivity.this, "도어락이 열렸습니다.", Toast.LENGTH_SHORT).show();
}
}
});
}
});
builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
......