From 548d10dbe05de41f1ccd8c123132999f4c9adbfb Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Wed, 9 Aug 2023 22:25:30 -0700 Subject: [PATCH] [Fix] Use correct data source type in PathAttributesFetcher. Fixes: #730 --- .../me/zhanghai/android/files/coil/CoilUtils.kt | 15 +++++++++++++++ .../android/files/coil/PathAttributesFetcher.kt | 7 +++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/me/zhanghai/android/files/coil/CoilUtils.kt b/app/src/main/java/me/zhanghai/android/files/coil/CoilUtils.kt index 4c67688ae..5e1da34de 100644 --- a/app/src/main/java/me/zhanghai/android/files/coil/CoilUtils.kt +++ b/app/src/main/java/me/zhanghai/android/files/coil/CoilUtils.kt @@ -7,17 +7,32 @@ package me.zhanghai.android.files.coil import android.graphics.Bitmap import android.os.Build +import coil.decode.DataSource import coil.size.Dimension import coil.size.Scale import coil.size.Size import coil.size.isOriginal import coil.size.pxOrElse +import java8.nio.file.Path +import me.zhanghai.android.files.provider.archive.archiveFile +import me.zhanghai.android.files.provider.archive.isArchivePath +import me.zhanghai.android.files.provider.ftp.isFtpPath +import me.zhanghai.android.files.provider.sftp.isSftpPath +import me.zhanghai.android.files.provider.smb.isSmbPath val Bitmap.Config.isHardware: Boolean get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && this == Bitmap.Config.HARDWARE fun Bitmap.Config.toSoftware(): Bitmap.Config = if (isHardware) Bitmap.Config.ARGB_8888 else this +val Path.dataSource: DataSource + get() = + when { + isArchivePath -> archiveFile.dataSource + isFtpPath || isSftpPath || isSmbPath -> DataSource.NETWORK + else -> DataSource.DISK + } + inline fun Size.widthPx(scale: Scale, original: () -> Int): Int = if (isOriginal) original() else width.toPx(scale) diff --git a/app/src/main/java/me/zhanghai/android/files/coil/PathAttributesFetcher.kt b/app/src/main/java/me/zhanghai/android/files/coil/PathAttributesFetcher.kt index a4ebbbdbd..627abe8db 100644 --- a/app/src/main/java/me/zhanghai/android/files/coil/PathAttributesFetcher.kt +++ b/app/src/main/java/me/zhanghai/android/files/coil/PathAttributesFetcher.kt @@ -11,7 +11,6 @@ import android.media.MediaMetadataRetriever import android.os.ParcelFileDescriptor import androidx.core.graphics.drawable.toDrawable import coil.ImageLoader -import coil.decode.DataSource import coil.decode.ImageSource import coil.fetch.DrawableResult import coil.fetch.FetchResult @@ -90,7 +89,7 @@ class PathAttributesFetcher( } if (thumbnail != null) { return DrawableResult( - thumbnail.toDrawable(options.context.resources), true, DataSource.DISK + thumbnail.toDrawable(options.context.resources), true, path.dataSource ) } } @@ -116,7 +115,7 @@ class PathAttributesFetcher( val inputStream = path.newInputStream() return SourceResult( ImageSource(inputStream.source().buffer(), options.context), - if (mimeType != MimeType.GENERIC) mimeType.value else null, DataSource.DISK + if (mimeType != MimeType.GENERIC) mimeType.value else null, path.dataSource ) } mimeType.isMedia && (path.isLinuxPath || path.isDocumentPath) -> { @@ -133,7 +132,7 @@ class PathAttributesFetcher( return SourceResult( ImageSource( embeddedPicture.inputStream().source().buffer(), options.context - ), null, DataSource.DISK + ), null, path.dataSource ) } if (mimeType.isVideo) {