Skip to content

Commit

Permalink
Refactor image repository and presenter screens
Browse files Browse the repository at this point in the history
- Refactor ImageRepository to include AppPolicy for captured four-cut image name
- Refactor GenerateSingleRowImageScreen and GenerateTwoRowImageScreen to use ChainStyle.Packed for vertical chain
- Refactor CameraViewModel to use AppPolicy for captured four-cut image name
- Refactor GenerateSingleRowImageViewModel and GenerateTwoRowImageViewModel to use AppPolicy for final image names
- Update AppPolicy to include constants for captured four-cut image name, single row final image name, and two row final image name
  • Loading branch information
ing03201 committed Oct 10, 2024
1 parent 760590e commit ab99935
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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
Expand All @@ -32,7 +33,7 @@ class ImageRepository @Inject constructor(
override fun getCachedImageUriList(): List<Uri> {
var uriList = mutableListOf<Uri>()
context.cacheDir.listFiles().forEach {
if(it.name.contains("capture")){
if(it.name.contains(AppPolicy.CAPTURED_FOUR_CUT_IMAGE_NAME)){
// capture로 시작하는 파일만 반환
uriList.add(Uri.fromFile(it))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CameraViewModel @Inject constructor(
override fun onFinish() {
viewModelScope.launch {
val bitmap = graphicsLayer.toImageBitmap().asAndroidBitmap()
generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, "capture_${_captureCount.value}")
generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, "${AppPolicy.CAPTURED_FOUR_CUT_IMAGE_NAME}_${_captureCount.value}")
_progressState.floatValue = 1f
if (_captureCount.intValue < AppPolicy.CAPTURE_COUNT) {
_captureCount.intValue += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import com.foke.together.domain.interactor.GeneratePhotoFrameUseCase
import com.foke.together.domain.interactor.entity.CutFrameType
import com.foke.together.util.AppLog
import com.foke.together.util.AppPolicy
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
Expand All @@ -21,8 +22,7 @@ class GenerateSingleRowImageViewModel @Inject constructor(

suspend fun generateImage(graphicsLayer: GraphicsLayer) {
val bitmap = graphicsLayer.toImageBitmap().asAndroidBitmap()
val finalExternalImageUri = generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, "final_single_row")
val finalInternalImageUri = generatePhotoFrameUseCase.saveFinalImage(bitmap, "final_single_row")
AppLog.d("GenerateImageViewModel", "generateTwoRowImage" ,"twoRow: $finalExternalImageUri")
val finalCachedImageUri = generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, AppPolicy.SINGLE_ROW_FINAL_IMAGE_NAME)
AppLog.d("GenerateImageViewModel", "generateTwoRowImage" ,"twoRow: $finalCachedImageUri")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import com.foke.together.domain.interactor.GeneratePhotoFrameUseCase
import com.foke.together.domain.interactor.entity.CutFrameType
import com.foke.together.util.AppLog
import com.foke.together.util.AppPolicy
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
Expand All @@ -21,8 +22,7 @@ class GenerateTwoRowImageViewModel @Inject constructor(

suspend fun generateImage(graphicsLayer: GraphicsLayer) {
val bitmap = graphicsLayer.toImageBitmap().asAndroidBitmap()
val finalExternalImageUri = generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, "final_two_row")
val finalInternalImageUri = generatePhotoFrameUseCase.saveFinalImage(bitmap, "final_two_row")
val finalExternalImageUri = generatePhotoFrameUseCase.saveGraphicsLayerImage(bitmap, AppPolicy.TWO_ROW_FINAL_IMAGE_NAME)
AppLog.d("GenerateImageViewModel", "generateTwoRowImage" ,"twoRow: $finalExternalImageUri")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class ShareViewModel @Inject constructor(
}

fun downloadImage() {

}
}
4 changes: 4 additions & 0 deletions util/src/main/java/com/foke/together/util/AppPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ object AppPolicy {
const val CAPTURE_INTERVAL = 10000L
const val CAPTURE_COUNT = 4
const val COUNTDOWN_INTERVAL = 10L

const val CAPTURED_FOUR_CUT_IMAGE_NAME = "capture"
const val SINGLE_ROW_FINAL_IMAGE_NAME = "final_single_row"
const val TWO_ROW_FINAL_IMAGE_NAME = "final_two_row"
}

0 comments on commit ab99935

Please sign in to comment.