Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to latest SDK #4657

Merged
merged 3 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ android {
javaMaxHeapSize "4g"
}

compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 29

// arguments to be passed to functional tests
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
407
409
2 changes: 1 addition & 1 deletion scripts/analysis/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 59 warnings</span>
<span class="mdl-layout-title">Lint Report: 73 warnings</span>
87 changes: 51 additions & 36 deletions src/main/java/com/owncloud/android/datamodel/MediaProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

Expand All @@ -51,11 +53,11 @@ public final class MediaProvider {
private static final Uri IMAGES_MEDIA_URI = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
private static final String[] FILE_PROJECTION = new String[]{MediaStore.MediaColumns.DATA};
private static final String IMAGES_FILE_SELECTION = MediaStore.Images.Media.BUCKET_ID + "=";
private static final String[] IMAGES_FOLDER_PROJECTION = {"Distinct " + MediaStore.Images.Media.BUCKET_ID,
private static final String[] IMAGES_FOLDER_PROJECTION = {MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
private static final String IMAGES_FOLDER_SORT_ORDER = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " ASC";

private static final String[] VIDEOS_FOLDER_PROJECTION = {"Distinct " + MediaStore.Video.Media.BUCKET_ID,
private static final String[] VIDEOS_FOLDER_PROJECTION = {MediaStore.Video.Media.BUCKET_ID,
MediaStore.Video.Media.BUCKET_DISPLAY_NAME};

private MediaProvider() {
Expand Down Expand Up @@ -86,28 +88,35 @@ public static List<MediaFolder> getImageFolders(ContentResolver contentResolver,
String dataPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder();

if (cursorFolders != null) {
String folderName;
String fileSortOrder = MediaStore.Images.Media.DATE_TAKEN + " DESC LIMIT " + itemLimit;
Cursor cursorImages;

Map<String, String> uniqueFolders = new HashMap<>();

// since sdk 29 we have to manually distinct on bucket id
while (cursorFolders.moveToNext()) {
String folderId = cursorFolders.getString(cursorFolders.getColumnIndex(MediaStore.Images.Media
.BUCKET_ID));
uniqueFolders.put(cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Images.Media.BUCKET_ID)),
cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME))
);
}
cursorFolders.close();

for (Map.Entry<String, String> folder : uniqueFolders.entrySet()) {
MediaFolder mediaFolder = new MediaFolder();
folderName = cursorFolders.getString(cursorFolders.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME));

mediaFolder.type = MediaFolderType.IMAGE;
mediaFolder.folderName = folderName;
mediaFolder.folderName = folder.getValue();
mediaFolder.filePaths = new ArrayList<>();

// query images
cursorImages = contentResolver.query(
IMAGES_MEDIA_URI,
FILE_PROJECTION,
IMAGES_FILE_SELECTION + folderId,
null,
fileSortOrder
IMAGES_MEDIA_URI,
FILE_PROJECTION,
IMAGES_FILE_SELECTION + folder.getKey(),
null,
fileSortOrder
);
Log.d(TAG, "Reading images for " + mediaFolder.folderName);

Expand All @@ -116,7 +125,7 @@ public static List<MediaFolder> getImageFolders(ContentResolver contentResolver,

while (cursorImages.moveToNext()) {
filePath = cursorImages.getString(cursorImages.getColumnIndexOrThrow(
MediaStore.MediaColumns.DATA));
MediaStore.MediaColumns.DATA));

// check if valid path and file exists
if (isValidAndExistingFilePath(filePath)) {
Expand All @@ -131,11 +140,11 @@ public static List<MediaFolder> getImageFolders(ContentResolver contentResolver,

// count images
Cursor count = contentResolver.query(
IMAGES_MEDIA_URI,
FILE_PROJECTION,
IMAGES_FILE_SELECTION + folderId,
null,
null);
IMAGES_MEDIA_URI,
FILE_PROJECTION,
IMAGES_FILE_SELECTION + folder.getKey(),
null,
null);

if (count != null) {
mediaFolder.numberOfFiles = count.getCount();
Expand All @@ -146,7 +155,6 @@ public static List<MediaFolder> getImageFolders(ContentResolver contentResolver,
}
}
}
cursorFolders.close();
}

return mediaFolders;
Expand Down Expand Up @@ -203,31 +211,38 @@ public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver,
String fileSortOrder = MediaStore.Video.Media.DATE_TAKEN + " DESC LIMIT " + itemLimit;
Cursor cursorVideos;

Map<String, String> uniqueFolders = new HashMap<>();

// since sdk 29 we have to manually distinct on bucket id
while (cursorFolders.moveToNext()) {
String folderId = cursorFolders.getString(cursorFolders.getColumnIndex(MediaStore.Video.Media
.BUCKET_ID));
uniqueFolders.put(cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Video.Media.BUCKET_ID)),
cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME))
);
}
cursorFolders.close();

for (Map.Entry<String, String> folder : uniqueFolders.entrySet()) {
MediaFolder mediaFolder = new MediaFolder();
folderName = cursorFolders.getString(cursorFolders.getColumnIndex(
MediaStore.Video.Media.BUCKET_DISPLAY_NAME));
mediaFolder.type = MediaFolderType.VIDEO;
mediaFolder.folderName = folderName;
mediaFolder.folderName = folder.getValue();
mediaFolder.filePaths = new ArrayList<>();

// query videos
cursorVideos = contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
FILE_PROJECTION,
MediaStore.Video.Media.BUCKET_ID + "=" + folderId,
null,
fileSortOrder);
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
FILE_PROJECTION,
MediaStore.Video.Media.BUCKET_ID + "=" + folder.getKey(),
null,
fileSortOrder);
Log.d(TAG, "Reading videos for " + mediaFolder.folderName);

if (cursorVideos != null) {
String filePath;
while (cursorVideos.moveToNext()) {
filePath = cursorVideos.getString(cursorVideos.getColumnIndexOrThrow(
MediaStore.MediaColumns.DATA));
MediaStore.MediaColumns.DATA));

if (filePath != null) {
mediaFolder.filePaths.add(filePath);
Expand All @@ -241,11 +256,11 @@ public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver,

// count images
Cursor count = contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
FILE_PROJECTION,
MediaStore.Video.Media.BUCKET_ID + "=" + folderId,
null,
null);
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
FILE_PROJECTION,
MediaStore.Video.Media.BUCKET_ID + "=" + folder.getKey(),
null,
null);

if (count != null) {
mediaFolder.numberOfFiles = count.getCount();
Expand Down