com.google.android.gms.drive.DriveApi.MetadataBufferResult Java Examples

The following examples show how to use com.google.android.gms.drive.DriveApi.MetadataBufferResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TGDriveBrowser.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void listElements(final TGBrowserCallBack<List<TGBrowserElement>> cb) {
	try {
		if( this.folder != null ) {
			this.folder.getFolder().listChildren(this.client).setResultCallback(new ResultCallback<MetadataBufferResult>() {
				public void onResult(MetadataBufferResult result) {
		            if( result.getStatus().isSuccess() ) {
		            	List<TGBrowserElement> elements = new ArrayList<TGBrowserElement>();
		            	
		            	Iterator<Metadata> it = result.getMetadataBuffer().iterator();
		            	while(it.hasNext()) {
		            		Metadata metadata = it.next();
		            		DriveId driveId = metadata.getDriveId();
		            		String name = metadata.getTitle();
		            		
		            		if(!metadata.isTrashed() && !metadata.isExplicitlyTrashed()) {
			            		if( metadata.isFolder() ) {
			            			elements.add(new TGDriveBrowserFolder(TGDriveBrowser.this.folder, Drive.DriveApi.getFolder(TGDriveBrowser.this.client, driveId), name));
			            		} else {
			            			elements.add(new TGDriveBrowserFile(TGDriveBrowser.this.folder, Drive.DriveApi.getFile(TGDriveBrowser.this.client, driveId), name));
			            		}
		            		}
		            	}
		            	
						if( !elements.isEmpty() ){
							Collections.sort(elements, new TGBrowserElementComparator());
						}
						
		            	cb.onSuccess(elements);
		            } else {
		            	cb.handleError(new TGBrowserException(findActivity().getString(R.string.gdrive_list_children_error)));
		            }
				};
			});
		} else {
			cb.onSuccess(new ArrayList<TGBrowserElement>());
		}
	} catch (Throwable e) {
		cb.handleError(e);
	}
}