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

Commit b7b47ef5 authored by Austin Kolander's avatar Austin Kolander
Browse files

Fixed bug of directorys loading the wrong thumbnail.

Directory was loading the thumbnail of the first item in the directory,
not the directorys mime icon.

Bug: 63768247
Test: --
Change-Id: I91cb9494e5610bce9996981e98b46af2b0557239
parent d1384dd8
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -18,19 +18,11 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/inspector_mime"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter"
        android:background="@android:color/black" />

    <ImageView
        android:id="@+id/inspector_thumbnail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="0.0"
        android:scaleType="centerCrop"
        android:background="@android:color/black" />

    <TextView
+17 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.TextView;

@@ -43,7 +44,6 @@ public final class HeaderView extends RelativeLayout implements Consumer<Documen

    private final Context mContext;
    private final View mHeader;
    private ImageView mMime;
    private ImageView mThumbnail;
    private final TextView mTitle;
    private Point mImageDimensions;
@@ -62,7 +62,6 @@ public final class HeaderView extends RelativeLayout implements Consumer<Documen
                Context.LAYOUT_INFLATER_SERVICE);
        mContext = context;
        mHeader = inflater.inflate(R.layout.inspector_header, null);
        mMime = (ImageView) mHeader.findViewById(R.id.inspector_mime);
        mThumbnail = (ImageView) mHeader.findViewById(R.id.inspector_thumbnail);
        mTitle = (TextView) mHeader.findViewById(R.id.inspector_file_title);

@@ -78,8 +77,12 @@ public final class HeaderView extends RelativeLayout implements Consumer<Documen
        }

        if (!hasHeaderImage()) {
            if (info.isDirectory()) {
                loadFileIcon(info);
            } else {
                loadHeaderImage(info);
            }
        }
        mTitle.setText(info.displayName);
    }

@@ -92,19 +95,25 @@ public final class HeaderView extends RelativeLayout implements Consumer<Documen
        return false;
    }

    private void loadFileIcon(DocumentInfo info) {
        Drawable mimeIcon = mContext.getContentResolver()
            .getTypeDrawable(info.mimeType);
        mThumbnail.setScaleType(ScaleType.FIT_CENTER);
        mThumbnail.setImageDrawable(mimeIcon);
    }

    private void loadHeaderImage(DocumentInfo info) {

        Consumer<Bitmap> callback = new Consumer<Bitmap>() {
            @Override
            public void accept(Bitmap bitmap) {
                if (bitmap != null) {
                    mThumbnail.setScaleType(ScaleType.CENTER_CROP);
                    mThumbnail.setImageBitmap(bitmap);
                    ThumbnailLoader.ANIM_FADE_IN.accept(mMime, mThumbnail);
                } else {
                    Drawable mimeIcon = mContext.getContentResolver()
                            .getTypeDrawable(info.mimeType);
                    mMime.setImageDrawable(mimeIcon);
                    loadFileIcon(info);
                }
                mThumbnail.animate().alpha(1.0f).start();
            }
        };