Showing
2 changed files
with
30 additions
and
2 deletions
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,8 +221,17 @@ public class MainActivity extends AppCompatActivity { | ... | @@ -220,8 +221,17 @@ 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() { |
224 | - Toast.makeText(MainActivity.this, "도어락이 열렸습니다.", Toast.LENGTH_SHORT).show(); | 225 | + @Override |
226 | + public void callbackMethod(Object obj) { | ||
227 | + if(obj == null) { | ||
228 | + Toast.makeText(getApplicationContext(),"연결 상태가 불안정합니다.",Toast.LENGTH_SHORT).show(); | ||
229 | + return; | ||
230 | + } else { | ||
231 | + Toast.makeText(MainActivity.this, "도어락이 열렸습니다.", Toast.LENGTH_SHORT).show(); | ||
232 | + } | ||
233 | + } | ||
234 | + }); | ||
225 | } | 235 | } |
226 | }); | 236 | }); |
227 | builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { | 237 | builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { | ... | ... |
-
Please register or login to post a comment