Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 961f1ec8 authored by Steve McKay's avatar Steve McKay
Browse files

Only load thumbnail if supported by provider.

Adjust padding on mime icon images so they don't get overlapped oddly by file name bar.
Fix NPE in paging provider.

Bug: 64080832
Bug: 64091913
Test: manual
Change-Id: I602f73a4952263c7943d8d51995094424582a253
parent efd10ac3
Loading
Loading
Loading
Loading
+35 −20
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import com.android.documentsui.inspector.InspectorController.HeaderDisplay;

import java.util.function.Consumer;

import javax.annotation.Nullable;

/**
 * Organizes and displays the title and thumbnail for a given document
 */
@@ -77,14 +79,35 @@ public final class HeaderView extends RelativeLayout implements HeaderDisplay {
        mTitle.setText(displayName);
    }

    private void loadHeaderImage(DocumentInfo info) {
    private void loadHeaderImage(DocumentInfo doc) {
        if (!doc.isThumbnailSupported()) {
            showImage(doc, null);
        } else {
            Consumer<Bitmap> callback = new Consumer<Bitmap>() {
                @Override
                public void accept(Bitmap thumbnail) {
                    showImage(doc, thumbnail);
                }
            };
            // load the thumbnail async.
            final ThumbnailLoader task = new ThumbnailLoader(doc.derivedUri, mThumbnail,
                    mImageDimensions, doc.lastModified, callback, false);
            task.executeOnExecutor(ProviderExecutor.forAuthority(doc.derivedUri.getAuthority()),
                    doc.derivedUri);
        }
    }

    /**
     * Shows the supplied image, falling back to a mimetype icon if the image is null.
     */
    private void showImage(DocumentInfo info, @Nullable Bitmap thumbnail) {
        if (thumbnail != null) {
            mThumbnail.resetPaddingToInitialValues();
            mThumbnail.setScaleType(ScaleType.CENTER_CROP);
            mThumbnail.setImageBitmap(thumbnail);
        } else {
            mThumbnail.setPadding(0, 0, 0, mTitle.getHeight());

            Drawable mimeIcon =
                    mContext.getContentResolver().getTypeDrawable(info.mimeType);
            mThumbnail.setScaleType(ScaleType.FIT_CENTER);
@@ -92,12 +115,4 @@ public final class HeaderView extends RelativeLayout implements HeaderDisplay {
        }
        mThumbnail.animate().alpha(1.0f).start();
    }
        };

        // load the thumbnail async.
        final ThumbnailLoader task = new ThumbnailLoader(info.derivedUri, mThumbnail,
                mImageDimensions, info.lastModified, callback, false);
        task.executeOnExecutor(ProviderExecutor.forAuthority(info.derivedUri.getAuthority()),
                info.derivedUri);
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class PagingProvider extends TestRootProvider {
            String parentDocumentId, String[] projection, Bundle queryArgs)
            throws FileNotFoundException {

        // TODO: Content notification.
        queryArgs = queryArgs != null ? queryArgs : Bundle.EMPTY;

        MatrixCursor c = createDocCursor(projection);
        Bundle extras = c.getExtras();