오윤석

원격 잠금해제 기록 API 연동2

......@@ -8,6 +8,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.sunnni.smartdoorlock.data.Auth;
import com.sunnni.smartdoorlock.data.RemoteRecord;
import com.sunnni.smartdoorlock.data.Setting;
import java.io.BufferedReader;
......@@ -16,6 +17,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
......@@ -174,4 +176,29 @@ public class Api {
}
});
}
static public void getRemotes(final Callback callback) {
callApi("GET", "/api/remote", null, new Callback() {
@Override
public void callbackMethod(Object obj) {
ApiResult apiResult = (ApiResult) obj;
if(apiResult.isSuccess()) {
JsonObject resp = (JsonObject) apiResult.getData();
if(resp.has("remoteHistoryList")) {
ArrayList<RemoteRecord> remoteRecords = new ArrayList<RemoteRecord>();
Iterator it = resp.getAsJsonArray("remoteHistoryList").iterator();
while(it.hasNext()) {
JsonObject jsonObject = (JsonObject) it.next();
remoteRecords.add(new RemoteRecord(jsonObject.get("device_name").getAsString(), jsonObject.get("created").getAsString()));
}
callback.callbackMethod(remoteRecords);
} else {
callback.callbackMethod(null);
}
} else {
callback.callbackMethod(null);
}
}
});
}
}
......
......@@ -37,7 +37,7 @@ public class RemoteControlRecordActivity extends AppCompatActivity {
setToolbar(mToolbar);
setRecyclerView();
Api.getRemote(new Api.Callback() {
Api.getRemotes(new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
if(obj == null) {
......