Wednesday, 8 August 2018

How can I indicate to the Storage Access Framework that I no longer require the loading animation?

I am writing a DocumentsProvider for Dropbox. I am attempting to follow the Google guidelines for creating a custom provider, as well as Ian Lake's post on Medium for the same.
I am attempting to incorporate the feature within the Storage Access Framework whereby one indicates that there is more data to load.
The relevant portions of my queryChildDocuments() method looks like:
@Override
public Cursor queryChildDocuments(final String parentDocumentId,
                                  final String[] projection,
                                  final String sortOrder)  {

    if (selfPermissionsFailed(getContext())) {
        // Permissions have changed, abort!
        return null;
    }

    // Create a cursor with either the requested fields, or the default projection if 
"projection" is null.
    final MatrixCursor cursor = new MatrixCursor(projection != null ? projection : 
getDefaultDocumentProjection()){
        // Indicate we will be batch loading
        @Override
        public Bundle getExtras() {
            Bundle bundle = new Bundle();
            bundle.putBoolean(DocumentsContract.EXTRA_LOADING, true);
            bundle.putString(DocumentsContract.EXTRA_INFO, getContext().getResources()
.getString(R.string.requesting_data));
            return bundle;
            }

        };

        ListFolderResult result = null;
        DbxClientV2 mDbxClient = DropboxClientFactory.getClient();

        result = mDbxClient.files().listFolderBuilder(parentDocumentId).start();

        if (result.getEntries().size() == 0) {
            // Nothing in the dropbox folder
            Log.d(TAG, "addRowsToQueryChildDocumentsCursor called mDbxClient.files()
.listFolder() but nothing was there!");
            return;
        }

        // Setup notification so cursor will continue to build
        cursor.setNotificationUri(getContext().getContentResolver(),
                                  getChildDocumentsUri(parentDocumentId));

        while (true) {

            // Load the entries and notify listener
            for (Metadata metadata : result.getEntries()) {

                if (metadata instanceof FolderMetadata) {
                    includeFolder(cursor, (FolderMetadata) metadata);

                } else if (metadata instanceof FileMetadata) {
                    includeFile(cursor, (FileMetadata) metadata);
                }

            }

            // Notify for this batch
getContext().getContentResolver().notifyChange(getChildDocumentsUri(parentDocumentId), 
null);

            // See if we are ready to exit
            if (!result.getHasMore()) {
                break;
            }
            result = mDbxClient.files().listFolderContinue(result.getCursor());
        }

This all works fine. I get the cursor loaded with data as I expect. What I get "for free" (presumably due to the extras bundle) is that the SAF automatically places a visual at the top of the screen for both the text to the user ("Requesting data"), and an animated bar (on my Samsung Galaxy S7 running API 27) moving back and forth to indicate that the cursor is loading:
screenshot of 'loading' bar and text
My question is - once I exit the fetch loop and so am done loading, how do I programmatically get rid of both the EXTRA_INFO text and the EXTRA_LOADING animation at the top of the screen? I have scoured the APIs and am not seeing anything that looks like a "signal" to tell the SAF that the loading is complete.
The android docs don't discuss this feature much, Ian's Medium post just briefly mentions to send the notification so the cursor knows to refresh itself. Neither have anything to say about the animation.


from How can I indicate to the Storage Access Framework that I no longer require the loading animation?

No comments:

Post a Comment