From 7f0daef88f6bb23b2b00e4989da52a1fe31d8d9a Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 5 Mar 2023 14:17:53 +0530 Subject: [PATCH] Simplify ImageHelper IO methods. --- .../com/github/libretube/helpers/ImageHelper.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt index a4cbf3937..7e2325504 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt @@ -15,8 +15,6 @@ import com.github.libretube.api.CronetHelper import com.github.libretube.constants.PreferenceKeys import com.github.libretube.util.DataSaverMode import java.io.File -import java.io.FileOutputStream -import okio.use object ImageHelper { lateinit var imageLoader: ImageLoader @@ -78,18 +76,15 @@ object ImageHelper { } private fun saveImage(context: Context, bitmapImage: Bitmap, imagePath: Uri) { - context.contentResolver.openFileDescriptor(imagePath, "w")?.use { - FileOutputStream(it.fileDescriptor).use { fos -> - bitmapImage.compress(Bitmap.CompressFormat.PNG, 25, fos) - } + context.contentResolver.openOutputStream(imagePath)?.use { + bitmapImage.compress(Bitmap.CompressFormat.PNG, 25, it) } } private fun getImage(context: Context, imagePath: Uri): Bitmap? { - context.contentResolver.openInputStream(imagePath)?.use { - return BitmapFactory.decodeStream(it) + return context.contentResolver.openInputStream(imagePath)?.use { + BitmapFactory.decodeStream(it) } - return null } /**