Skip to content

Commit

Permalink
Merge pull request #341 from leonlatsch/master
Browse files Browse the repository at this point in the history
Finish Release 1.7.2
  • Loading branch information
leonlatsch authored Jul 4, 2024
2 parents 7650f84 + 50e447f commit cb7ad91
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/open_source_licenses.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fun AlbumTile(album: AlbumItem, onAlbumClicked: (String) -> Unit) {
} else {
val requestData = remember(album) {
EncryptedImageRequestData(
album.albumCover.filename,
album.albumCover.filename,
internalFileName = album.albumCover.filename,
mimeType = album.albumCover.mimeType
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ package dev.leonlatsch.photok.imageloading.compose
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import android.graphics.Movie
import android.os.Build
import androidx.core.graphics.drawable.toDrawable
import coil.decode.DataSource
import coil.drawable.MovieDrawable
import coil.fetch.DrawableResult
import coil.fetch.FetchResult
import coil.fetch.Fetcher
import dev.leonlatsch.photok.imageloading.compose.model.EncryptedImageRequestData
import dev.leonlatsch.photok.model.database.entity.PhotoType
import dev.leonlatsch.photok.model.io.EncryptedStorageManager

/**
Expand All @@ -38,15 +43,28 @@ class EncryptedImageFetcher(
private val resources: Resources,
) : Fetcher {

@Suppress("DEPRECATION") // ImageDecoder is only available from API 28
override suspend fun fetch(): FetchResult? {
val inputStream = encryptedStorageManager.internalOpenEncryptedFileInput(requestData.internalFileName)
inputStream ?: return null

val bitmap: Bitmap? = BitmapFactory.decodeStream(inputStream)
bitmap ?: return null
val drawable = if (requestData.mimeType == PhotoType.GIF.mimeType && requestData.playGif) {
if (Build.VERSION.SDK_INT >= 31) {
val bytes = inputStream.readBytes()
val source = ImageDecoder.createSource(bytes)
ImageDecoder.decodeDrawable(source)
} else {
val movie = Movie.decodeStream(inputStream)
MovieDrawable(movie)
}
} else {
val bitmap: Bitmap? = BitmapFactory.decodeStream(inputStream)
bitmap ?: return null
bitmap.toDrawable(resources)
}

return DrawableResult(
drawable = bitmap.toDrawable(resources),
drawable = drawable,
isSampled = false,
dataSource = DataSource.DISK,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ package dev.leonlatsch.photok.imageloading.compose.model
data class EncryptedImageRequestData(
val internalFileName: String,
val mimeType: String,
val playGif: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package dev.leonlatsch.photok.imageloading.di

import android.content.Context
import android.os.Build.VERSION.SDK_INT
import coil.ImageLoader
import coil.decode.GifDecoder
import coil.decode.ImageDecoderDecoder
import coil.request.CachePolicy
import dagger.Module
import dagger.Provides
Expand All @@ -41,11 +38,6 @@ object ImageLoadingModule {
): ImageLoader = ImageLoader.Builder(context)
.components {
add(encryptedImageFetcherFactory)
if (SDK_INT >= 28) {
add(ImageDecoderDecoder.Factory())
} else {
add(GifDecoder.Factory())
}
}
.diskCachePolicy(CachePolicy.DISABLED)
.diskCache(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ fun PhotoViewHolderContent(
}

EncryptedImageRequestData(
fileName,
photo.type.mimeType,
internalFileName = fileName,
mimeType = photo.type.mimeType,
playGif = true,
)
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#Sat Jun 01 10:22:31 UTC 2024
#Wed Jul 03 08:11:08 UTC 2024
android.nonTransitiveRClass=false
kotlin.code.style=official
kapt.incremental.apt=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.databinding.incremental=true
appVersionName=1.7.1
appVersionName=1.7.2
org.gradle.jvmargs=-Xmx2048m
appVersionCode=29
appVersionCode=30
android.useAndroidX=true
android.enableJetifier=true

0 comments on commit cb7ad91

Please sign in to comment.