getAlbumsWithThumbnails returns uris not base64 data
This commit is contained in:
parent
b805ca8173
commit
b89c23defd
|
@ -26,7 +26,7 @@ import java.util.HashMap;
|
||||||
public class NativeGalleryModule extends ReactContextBaseJavaModule {
|
public class NativeGalleryModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
public static final String[] ALBUMS_PROJECTION = new String[]{
|
public static final String[] ALBUMS_PROJECTION = new String[]{
|
||||||
MediaStore.Images.Media._ID,
|
MediaStore.Images.Media.DATA,
|
||||||
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
|
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
|
||||||
};
|
};
|
||||||
public static final String[] IMAGES_PROJECTION = new String[]{
|
public static final String[] IMAGES_PROJECTION = new String[]{
|
||||||
|
@ -40,34 +40,27 @@ public class NativeGalleryModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
private class Album {
|
private class Album {
|
||||||
String name;
|
String name;
|
||||||
String imageData = null;
|
String imageUri = null;
|
||||||
int count = 1;
|
int count = 1;
|
||||||
|
|
||||||
public Album(String name) {
|
public Album(String name, String uri) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.imageUri = uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AlbumList {
|
private class AlbumList {
|
||||||
HashMap<String, Album> albums = new HashMap<>();
|
HashMap<String, Album> albums = new HashMap<>();
|
||||||
|
|
||||||
public void addAlbum(String name) {
|
public void addAlbum(String name, String uri) {
|
||||||
if (!albums.containsKey(name)) {
|
if (!albums.containsKey(name)) {
|
||||||
albums.put(name, new Album(name));
|
albums.put(name, new Album(name, uri));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
albums.get(name).count++;
|
albums.get(name).count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThumbnail(String name, Bitmap thumbnail) {
|
|
||||||
albums.get(name).imageData = Utils.getBase64FromBitmap(thumbnail);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasThumbnail(String name) {
|
|
||||||
return albums.get(name).imageData != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Album> getAlbums() {
|
public Collection<Album> getAlbums() {
|
||||||
return albums.values();
|
return albums.values();
|
||||||
}
|
}
|
||||||
|
@ -87,7 +80,7 @@ public class NativeGalleryModule extends ReactContextBaseJavaModule {
|
||||||
WritableMap map = Arguments.createMap();
|
WritableMap map = Arguments.createMap();
|
||||||
map.putInt("imagesCount", album.count);
|
map.putInt("imagesCount", album.count);
|
||||||
map.putString("albumName", album.name);
|
map.putString("albumName", album.name);
|
||||||
map.putString("image", album.imageData);
|
map.putString("thumbUri", album.imageUri);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,17 +90,12 @@ public class NativeGalleryModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
if (imagesCursor.moveToFirst()) {
|
if (imagesCursor.moveToFirst()) {
|
||||||
int bucketColumn = imagesCursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
|
int bucketColumn = imagesCursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
|
||||||
int thumbIdColumn = imagesCursor.getColumnIndex(MediaStore.Images.Media._ID);
|
int uriColumn = imagesCursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
do {
|
do {
|
||||||
String name = imagesCursor.getString(bucketColumn);
|
String name = imagesCursor.getString(bucketColumn);
|
||||||
albums.addAlbum(name);
|
String uri = imagesCursor.getString(uriColumn);
|
||||||
albums.addAlbum(ALL_PHOTOS);
|
albums.addAlbum(name, uri);
|
||||||
if(!albums.hasThumbnail(name)) {
|
albums.addAlbum(ALL_PHOTOS, uri);
|
||||||
albums.setThumbnail(name, getThumbnail(imagesCursor.getInt(thumbIdColumn)));
|
|
||||||
}
|
|
||||||
if(!albums.hasThumbnail(ALL_PHOTOS)) {
|
|
||||||
albums.setThumbnail(ALL_PHOTOS, getThumbnail(imagesCursor.getInt(thumbIdColumn)));
|
|
||||||
}
|
|
||||||
} while (imagesCursor.moveToNext());
|
} while (imagesCursor.moveToNext());
|
||||||
}
|
}
|
||||||
imagesCursor.close();
|
imagesCursor.close();
|
||||||
|
|
Loading…
Reference in New Issue