Update del API for list
parent
22ed3b3cb0
commit
414f6cf5ed
|
@ -19,6 +19,8 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.collection.ArrayMap;
|
import androidx.collection.ArrayMap;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import gallery.memories.service.ImageService;
|
import gallery.memories.service.ImageService;
|
||||||
|
@ -114,8 +116,8 @@ public class NativeX {
|
||||||
return makeResponse(mImageService.getFull(Long.parseLong(parts[3])), "image/jpeg");
|
return makeResponse(mImageService.getFull(Long.parseLong(parts[3])), "image/jpeg");
|
||||||
} else if (path.matches("^/api/image/info/\\d+$")) {
|
} else if (path.matches("^/api/image/info/\\d+$")) {
|
||||||
return makeResponse(mQuery.getImageInfo(Long.parseLong(parts[4])));
|
return makeResponse(mQuery.getImageInfo(Long.parseLong(parts[4])));
|
||||||
} else if (path.matches("^/api/image/delete/\\d+$")) {
|
} else if (path.matches("^/api/image/delete/\\d+(,\\d+)*$")) {
|
||||||
return makeResponse(mQuery.delete(Long.parseLong(parts[4])));
|
return makeResponse(mQuery.delete(parseIds(parts[4])));
|
||||||
} else if (path.matches("^/api/days$")) {
|
} else if (path.matches("^/api/days$")) {
|
||||||
return makeResponse(mQuery.getDays());
|
return makeResponse(mQuery.getDays());
|
||||||
} else if (path.matches("/api/days/\\d+$")) {
|
} else if (path.matches("/api/days/\\d+$")) {
|
||||||
|
@ -142,4 +144,12 @@ public class NativeX {
|
||||||
response.setStatusCodeAndReasonPhrase(500, "Internal Server Error");
|
response.setStatusCodeAndReasonPhrase(500, "Internal Server Error");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static List<Long> parseIds(String ids) {
|
||||||
|
List<Long> result = new ArrayList<>();
|
||||||
|
for (String id : ids.split(",")) {
|
||||||
|
result.add(Long.parseLong(id));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ import org.json.JSONObject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ public class TimelineQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject delete(long id) throws Exception {
|
public JSONObject delete(List<Long> ids) throws Exception {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (deleting) {
|
if (deleting) {
|
||||||
throw new Exception("Already deleting another set of images");
|
throw new Exception("Already deleting another set of images");
|
||||||
|
@ -286,12 +286,16 @@ public class TimelineQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// List of URIs
|
||||||
|
List<Uri> uris = new ArrayList<>();
|
||||||
|
for (long id : ids) {
|
||||||
|
uris.add(ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id));
|
||||||
|
}
|
||||||
|
|
||||||
// Delete file with media store
|
// Delete file with media store
|
||||||
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
// Delete with media store
|
PendingIntent intent = MediaStore.createTrashRequest(mCtx.getContentResolver(), uris, true);
|
||||||
Uri uri = ContentUris.withAppendedId(collection, id);
|
|
||||||
PendingIntent intent = MediaStore.createTrashRequest(mCtx.getContentResolver(), Collections.singletonList(uri), true);
|
|
||||||
deleteIntentLauncher.launch(new IntentSenderRequest.Builder(intent.getIntentSender()).build());
|
deleteIntentLauncher.launch(new IntentSenderRequest.Builder(intent.getIntentSender()).build());
|
||||||
|
|
||||||
// Wait for response
|
// Wait for response
|
||||||
|
@ -304,10 +308,10 @@ public class TimelineQuery {
|
||||||
throw new Exception("Delete canceled or failed");
|
throw new Exception("Delete canceled or failed");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Delete with media store
|
for (Uri uri : uris) {
|
||||||
Uri uri = ContentUris.withAppendedId(collection, id);
|
|
||||||
mCtx.getContentResolver().delete(uri, null, null);
|
mCtx.getContentResolver().delete(uri, null, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new JSONObject().put("message", "ok");
|
return new JSONObject().put("message", "ok");
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue