-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from leonlatsch/release/1.7.4
Release: 1.7.4
- Loading branch information
Showing
17 changed files
with
313 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/main/java/dev/leonlatsch/photok/imageloading/data/ImageStorageImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2020-2024 Leon Latsch | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.leonlatsch.photok.imageloading.data | ||
|
||
import androidx.core.graphics.drawable.toBitmap | ||
import coil.ImageLoader | ||
import coil.request.ErrorResult | ||
import coil.request.ImageRequest | ||
import coil.request.SuccessResult | ||
import dev.leonlatsch.photok.imageloading.domain.ImageStorage | ||
import dev.leonlatsch.photok.other.extensions.writeTo | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.OutputStream | ||
import javax.inject.Inject | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
class ImageStorageImpl @Inject constructor( | ||
private val imageLoader: ImageLoader, | ||
) : ImageStorage { | ||
|
||
/** | ||
* Executes an [imageRequest] and writes its result to the desired [outputStream]. | ||
*/ | ||
override suspend fun execAndWrite( | ||
imageRequest: ImageRequest, | ||
outputStream: OutputStream?, | ||
): Result<Unit> = withContext(Dispatchers.IO) { | ||
outputStream ?: return@withContext Result.failure(Exception("stream is null")) | ||
|
||
when (val imageResult = imageLoader.execute(imageRequest)) { | ||
is SuccessResult -> suspendCoroutine { continuation -> | ||
try { | ||
outputStream.use { out -> | ||
imageResult.drawable.toBitmap().writeTo(out) | ||
} | ||
|
||
continuation.resume(Result.success(Unit)) | ||
} catch (e: Exception) { | ||
continuation.resume(Result.failure(e)) | ||
} | ||
} | ||
is ErrorResult -> Result.failure(imageResult.throwable) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/dev/leonlatsch/photok/imageloading/domain/ImageStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2020-2024 Leon Latsch | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.leonlatsch.photok.imageloading.domain | ||
|
||
import coil.request.ImageRequest | ||
import java.io.OutputStream | ||
|
||
interface ImageStorage { | ||
suspend fun execAndWrite( | ||
imageRequest: ImageRequest, | ||
outputStream: OutputStream?, | ||
): Result<Unit> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.