Skip to content

Commit

Permalink
[Fix] Use correct data source type in PathAttributesFetcher.
Browse files Browse the repository at this point in the history
Fixes: #730
  • Loading branch information
zhanghai committed Aug 10, 2023
1 parent efdcb8c commit 548d10d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/me/zhanghai/android/files/coil/CoilUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
}
Expand All @@ -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) -> {
Expand All @@ -133,7 +132,7 @@ class PathAttributesFetcher(
return SourceResult(
ImageSource(
embeddedPicture.inputStream().source().buffer(), options.context
), null, DataSource.DISK
), null, path.dataSource
)
}
if (mimeType.isVideo) {
Expand Down

0 comments on commit 548d10d

Please sign in to comment.