Update del API for list

pull/653/merge
Varun Patil 2023-05-10 13:20:31 -07:00
parent 22ed3b3cb0
commit 414f6cf5ed
2 changed files with 24 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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,10 +308,10 @@ public class TimelineQuery {
throw new Exception("Delete canceled or failed");
}
} else {
// Delete with media store
Uri uri = ContentUris.withAppendedId(collection, id);
for (Uri uri : uris) {
mCtx.getContentResolver().delete(uri, null, null);
}
}
return new JSONObject().put("message", "ok");
} finally {