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