-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate Image [#59] #74
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions
23
domain/src/main/java/com/foke/together/domain/interactor/GeneratePhotoFrameUseCase.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,23 @@ | ||
package com.foke.together.domain.interactor | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.net.Uri | ||
import com.foke.together.domain.interactor.entity.CutFrameType | ||
import com.foke.together.domain.output.ImageRepositoryInterface | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class GeneratePhotoFrameUseCase @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
private val imageRepositoryInterface: ImageRepositoryInterface | ||
){ | ||
fun getCutFrameType(): CutFrameType = imageRepositoryInterface.getCutFrameType() | ||
suspend fun setCutFrameType(type: Int) = imageRepositoryInterface.setCutFrameType(type) | ||
|
||
fun getCapturedImageListUri(): List<Uri> = imageRepositoryInterface.getCachedImageUriList() | ||
suspend fun clearCapturedImageList() = imageRepositoryInterface.clearCacheDir() | ||
suspend fun saveGraphicsLayerImage(image: Bitmap, fileName: String) = imageRepositoryInterface.cachingImage(image, fileName) | ||
suspend fun saveFinalImage(image: Bitmap, fileName: String) = imageRepositoryInterface.saveToStorage(image, fileName) | ||
} |
26 changes: 26 additions & 0 deletions
26
domain/src/main/java/com/foke/together/domain/interactor/entity/CutFrameType.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,26 @@ | ||
package com.foke.together.domain.interactor.entity | ||
|
||
enum class CutFrameType { | ||
MAKER_FAIRE, | ||
FOURCUT_LIGHT, | ||
FOURCUT_DARK; | ||
|
||
companion object { | ||
fun findBy(name: String): CutFrameType { | ||
return when (name) { | ||
MAKER_FAIRE.name -> MAKER_FAIRE | ||
FOURCUT_LIGHT.name -> FOURCUT_LIGHT | ||
FOURCUT_DARK.name -> FOURCUT_DARK | ||
else -> throw IllegalArgumentException("Unknown value: $name") | ||
} | ||
} | ||
fun findBy(ordinal: Int): CutFrameType { | ||
return when (ordinal) { | ||
MAKER_FAIRE.ordinal -> MAKER_FAIRE | ||
FOURCUT_LIGHT.ordinal -> FOURCUT_LIGHT | ||
FOURCUT_DARK.ordinal -> FOURCUT_DARK | ||
else -> throw IllegalArgumentException("Unknown value: $ordinal") | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
domain/src/main/java/com/foke/together/domain/output/ImageRepositoryInterface.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,20 @@ | ||
package com.foke.together.domain.output | ||
|
||
import android.graphics.Bitmap | ||
import android.net.Uri | ||
import android.os.Environment | ||
import com.foke.together.domain.interactor.entity.CutFrameType | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface ImageRepositoryInterface { | ||
fun getCutFrameType(): CutFrameType | ||
suspend fun setCutFrameType(type: Int) | ||
// 촬영한 사진들 모음 | ||
suspend fun cachingImage(image: Bitmap, fileName: String) : Uri | ||
fun getCachedImageUriList() : List<Uri> | ||
suspend fun clearCacheDir() | ||
|
||
// 완성된 프레임 모음 | ||
suspend fun saveToStorage(image: Bitmap, fileName :String) : Uri | ||
fun getUriToBitmap(imageUri: Uri): Bitmap | ||
} |
60 changes: 60 additions & 0 deletions
60
external/src/main/java/com/foke/together/external/repository/ImageRepository.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,60 @@ | ||
package com.foke.together.external.repository | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.ImageDecoder | ||
import android.net.Uri | ||
import android.provider.MediaStore | ||
import com.foke.together.domain.interactor.entity.CutFrameType | ||
import com.foke.together.domain.output.ImageRepositoryInterface | ||
import com.foke.together.util.AppPolicy | ||
import com.foke.together.util.ImageFileUtil | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class ImageRepository @Inject constructor( | ||
@ApplicationContext private val context: Context | ||
): ImageRepositoryInterface{ | ||
private var cutFrameType: CutFrameType = CutFrameType.MAKER_FAIRE | ||
|
||
override fun getCutFrameType(): CutFrameType = cutFrameType | ||
override suspend fun setCutFrameType(type: Int) { | ||
cutFrameType = CutFrameType.findBy(type) | ||
} | ||
|
||
override suspend fun cachingImage(image: Bitmap, fileName: String): Uri { | ||
return ImageFileUtil.cacheBitmap(context, image, fileName) | ||
} | ||
|
||
override fun getCachedImageUriList(): List<Uri> { | ||
var uriList = mutableListOf<Uri>() | ||
context.cacheDir.listFiles().forEach { | ||
if(it.name.contains(AppPolicy.CAPTURED_FOUR_CUT_IMAGE_NAME)){ | ||
// capture로 시작하는 파일만 반환 | ||
uriList.add(Uri.fromFile(it)) | ||
} | ||
} | ||
return uriList | ||
} | ||
|
||
override suspend fun clearCacheDir() { | ||
context.cacheDir.listFiles().forEach { | ||
if(it.name.contains(".jpg")){ | ||
it.delete() | ||
} | ||
} | ||
} | ||
|
||
override suspend fun saveToStorage(image: Bitmap, fileName: String): Uri { | ||
return ImageFileUtil.saveBitmapToStorage(context, image, fileName) | ||
} | ||
|
||
override fun getUriToBitmap(imageUri: Uri): Bitmap { | ||
return ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, imageUri)) | ||
} | ||
|
||
} |
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
91 changes: 58 additions & 33 deletions
91
presenter/src/main/java/com/foke/together/presenter/frame/FourCutFrame.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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file 작업 코드는 repository에서 직접 하는거보단 하위에
DataStore
나Util
에서 하는게 맞아보입니다. 다음 페이즈에서 변경해봅시다~