Skip to content

Commit

Permalink
feat: resourceUri 로직 추가 #111
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 20, 2024
1 parent 32d08ce commit 1be049f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,4 +11,5 @@ interface ImageRepository {
suspend fun getMimeType(uri: Uri): Result<String>
suspend fun uploadImage(url: String, fileType: String, uri: Uri): Result<Unit>
suspend fun completeImageUpload(fileName: String): Result<Unit>
suspend fun getDrawableUri(drawableId: Int): Result<Uri>
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,11 +42,30 @@ class ImageRepositoryImpl @Inject constructor(
return NofficeFileProvider.getMimeType(context, uri)
}

override suspend fun uploadImage(url: String, fileType: String, uri: Uri): Result<Unit> = withContext(dispatcher) {
return@withContext imageUploader.uploadImage(context, url, fileType, uri)
override suspend fun uploadImage(url: String, fileType: String, uri: Uri): Result<Unit> =
withContext(dispatcher) {
return@withContext imageUploader.uploadImage(context, url, fileType, uri)
}

override suspend fun completeImageUpload(fileName: String): Result<Unit> =
withContext(dispatcher) {
return@withContext imageService.completeImageUpload(ImageRequest(fileName))
}

override suspend fun getDrawableUri(drawableId: Int): Result<Uri> {
return kotlin.runCatching {
drawableId.getResourceUri(context)
}
}

override suspend fun completeImageUpload(fileName: String): Result<Unit> = 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()
}
}
}

0 comments on commit 1be049f

Please sign in to comment.