sunnnl

기기, 비디오 삭제 오류 수정

...@@ -53,7 +53,7 @@ public class Api { ...@@ -53,7 +53,7 @@ public class Api {
53 conn.setRequestMethod(method); 53 conn.setRequestMethod(method);
54 54
55 if (accessToken != null) { 55 if (accessToken != null) {
56 - conn.setRequestProperty("access_token", accessToken); 56 + conn.setRequestProperty("Authorization", "Token " + accessToken);
57 } 57 }
58 58
59 if ("POST".equals(method) || "PUT".equals(method)) { 59 if ("POST".equals(method) || "PUT".equals(method)) {
...@@ -254,6 +254,7 @@ public class Api { ...@@ -254,6 +254,7 @@ public class Api {
254 ApiResult apiResult = (ApiResult) obj; 254 ApiResult apiResult = (ApiResult) obj;
255 if (apiResult.isSuccess()) { 255 if (apiResult.isSuccess()) {
256 callback.callbackMethod(new Boolean(true)); 256 callback.callbackMethod(new Boolean(true));
257 + Log.d("삭제 테스트", apiResult.toString());
257 } else { 258 } else {
258 callback.callbackMethod(null); 259 callback.callbackMethod(null);
259 } 260 }
...@@ -293,6 +294,7 @@ public class Api { ...@@ -293,6 +294,7 @@ public class Api {
293 ApiResult apiResult = (ApiResult) obj; 294 ApiResult apiResult = (ApiResult) obj;
294 if (apiResult.isSuccess()) { 295 if (apiResult.isSuccess()) {
295 callback.callbackMethod(new Boolean(true)); 296 callback.callbackMethod(new Boolean(true));
297 + Log.d("삭제 테스트", apiResult.toString());
296 } else { 298 } else {
297 callback.callbackMethod(null); 299 callback.callbackMethod(null);
298 } 300 }
...@@ -301,7 +303,7 @@ public class Api { ...@@ -301,7 +303,7 @@ public class Api {
301 } 303 }
302 304
303 static public void requestAddDevice(final Callback callback) { 305 static public void requestAddDevice(final Callback callback) {
304 - callApi("POST", "/api/device/request", null, new Callback() { 306 + callApi("PUT", "/api/device/request", null, new Callback() {
305 @Override 307 @Override
306 public void callbackMethod(Object obj) { 308 public void callbackMethod(Object obj) {
307 ApiResult apiResult = (ApiResult) obj; 309 ApiResult apiResult = (ApiResult) obj;
......
...@@ -12,7 +12,7 @@ public class Device { ...@@ -12,7 +12,7 @@ public class Device {
12 } 12 }
13 13
14 public String getCreated() { 14 public String getCreated() {
15 - return created; 15 + return created.substring(0,10) + " " + created.substring(11, 19);
16 } 16 }
17 17
18 public int getDeviceId() { 18 public int getDeviceId() {
......
...@@ -4,7 +4,7 @@ public class RemoteRecord { ...@@ -4,7 +4,7 @@ public class RemoteRecord {
4 private String deviceName; 4 private String deviceName;
5 private String created; 5 private String created;
6 6
7 - public RemoteRecord(String deviceName, String created){ 7 + public RemoteRecord(String deviceName, String created) {
8 this.deviceName = deviceName; 8 this.deviceName = deviceName;
9 this.created = created; 9 this.created = created;
10 } 10 }
...@@ -14,6 +14,6 @@ public class RemoteRecord { ...@@ -14,6 +14,6 @@ public class RemoteRecord {
14 } 14 }
15 15
16 public String getCreated() { 16 public String getCreated() {
17 - return created; 17 + return created.substring(0, 10) + " " + created.substring(11, 19);
18 } 18 }
19 } 19 }
......
...@@ -19,7 +19,7 @@ public class Video { ...@@ -19,7 +19,7 @@ public class Video {
19 } 19 }
20 20
21 public String getCreated() { 21 public String getCreated() {
22 - return created; 22 + return created.substring(0,10) + " " + created.substring(11, 19);
23 } 23 }
24 24
25 public String getS3link() { 25 public String getS3link() {
......
...@@ -135,6 +135,7 @@ public class DeviceManagerActivity extends AppCompatActivity implements OnItemCl ...@@ -135,6 +135,7 @@ public class DeviceManagerActivity extends AppCompatActivity implements OnItemCl
135 @Override 135 @Override
136 public void onItemClick() { 136 public void onItemClick() {
137 getDevice(); 137 getDevice();
138 - Toast.makeText(this, "호출 테스트", Toast.LENGTH_LONG).show(); 138 + mAdapter.notifyDataSetChanged();
139 + Toast.makeText(this, "기기가 삭제되었습니다.", Toast.LENGTH_LONG).show();
139 } 140 }
140 } 141 }
......
...@@ -93,12 +93,38 @@ public class DeviceRecyclerViewAdapter extends RecyclerView.Adapter<DeviceRecycl ...@@ -93,12 +93,38 @@ public class DeviceRecyclerViewAdapter extends RecyclerView.Adapter<DeviceRecycl
93 } 93 }
94 94
95 @Override 95 @Override
96 - public void onBindViewHolder(@NonNull DeviceViewHolder holder, int position) { 96 + public void onBindViewHolder(@NonNull final DeviceViewHolder holder, final int position) {
97 holder.bind(mList.get(position)); 97 holder.bind(mList.get(position));
98 holder.mTrashcan.setOnClickListener(new View.OnClickListener() { 98 holder.mTrashcan.setOnClickListener(new View.OnClickListener() {
99 @Override 99 @Override
100 public void onClick(View v) { 100 public void onClick(View v) {
101 - mCallback.onItemClick(); 101 + AlertDialog.Builder builder = new AlertDialog.Builder(holder.mTrashcan.getContext(), R.style.AlertDialogTheme);
102 + builder.setTitle("확인")
103 + .setMessage(R.string.alert_message_delete);
104 + builder.setPositiveButton("삭제", new DialogInterface.OnClickListener() {
105 + @Override
106 + public void onClick(DialogInterface dialog, int which) {
107 + Api.removeDevice(mList.get(position), new Api.Callback() {
108 + @Override
109 + public void callbackMethod(Object obj) {
110 + if(obj == null) {
111 + Toast.makeText(holder.mTrashcan.getContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show();
112 + return;
113 + } else {
114 + mCallback.onItemClick();
115 + }
116 + }
117 + });
118 + }
119 + });
120 + builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
121 + @Override
122 + public void onClick(DialogInterface dialog, int which) {
123 +
124 + }
125 + });
126 + AlertDialog alertDialog = builder.create();
127 + alertDialog.show();
102 } 128 }
103 }); 129 });
104 } 130 }
......
...@@ -9,6 +9,7 @@ import androidx.annotation.NonNull; ...@@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
9 import androidx.recyclerview.widget.RecyclerView; 9 import androidx.recyclerview.widget.RecyclerView;
10 10
11 import com.sunnni.smartdoorlock.R; 11 import com.sunnni.smartdoorlock.R;
12 +import com.sunnni.smartdoorlock.api.OnItemClick;
12 import com.sunnni.smartdoorlock.data.Device; 13 import com.sunnni.smartdoorlock.data.Device;
13 import com.sunnni.smartdoorlock.data.RemoteRecord; 14 import com.sunnni.smartdoorlock.data.RemoteRecord;
14 15
......
...@@ -46,7 +46,7 @@ public class SettingActivity extends AppCompatActivity { ...@@ -46,7 +46,7 @@ public class SettingActivity extends AppCompatActivity {
46 swcRecording.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 46 swcRecording.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
47 @Override 47 @Override
48 public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 48 public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
49 - Api.setSetting(new Setting(true), new Api.Callback() { 49 + Api.setSetting(new Setting(b), new Api.Callback() {
50 @Override 50 @Override
51 public void callbackMethod(Object obj) { 51 public void callbackMethod(Object obj) {
52 if (obj == null) { 52 if (obj == null) {
......
...@@ -147,6 +147,7 @@ public class VideoCheckActivity extends AppCompatActivity implements OnItemClick ...@@ -147,6 +147,7 @@ public class VideoCheckActivity extends AppCompatActivity implements OnItemClick
147 public void onItemClick() { 147 public void onItemClick() {
148 // 삭제했을 때 여기서 다시 비디오 리스트 불러오기 148 // 삭제했을 때 여기서 다시 비디오 리스트 불러오기
149 getVideos(); 149 getVideos();
150 - Toast.makeText(this, "호출 테스트", Toast.LENGTH_LONG).show(); 150 + mAdapter.notifyDataSetChanged();
151 + Toast.makeText(this, "비디오가 삭제되었습니다.", Toast.LENGTH_LONG).show();
151 } 152 }
152 } 153 }
......
...@@ -24,11 +24,11 @@ public class VideoPlayerActivity extends AppCompatActivity { ...@@ -24,11 +24,11 @@ public class VideoPlayerActivity extends AppCompatActivity {
24 24
25 mVideoView = findViewById(R.id.vv); 25 mVideoView = findViewById(R.id.vv);
26 26
27 - if (getIntent().getStringExtra("video_url").isEmpty()){ 27 + if (getIntent().getStringExtra("video_url").isEmpty()) {
28 Toast.makeText(this, "링크 null", Toast.LENGTH_SHORT).show(); 28 Toast.makeText(this, "링크 null", Toast.LENGTH_SHORT).show();
29 - } else{ 29 + } else {
30 String url = getIntent().getStringExtra("video_url"); 30 String url = getIntent().getStringExtra("video_url");
31 - videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + url); 31 + videoUri = Uri.parse(url);
32 playVideo(); 32 playVideo();
33 } 33 }
34 } 34 }
...@@ -36,16 +36,16 @@ public class VideoPlayerActivity extends AppCompatActivity { ...@@ -36,16 +36,16 @@ public class VideoPlayerActivity extends AppCompatActivity {
36 @Override 36 @Override
37 protected void onPause() { 37 protected void onPause() {
38 super.onPause(); 38 super.onPause();
39 - if(mVideoView!=null && mVideoView.isPlaying()) mVideoView.pause(); 39 + if (mVideoView != null && mVideoView.isPlaying()) mVideoView.pause();
40 } 40 }
41 41
42 @Override 42 @Override
43 protected void onDestroy() { 43 protected void onDestroy() {
44 super.onDestroy(); 44 super.onDestroy();
45 - if(mVideoView!=null) mVideoView.stopPlayback(); 45 + if (mVideoView != null) mVideoView.stopPlayback();
46 } 46 }
47 47
48 - private void playVideo(){ 48 + private void playVideo() {
49 mVideoView.setMediaController(new MediaController(this)); 49 mVideoView.setMediaController(new MediaController(this));
50 mVideoView.setVideoURI(videoUri); 50 mVideoView.setVideoURI(videoUri);
51 mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 51 mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
......
...@@ -50,41 +50,6 @@ public class VideoRvAdapter extends RecyclerView.Adapter<VideoRvAdapter.VideoVie ...@@ -50,41 +50,6 @@ public class VideoRvAdapter extends RecyclerView.Adapter<VideoRvAdapter.VideoVie
50 .load(video.getThumb()) 50 .load(video.getThumb())
51 .into(mImgThumbnail); 51 .into(mImgThumbnail);
52 52
53 - mImgDelete.setOnClickListener(new View.OnClickListener() {
54 - @Override
55 - public void onClick(View v) {
56 - AlertDialog.Builder builder = new AlertDialog.Builder(itemView.getContext(), R.style.AlertDialogTheme);
57 - builder.setTitle("확인")
58 - .setMessage(R.string.alert_message_delete);
59 - builder.setPositiveButton("삭제", new DialogInterface.OnClickListener() {
60 - @Override
61 - public void onClick(DialogInterface dialog, int which) {
62 - Api.removeVideo(video, new Api.Callback() {
63 - @Override
64 - public void callbackMethod(Object obj) {
65 - if(obj==null){
66 - Toast.makeText(itemView.getContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show();
67 - // itemView.getContext().startActivity(new Intent(itemView.getContext(), MainActivity.class));
68 - return;
69 -
70 - } else {
71 - // Toast.makeText(itemView.getContext(), "삭제되었습니다.", Toast.LENGTH_LONG).show();
72 - }
73 - }
74 - });
75 - }
76 - });
77 - builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
78 - @Override
79 - public void onClick(DialogInterface dialog, int which) {
80 -
81 - }
82 - });
83 - AlertDialog alertDialog = builder.create();
84 - alertDialog.show();
85 - }
86 - });
87 -
88 mCtnItem.setOnClickListener(new View.OnClickListener() { 53 mCtnItem.setOnClickListener(new View.OnClickListener() {
89 @Override 54 @Override
90 public void onClick(View v) { 55 public void onClick(View v) {
...@@ -125,12 +90,39 @@ public class VideoRvAdapter extends RecyclerView.Adapter<VideoRvAdapter.VideoVie ...@@ -125,12 +90,39 @@ public class VideoRvAdapter extends RecyclerView.Adapter<VideoRvAdapter.VideoVie
125 } 90 }
126 91
127 @Override 92 @Override
128 - public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) { 93 + public void onBindViewHolder(@NonNull final VideoViewHolder holder, final int position) {
129 holder.bind(videoList.get(position)); 94 holder.bind(videoList.get(position));
130 holder.mImgDelete.setOnClickListener(new View.OnClickListener() { 95 holder.mImgDelete.setOnClickListener(new View.OnClickListener() {
131 @Override 96 @Override
132 public void onClick(View v) { 97 public void onClick(View v) {
133 - mCallback.onItemClick(); 98 + AlertDialog.Builder builder = new AlertDialog.Builder(holder.mImgDelete.getContext(), R.style.AlertDialogTheme);
99 + builder.setTitle("확인")
100 + .setMessage(R.string.alert_message_delete);
101 + builder.setPositiveButton("삭제", new DialogInterface.OnClickListener() {
102 + @Override
103 + public void onClick(DialogInterface dialog, int which) {
104 + Api.removeVideo(videoList.get(position), new Api.Callback() {
105 + @Override
106 + public void callbackMethod(Object obj) {
107 + if(obj==null){
108 + Toast.makeText(holder.mImgDelete.getContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show();
109 + return;
110 +
111 + } else {
112 + mCallback.onItemClick();
113 + }
114 + }
115 + });
116 + }
117 + });
118 + builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
119 + @Override
120 + public void onClick(DialogInterface dialog, int which) {
121 +
122 + }
123 + });
124 + AlertDialog alertDialog = builder.create();
125 + alertDialog.show();
134 } 126 }
135 }); 127 });
136 } 128 }
......