From 1be049fc91e186b005c7d71a58ae64431d3e4483 Mon Sep 17 00:00:00 2001 From: easyhz Date: Wed, 21 Aug 2024 00:18:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20resourceUri=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#111?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/image/ImageRepository.kt | 2 ++ .../repository/image/ImageRepositoryImpl.kt | 28 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepository.kt b/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepository.kt index 02e4f22e..81b989f6 100644 --- a/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepository.kt +++ b/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepository.kt @@ -1,5 +1,6 @@ package com.easyhz.noffice.data.organization.repository.image +import android.content.Context import android.net.Uri import com.easyhz.noffice.core.model.image.ImagePurpose import com.easyhz.noffice.core.model.image.ImageUrl @@ -10,4 +11,5 @@ interface ImageRepository { suspend fun getMimeType(uri: Uri): Result suspend fun uploadImage(url: String, fileType: String, uri: Uri): Result suspend fun completeImageUpload(fileName: String): Result + suspend fun getDrawableUri(drawableId: Int): Result } \ No newline at end of file diff --git a/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepositoryImpl.kt b/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepositoryImpl.kt index 2723bf96..4fa62c13 100644 --- a/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepositoryImpl.kt +++ b/data/organization/src/main/java/com/easyhz/noffice/data/organization/repository/image/ImageRepositoryImpl.kt @@ -1,5 +1,6 @@ package com.easyhz.noffice.data.organization.repository.image +import android.content.ContentResolver import android.content.Context import android.net.Uri import com.easyhz.noffice.core.common.di.Dispatcher @@ -41,11 +42,30 @@ class ImageRepositoryImpl @Inject constructor( return NofficeFileProvider.getMimeType(context, uri) } - override suspend fun uploadImage(url: String, fileType: String, uri: Uri): Result = withContext(dispatcher) { - return@withContext imageUploader.uploadImage(context, url, fileType, uri) + override suspend fun uploadImage(url: String, fileType: String, uri: Uri): Result = + withContext(dispatcher) { + return@withContext imageUploader.uploadImage(context, url, fileType, uri) + } + + override suspend fun completeImageUpload(fileName: String): Result = + withContext(dispatcher) { + return@withContext imageService.completeImageUpload(ImageRequest(fileName)) + } + + override suspend fun getDrawableUri(drawableId: Int): Result { + return kotlin.runCatching { + drawableId.getResourceUri(context) + } } - override suspend fun completeImageUpload(fileName: String): Result = withContext(dispatcher) { - return@withContext imageService.completeImageUpload(ImageRequest(fileName)) + private fun Int.getResourceUri(context: Context): Uri { + return context.resources.let { + Uri.Builder() + .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) + .authority(it.getResourcePackageName(this)) + .appendPath(it.getResourceTypeName(this)) + .appendPath(it.getResourceEntryName(this)) + .build() + } } } \ No newline at end of file