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

Commit 1987de82 authored by Austin Kolander's avatar Austin Kolander Committed by android-build-merger
Browse files

Fixed bug of directorys loading the wrong thumbnail.

am: b7b47ef5

Change-Id: I41ba6ccb2ee99c3987e37a18e0b5f06062d37dbe
parents a835f8e7 b7b47ef5
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();
            }
        };