Java Code Examples for com.google.android.gms.drive.DriveApi#MetadataBufferResult
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: GoogleDriveClient.java From financisto with GNU General Public License v2.0 | 6 votes |
private List<DriveFileInfo> fetchFiles(DriveApi.MetadataBufferResult metadataBufferResult) { List<DriveFileInfo> files = new ArrayList<DriveFileInfo>(); MetadataBuffer metadataBuffer = metadataBufferResult.getMetadataBuffer(); if (metadataBuffer == null) return files; try { for (Metadata metadata : metadataBuffer) { if (metadata == null) continue; String title = metadata.getTitle(); if (!title.endsWith(".backup")) continue; files.add(new DriveFileInfo(metadata.getDriveId(), title, metadata.getCreatedDate())); } } finally { metadataBuffer.close(); } Collections.sort(files); return files; }
Example 2
Source File: Querier.java From Drive-Database-Sync with Apache License 2.0 | 6 votes |
/** * Handles the result of the query. If the results are nonzero, passes up the {@link Metadata} * out of the result one at a time through {@link QuerierResultCallback#onQuerierResult(Metadata)} * with the {@link QuerierResultCallback} registered in ths {@link Querier}. If the results are * null, calls {@link QuerierResultCallback#onNoQuerierResult()} * @param result the result of the query */ @Override public void onResult(DriveApi.MetadataBufferResult result) { if (!result.getStatus().isSuccess()) { Log.e("Querier", "Problem while retrieving files"); return; } // Get the metadata buffer MetadataBuffer buffer = result.getMetadataBuffer(); // Check for file dne if (buffer.getCount() == 0) { // Call null result callback callback.onNoQuerierResult(); } // Get the metadata for (Metadata m : buffer) { if (m.isInAppFolder() && !m.isTrashed()) { callback.onQuerierResult(m); break; } } }
Example 3
Source File: SettingsBackup.java From Slide with GNU General Public License v3.0 | 6 votes |
@Override public void onResult(DriveApi.MetadataBufferResult result) { int i = 0; for (Metadata a : result.getMetadataBuffer()) { i++; title = a.getTitle(); new RetrieveDriveFileContentsAsyncTask(title).execute(a.getDriveId()); } progress = new MaterialDialog.Builder(SettingsBackup.this) .cancelable(false) .title(R.string.backup_restoring) .progress(false, i) .build(); progress.show(); }
Example 4
Source File: GoogleDriveClient.java From financisto with GNU General Public License v2.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.BACKGROUND) public void listFiles(DoDriveListFiles event) { try { String targetFolder = getDriveFolderName(); ConnectionResult connectionResult = connect(); if (connectionResult.isSuccess()) { DriveFolder folder = getDriveFolder(targetFolder); Query query = new Query.Builder() .addFilter(Filters.and( Filters.eq(SearchableField.MIME_TYPE, Export.BACKUP_MIME_TYPE), Filters.eq(SearchableField.TRASHED, false) )) .build(); DriveApi.MetadataBufferResult metadataBufferResult = folder.queryChildren(googleApiClient, query).await(); if (metadataBufferResult.getStatus().isSuccess()) { List<DriveFileInfo> driveFiles = fetchFiles(metadataBufferResult); handleSuccess(driveFiles); } else { handleFailure(metadataBufferResult.getStatus()); } } else { handleConnectionResult(connectionResult); } } catch (Exception e) { handleError(e); } }
Example 5
Source File: GoogleDriveClient.java From financisto with GNU General Public License v2.0 | 5 votes |
private DriveFolder getOrCreateDriveFolder(String targetFolder) throws IOException { Query query = new Query.Builder().addFilter(Filters.and( Filters.eq(SearchableField.TRASHED, false), Filters.eq(SearchableField.TITLE, targetFolder), Filters.eq(SearchableField.MIME_TYPE, "application/vnd.google-apps.folder") )).build(); DriveApi.MetadataBufferResult result = Drive.DriveApi.query(googleApiClient, query).await(); if (result.getStatus().isSuccess()) { DriveId driveId = fetchDriveId(result); if (driveId != null) { return Drive.DriveApi.getFolder(googleApiClient, driveId); } } return createDriveFolder(targetFolder); }
Example 6
Source File: GoogleDriveClient.java From financisto with GNU General Public License v2.0 | 5 votes |
private DriveId fetchDriveId(DriveApi.MetadataBufferResult result) { MetadataBuffer buffer = result.getMetadataBuffer(); try { for (Metadata metadata : buffer) { if (metadata == null) continue; return metadata.getDriveId(); } } finally { buffer.close(); } return null; }
Example 7
Source File: GoogleDriveService.java From WheelLogAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void onResult(@NonNull DriveApi.MetadataBufferResult result) { if (!result.getStatus().isSuccess()) { Timber.i("Problem while retrieving files"); exitUploadFailed(); return; } for (Metadata m: result.getMetadataBuffer()) { if (m.isFolder() && !m.isTrashed() && Constants.LOG_FOLDER_NAME.equals(m.getTitle())) { folderDriveId = m.getDriveId(); break; } } result.release(); Timber.i("Successfully listed files."); if (folderDriveId == null) { Timber.i("Folder DriveId is null"); createLogFolderInDriveRoot(); } else { Timber.i("Folder DriveId is not null"); createLogInFolder(); } }