Example usage for com.facebook.react.bridge WritableMap getInt

List of usage examples for com.facebook.react.bridge WritableMap getInt

Introduction

In this page you can find the example usage for com.facebook.react.bridge WritableMap getInt.

Prototype

int getInt(@NonNull String name);

Source Link

Usage

From source file:com.dylanvann.cameraroll.CameraRollManager.java

License:Open Source License

private static void putAlbums(ContentResolver resolver, Cursor cursor, WritableMap response) {
    WritableArray albums = new WritableNativeArray();
    int bucketIdIndex = cursor.getColumnIndex(Video.VideoColumns.BUCKET_ID);
    int bucketNameIndex = cursor.getColumnIndex(Video.VideoColumns.BUCKET_DISPLAY_NAME);
    int idIndex = cursor.getColumnIndex(FileColumns._ID);
    int mimeTypeIndex = cursor.getColumnIndex(FileColumns.MIME_TYPE);
    int mediaTypeIndex = cursor.getColumnIndex(FileColumns.MEDIA_TYPE);
    int dateModifiedIndex = cursor.getColumnIndex(FileColumns.DATE_MODIFIED);
    int widthIndex = IS_JELLY_BEAN_OR_LATER ? cursor.getColumnIndex(FileColumns.WIDTH) : -1;
    int heightIndex = IS_JELLY_BEAN_OR_LATER ? cursor.getColumnIndex(FileColumns.HEIGHT) : -1;
    HashMap<String, WritableMap> albumsMap = new HashMap<>();
    String assetCountKey = "assetCount";
    if (cursor.moveToFirst()) {
        {//from  w w w  . j ava 2  s  . c  o m
            WritableMap album = new WritableNativeMap();
            album.putInt(assetCountKey, cursor.getCount());
            WritableArray previewAssets = new WritableNativeArray();
            WritableMap asset = new WritableNativeMap();
            putAssetInfo(resolver, cursor, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex,
                    mimeTypeIndex, dateModifiedIndex);
            previewAssets.pushMap(asset);
            album.putArray("previewAssets", previewAssets);
            albumsMap.put("-1", album);
        }

        while (cursor.moveToNext()) {
            String albumId = cursor.getString(bucketIdIndex);
            if (!albumsMap.containsKey(albumId)) {
                WritableMap album = new WritableNativeMap();
                String albumName = cursor.getString(bucketNameIndex);
                album.putString("id", albumId);
                album.putString("title", albumName);
                album.putInt(assetCountKey, 1);
                WritableArray previewAssets = new WritableNativeArray();
                WritableMap asset = new WritableNativeMap();
                putAssetInfo(resolver, cursor, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex,
                        mimeTypeIndex, dateModifiedIndex);
                previewAssets.pushMap(asset);
                album.putArray("previewAssets", previewAssets);
                albumsMap.put(albumId, album);
            } else {
                WritableMap album = albumsMap.get(albumId);
                int count = album.getInt(assetCountKey);
                album.putInt(assetCountKey, count + 1);
            }
        }
        Collection<WritableMap> albumsCollection = albumsMap.values();
        for (WritableMap album : albumsCollection) {
            albums.pushMap(album);
        }
    }
    response.putArray("albums", albums);
}