sunnnl

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

......@@ -53,7 +53,7 @@ public class Api {
conn.setRequestMethod(method);
if (accessToken != null) {
conn.setRequestProperty("access_token", accessToken);
conn.setRequestProperty("Authorization", "Token " + accessToken);
}
if ("POST".equals(method) || "PUT".equals(method)) {
......@@ -254,6 +254,7 @@ public class Api {
ApiResult apiResult = (ApiResult) obj;
if (apiResult.isSuccess()) {
callback.callbackMethod(new Boolean(true));
Log.d("삭제 테스트", apiResult.toString());
} else {
callback.callbackMethod(null);
}
......@@ -293,6 +294,7 @@ public class Api {
ApiResult apiResult = (ApiResult) obj;
if (apiResult.isSuccess()) {
callback.callbackMethod(new Boolean(true));
Log.d("삭제 테스트", apiResult.toString());
} else {
callback.callbackMethod(null);
}
......@@ -301,7 +303,7 @@ public class Api {
}
static public void requestAddDevice(final Callback callback) {
callApi("POST", "/api/device/request", null, new Callback() {
callApi("PUT", "/api/device/request", null, new Callback() {
@Override
public void callbackMethod(Object obj) {
ApiResult apiResult = (ApiResult) obj;
......
......@@ -12,7 +12,7 @@ public class Device {
}
public String getCreated() {
return created;
return created.substring(0,10) + " " + created.substring(11, 19);
}
public int getDeviceId() {
......
......@@ -4,7 +4,7 @@ public class RemoteRecord {
private String deviceName;
private String created;
public RemoteRecord(String deviceName, String created){
public RemoteRecord(String deviceName, String created) {
this.deviceName = deviceName;
this.created = created;
}
......@@ -14,6 +14,6 @@ public class RemoteRecord {
}
public String getCreated() {
return created;
return created.substring(0, 10) + " " + created.substring(11, 19);
}
}
......
......@@ -19,7 +19,7 @@ public class Video {
}
public String getCreated() {
return created;
return created.substring(0,10) + " " + created.substring(11, 19);
}
public String getS3link() {
......
......@@ -135,6 +135,7 @@ public class DeviceManagerActivity extends AppCompatActivity implements OnItemCl
@Override
public void onItemClick() {
getDevice();
Toast.makeText(this, "호출 테스트", Toast.LENGTH_LONG).show();
mAdapter.notifyDataSetChanged();
Toast.makeText(this, "기기가 삭제되었습니다.", Toast.LENGTH_LONG).show();
}
}
......
......@@ -93,12 +93,38 @@ public class DeviceRecyclerViewAdapter extends RecyclerView.Adapter<DeviceRecycl
}
@Override
public void onBindViewHolder(@NonNull DeviceViewHolder holder, int position) {
public void onBindViewHolder(@NonNull final DeviceViewHolder holder, final int position) {
holder.bind(mList.get(position));
holder.mTrashcan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallback.onItemClick();
AlertDialog.Builder builder = new AlertDialog.Builder(holder.mTrashcan.getContext(), R.style.AlertDialogTheme);
builder.setTitle("확인")
.setMessage(R.string.alert_message_delete);
builder.setPositiveButton("삭제", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Api.removeDevice(mList.get(position), new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
if(obj == null) {
Toast.makeText(holder.mTrashcan.getContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show();
return;
} else {
mCallback.onItemClick();
}
}
});
}
});
builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
}
......
......@@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.sunnni.smartdoorlock.R;
import com.sunnni.smartdoorlock.api.OnItemClick;
import com.sunnni.smartdoorlock.data.Device;
import com.sunnni.smartdoorlock.data.RemoteRecord;
......
......@@ -46,7 +46,7 @@ public class SettingActivity extends AppCompatActivity {
swcRecording.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Api.setSetting(new Setting(true), new Api.Callback() {
Api.setSetting(new Setting(b), new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
if (obj == null) {
......
......@@ -147,6 +147,7 @@ public class VideoCheckActivity extends AppCompatActivity implements OnItemClick
public void onItemClick() {
// 삭제했을 때 여기서 다시 비디오 리스트 불러오기
getVideos();
Toast.makeText(this, "호출 테스트", Toast.LENGTH_LONG).show();
mAdapter.notifyDataSetChanged();
Toast.makeText(this, "비디오가 삭제되었습니다.", Toast.LENGTH_LONG).show();
}
}
......
......@@ -24,11 +24,11 @@ public class VideoPlayerActivity extends AppCompatActivity {
mVideoView = findViewById(R.id.vv);
if (getIntent().getStringExtra("video_url").isEmpty()){
if (getIntent().getStringExtra("video_url").isEmpty()) {
Toast.makeText(this, "링크 null", Toast.LENGTH_SHORT).show();
} else{
} else {
String url = getIntent().getStringExtra("video_url");
videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + url);
videoUri = Uri.parse(url);
playVideo();
}
}
......@@ -36,16 +36,16 @@ public class VideoPlayerActivity extends AppCompatActivity {
@Override
protected void onPause() {
super.onPause();
if(mVideoView!=null && mVideoView.isPlaying()) mVideoView.pause();
if (mVideoView != null && mVideoView.isPlaying()) mVideoView.pause();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(mVideoView!=null) mVideoView.stopPlayback();
if (mVideoView != null) mVideoView.stopPlayback();
}
private void playVideo(){
private void playVideo() {
mVideoView.setMediaController(new MediaController(this));
mVideoView.setVideoURI(videoUri);
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
......
......@@ -50,41 +50,6 @@ public class VideoRvAdapter extends RecyclerView.Adapter<VideoRvAdapter.VideoVie
.load(video.getThumb())
.into(mImgThumbnail);
mImgDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(itemView.getContext(), R.style.AlertDialogTheme);
builder.setTitle("확인")
.setMessage(R.string.alert_message_delete);
builder.setPositiveButton("삭제", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Api.removeVideo(video, new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
if(obj==null){
Toast.makeText(itemView.getContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show();
// itemView.getContext().startActivity(new Intent(itemView.getContext(), MainActivity.class));
return;
} else {
// Toast.makeText(itemView.getContext(), "삭제되었습니다.", Toast.LENGTH_LONG).show();
}
}
});
}
});
builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
mCtnItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -125,12 +90,39 @@ public class VideoRvAdapter extends RecyclerView.Adapter<VideoRvAdapter.VideoVie
}
@Override
public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) {
public void onBindViewHolder(@NonNull final VideoViewHolder holder, final int position) {
holder.bind(videoList.get(position));
holder.mImgDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallback.onItemClick();
AlertDialog.Builder builder = new AlertDialog.Builder(holder.mImgDelete.getContext(), R.style.AlertDialogTheme);
builder.setTitle("확인")
.setMessage(R.string.alert_message_delete);
builder.setPositiveButton("삭제", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Api.removeVideo(videoList.get(position), new Api.Callback() {
@Override
public void callbackMethod(Object obj) {
if(obj==null){
Toast.makeText(holder.mImgDelete.getContext(), "연결 상태가 불안정합니다.", Toast.LENGTH_SHORT).show();
return;
} else {
mCallback.onItemClick();
}
}
});
}
});
builder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
}
......