Showing
4 changed files
with
202 additions
and
3 deletions
... | @@ -10,6 +10,7 @@ import com.google.gson.JsonParser; | ... | @@ -10,6 +10,7 @@ import com.google.gson.JsonParser; |
10 | import com.sunnni.smartdoorlock.data.Auth; | 10 | import com.sunnni.smartdoorlock.data.Auth; |
11 | import com.sunnni.smartdoorlock.data.RemoteRecord; | 11 | import com.sunnni.smartdoorlock.data.RemoteRecord; |
12 | import com.sunnni.smartdoorlock.data.Setting; | 12 | import com.sunnni.smartdoorlock.data.Setting; |
13 | +import com.sunnni.smartdoorlock.data.Video; | ||
13 | 14 | ||
14 | import java.io.BufferedReader; | 15 | import java.io.BufferedReader; |
15 | import java.io.InputStream; | 16 | import java.io.InputStream; |
... | @@ -55,14 +56,13 @@ public class Api { | ... | @@ -55,14 +56,13 @@ public class Api { |
55 | } | 56 | } |
56 | 57 | ||
57 | if("POST".equals(method) || "PUT".equals(method)) { | 58 | if("POST".equals(method) || "PUT".equals(method)) { |
58 | - if(params == null) { | 59 | + if(params != null) { |
59 | - throw new Exception("params is null"); | ||
60 | - } | ||
61 | OutputStream os = conn.getOutputStream(); | 60 | OutputStream os = conn.getOutputStream(); |
62 | os.write(params.toString().getBytes()); | 61 | os.write(params.toString().getBytes()); |
63 | os.flush(); | 62 | os.flush(); |
64 | os.close(); | 63 | os.close(); |
65 | } | 64 | } |
65 | + } | ||
66 | 66 | ||
67 | int status = conn.getResponseCode(); | 67 | int status = conn.getResponseCode(); |
68 | Log.d("status", String.valueOf(status)); | 68 | Log.d("status", String.valueOf(status)); |
... | @@ -201,4 +201,63 @@ public class Api { | ... | @@ -201,4 +201,63 @@ public class Api { |
201 | } | 201 | } |
202 | }); | 202 | }); |
203 | } | 203 | } |
204 | + | ||
205 | + static public void getVideos(final Callback callback) { | ||
206 | + callApi("GET", "/api/video", null, new Callback() { | ||
207 | + @Override | ||
208 | + public void callbackMethod(Object obj) { | ||
209 | + ApiResult apiResult = (ApiResult) obj; | ||
210 | + if(apiResult.isSuccess()) { | ||
211 | + JsonObject resp = (JsonObject) apiResult.getData(); | ||
212 | + if(resp.has("videoList")) { | ||
213 | + ArrayList<Video> videos = new ArrayList<Video>(); | ||
214 | + Iterator it = resp.getAsJsonArray("videoList").iterator(); | ||
215 | + while(it.hasNext()) { | ||
216 | + JsonObject jsonObject = (JsonObject) it.next(); | ||
217 | + videos.add(new Video(jsonObject.get("vid_name").getAsString(), jsonObject.get("thumb").getAsString(), jsonObject.get("created").getAsString())); | ||
218 | + } | ||
219 | + callback.callbackMethod(videos); | ||
220 | + } else { | ||
221 | + callback.callbackMethod(null); | ||
222 | + } | ||
223 | + } else { | ||
224 | + callback.callbackMethod(null); | ||
225 | + } | ||
226 | + } | ||
227 | + }); | ||
228 | + } | ||
229 | + | ||
230 | + static public void getVideo(Video video, final Callback callback) { | ||
231 | + callApi("GET", "/api/video/" + video.getVidName(), null, new Callback() { | ||
232 | + @Override | ||
233 | + public void callbackMethod(Object obj) { | ||
234 | + ApiResult apiResult = (ApiResult) obj; | ||
235 | + if(apiResult.isSuccess()) { | ||
236 | + JsonObject resp = (JsonObject) apiResult.getData(); | ||
237 | + if(resp.has("s3link")) { | ||
238 | + callback.callbackMethod(resp.get("s3link").getAsString()); | ||
239 | + } else { | ||
240 | + callback.callbackMethod(null); | ||
241 | + } | ||
242 | + } else { | ||
243 | + callback.callbackMethod(null); | ||
244 | + } | ||
245 | + } | ||
246 | + }); | ||
247 | + } | ||
248 | + | ||
249 | + static public void removeVideo(Video video, final Callback callback) { | ||
250 | + callApi("DELETE", "/api/video/" + video.getVidName(), null, new Callback() { | ||
251 | + @Override | ||
252 | + public void callbackMethod(Object obj) { | ||
253 | + ApiResult apiResult = (ApiResult) obj; | ||
254 | + if(apiResult.isSuccess()) { | ||
255 | + callback.callbackMethod(new Boolean(true)); | ||
256 | + } else { | ||
257 | + callback.callbackMethod(null); | ||
258 | + } | ||
259 | + } | ||
260 | + }); | ||
261 | + } | ||
262 | + | ||
204 | } | 263 | } | ... | ... |
1 | +package com.sunnni.smartdoorlock.data; | ||
2 | + | ||
3 | +public class Video { | ||
4 | + private String vidName; | ||
5 | + private String thumb; | ||
6 | + private String created; | ||
7 | + private String s3link; | ||
8 | + | ||
9 | + public Video(String vidName, String thumb, String created) { | ||
10 | + this.vidName = vidName; | ||
11 | + this.thumb = thumb; | ||
12 | + this.created = created; | ||
13 | + } | ||
14 | + | ||
15 | + public void setS3link(String s3link) { | ||
16 | + this.s3link = s3link; | ||
17 | + } | ||
18 | + | ||
19 | + public String getCreated() { | ||
20 | + return created; | ||
21 | + } | ||
22 | + | ||
23 | + public String getS3link() { | ||
24 | + return s3link; | ||
25 | + } | ||
26 | + | ||
27 | + public String getThumb() { | ||
28 | + return thumb; | ||
29 | + } | ||
30 | + | ||
31 | + public String getVidName() { | ||
32 | + return vidName; | ||
33 | + } | ||
34 | +} |
... | @@ -3,15 +3,26 @@ package com.sunnni.smartdoorlock.ui; | ... | @@ -3,15 +3,26 @@ package com.sunnni.smartdoorlock.ui; |
3 | import androidx.appcompat.app.AppCompatActivity; | 3 | import androidx.appcompat.app.AppCompatActivity; |
4 | import androidx.appcompat.widget.Toolbar; | 4 | import androidx.appcompat.widget.Toolbar; |
5 | 5 | ||
6 | +import android.content.Intent; | ||
6 | import android.os.Bundle; | 7 | import android.os.Bundle; |
7 | import android.view.View; | 8 | import android.view.View; |
9 | +import android.widget.Button; | ||
10 | +import android.widget.Toast; | ||
8 | 11 | ||
9 | import com.sunnni.smartdoorlock.R; | 12 | import com.sunnni.smartdoorlock.R; |
13 | +import com.sunnni.smartdoorlock.api.Api; | ||
14 | +import com.sunnni.smartdoorlock.data.RemoteRecord; | ||
15 | +import com.sunnni.smartdoorlock.data.Video; | ||
10 | 16 | ||
17 | +import java.util.ArrayList; | ||
11 | import java.util.Objects; | 18 | import java.util.Objects; |
12 | 19 | ||
13 | public class VideoCheckActivity extends AppCompatActivity { | 20 | public class VideoCheckActivity extends AppCompatActivity { |
14 | 21 | ||
22 | + ArrayList<Video> mVideoList = new ArrayList<Video>(); | ||
23 | + Button mBtnRemoveVideo; | ||
24 | + Button mBtnViewVideo; | ||
25 | + | ||
15 | @Override | 26 | @Override |
16 | protected void onCreate(Bundle savedInstanceState) { | 27 | protected void onCreate(Bundle savedInstanceState) { |
17 | super.onCreate(savedInstanceState); | 28 | super.onCreate(savedInstanceState); |
... | @@ -19,6 +30,61 @@ public class VideoCheckActivity extends AppCompatActivity { | ... | @@ -19,6 +30,61 @@ public class VideoCheckActivity extends AppCompatActivity { |
19 | 30 | ||
20 | Toolbar mToolbar = findViewById(R.id.toolbar_video_check); | 31 | Toolbar mToolbar = findViewById(R.id.toolbar_video_check); |
21 | setToolbar(mToolbar); | 32 | setToolbar(mToolbar); |
33 | + | ||
34 | + mBtnRemoveVideo = (Button) findViewById(R.id.btn_remove_video); | ||
35 | + mBtnViewVideo = (Button) findViewById(R.id.btn_view_video); | ||
36 | + | ||
37 | + getVideos(); | ||
38 | + | ||
39 | + mBtnRemoveVideo.setOnClickListener(new View.OnClickListener() { | ||
40 | + @Override | ||
41 | + public void onClick(View view) { | ||
42 | + // TODO : 삭제 버튼이 클릭되었을 때 | ||
43 | + // 원래는 각 비디오에 대해서 동작해야 함. 코드 의미 전달을 위해 video[0]에 대해 삭제하는 코드만 구현 | ||
44 | + Api.removeVideo(mVideoList.get(0), new Api.Callback() { | ||
45 | + @Override | ||
46 | + public void callbackMethod(Object obj) { | ||
47 | + if(obj == null) { | ||
48 | + Toast.makeText(getApplicationContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show(); | ||
49 | + startActivity(new Intent(VideoCheckActivity.this, MainActivity.class)); | ||
50 | + return; | ||
51 | + } else { | ||
52 | + // 삭제가 완료되었으므로 비디오 리스트 다시 조회 | ||
53 | + // (또는 해당 비디오만 삭제하고 notifyDataSetChanged) | ||
54 | + getVideos(); | ||
55 | + } | ||
56 | + } | ||
57 | + }); | ||
58 | + } | ||
59 | + }); | ||
60 | + | ||
61 | + mBtnViewVideo.setOnClickListener(new View.OnClickListener() { | ||
62 | + @Override | ||
63 | + public void onClick(View view) { | ||
64 | + // TODO : 비디오가 클릭되었을 때 (비디오 재생) | ||
65 | + // 원래는 각 비디오에 대해서 동작해야 함. 코드 의미 전달을 위해 video[0]에 대해 재생하는 코드만 구현 | ||
66 | + final Video video = mVideoList.get(0); | ||
67 | + // s3 링크를 받아오지 못한 경우에만 조회. 이미 받아온 경우 바로 해당 링크로 재생 | ||
68 | + if(video.getS3link() == null) { | ||
69 | + Api.getVideo(mVideoList.get(0), new Api.Callback() { | ||
70 | + @Override | ||
71 | + public void callbackMethod(Object obj) { | ||
72 | + if (obj == null) { | ||
73 | + Toast.makeText(getApplicationContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show(); | ||
74 | + startActivity(new Intent(VideoCheckActivity.this, MainActivity.class)); | ||
75 | + return; | ||
76 | + } else { | ||
77 | + String s3link = (String) obj; | ||
78 | + video.setS3link(s3link); | ||
79 | + // TODO : 비디오 재생 코드 구현 (video.setS3link를 통해) | ||
80 | + } | ||
81 | + } | ||
82 | + }); | ||
83 | + } else { | ||
84 | + // TODO : 비디오 재생 코드 구현 (video.setS3link를 통해) | ||
85 | + } | ||
86 | + } | ||
87 | + }); | ||
22 | } | 88 | } |
23 | 89 | ||
24 | private void setToolbar(Toolbar toolbar){ | 90 | private void setToolbar(Toolbar toolbar){ |
... | @@ -35,4 +101,22 @@ public class VideoCheckActivity extends AppCompatActivity { | ... | @@ -35,4 +101,22 @@ public class VideoCheckActivity extends AppCompatActivity { |
35 | } | 101 | } |
36 | }); | 102 | }); |
37 | } | 103 | } |
104 | + | ||
105 | + private void getVideos() { | ||
106 | + Api.getVideos(new Api.Callback() { | ||
107 | + @Override | ||
108 | + public void callbackMethod(Object obj) { | ||
109 | + // TODO : 비디오 리스트가 로드되었을 때 | ||
110 | + if(obj == null) { | ||
111 | + Toast.makeText(getApplicationContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show(); | ||
112 | + startActivity(new Intent(VideoCheckActivity.this, MainActivity.class)); | ||
113 | + return; | ||
114 | + } else { | ||
115 | + mVideoList.clear(); | ||
116 | + mVideoList.addAll(0, (ArrayList<Video>) obj); | ||
117 | + //mAdapter.notifyDataSetChanged(); | ||
118 | + } | ||
119 | + } | ||
120 | + }); | ||
121 | + } | ||
38 | } | 122 | } | ... | ... |
... | @@ -26,4 +26,26 @@ | ... | @@ -26,4 +26,26 @@ |
26 | 26 | ||
27 | </androidx.appcompat.widget.Toolbar> | 27 | </androidx.appcompat.widget.Toolbar> |
28 | 28 | ||
29 | + <Button | ||
30 | + android:id="@+id/btn_remove_video" | ||
31 | + android:layout_width="wrap_content" | ||
32 | + android:layout_height="wrap_content" | ||
33 | + android:layout_marginBottom="563dp" | ||
34 | + android:layout_marginStart="100dp" | ||
35 | + android:text="btn_remove_video" | ||
36 | + app:layout_constraintBottom_toBottomOf="parent" | ||
37 | + app:layout_constraintStart_toStartOf="parent" | ||
38 | + app:layout_constraintTop_toBottomOf="@+id/toolbar_video_check" /> | ||
39 | + | ||
40 | + <Button | ||
41 | + android:id="@+id/btn_view_video" | ||
42 | + android:layout_width="wrap_content" | ||
43 | + android:layout_height="wrap_content" | ||
44 | + android:layout_marginBottom="504dp" | ||
45 | + android:layout_marginStart="6dp" | ||
46 | + android:text="btn_view_video" | ||
47 | + app:layout_constraintBottom_toBottomOf="parent" | ||
48 | + app:layout_constraintStart_toStartOf="@+id/btn_remove_video" | ||
49 | + app:layout_constraintTop_toBottomOf="@+id/toolbar_video_check" /> | ||
50 | + | ||
29 | </androidx.constraintlayout.widget.ConstraintLayout> | 51 | </androidx.constraintlayout.widget.ConstraintLayout> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment