Skip to content

Commit

Permalink
refactor Session data [FoKE-Developers#121]
Browse files Browse the repository at this point in the history
- 기존에 단순하게 세션 키만 담고 있었음
- 세션 키, 화면 상태, 프레임 정보 및 상태 정보를 담도록 변경
  • Loading branch information
DokySp committed Dec 27, 2024
1 parent 2ab3e2b commit e182e78
Show file tree
Hide file tree
Showing 34 changed files with 345 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,48 @@ 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.interactor.entity.CutFrameTypeV1
import com.foke.together.domain.output.ImageRepositoryInterface
import com.foke.together.util.AppPolicy
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@Deprecated("Not in use")
class GeneratePhotoFrameUseCase @Inject constructor(
@ApplicationContext private val context: Context,
private val imageRepositoryInterface: ImageRepositoryInterface
){
fun getCutFrameType(): CutFrameType = imageRepositoryInterface.getCutFrameType()
// 네컷 프레임 선택하는 UseCase
@Deprecated("Not in use")
fun getCutFrameType(): CutFrameTypeV1 = imageRepositoryInterface.getCutFrameType()
@Deprecated("Not in use")
suspend fun setCutFrameType(type: Int) = imageRepositoryInterface.setCutFrameType(type)


// 촬영한 이미지 리스트 관리
@Deprecated("Not in use")
fun getCapturedImageListUri(): List<Uri> = imageRepositoryInterface.getCachedImageUriList()
@Deprecated("Not in use")
suspend fun clearCapturedImageList() = imageRepositoryInterface.clearCacheDir()


// 화면 요소를 이미지로 저장
@Deprecated("Not in use")
suspend fun saveGraphicsLayerImage(image: Bitmap, fileName: String) = imageRepositoryInterface.cachingImage(image, fileName)
@Deprecated("Not in use")
suspend fun saveFinalImage(image: Bitmap, fileName: String) = imageRepositoryInterface.saveToStorage(image, fileName)


// 최종 이미지 URL 가져오기
@Deprecated("Not in use")
fun getFinalSingleImageUri(): Uri {
var finalSingleImageUri: Uri = Uri.EMPTY
context.cacheDir.listFiles().forEach {
file -> if (file.name.contains("${AppPolicy.SINGLE_ROW_FINAL_IMAGE_NAME}")) { finalSingleImageUri = Uri.fromFile(file) }
}
return finalSingleImageUri
}

@Deprecated("Not in use")
fun getFinalTwoImageUri(): Uri {
var finalTwoImageUri: Uri = Uri.EMPTY
context.cacheDir.listFiles().forEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package com.foke.together.domain.interactor.entity

enum class CutFrameType {
MAKER_FAIRE,
FOURCUT_LIGHT,
FOURCUT_DARK;
import androidx.annotation.DrawableRes
import com.foke.together.domain.R

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")
}
}
}
}
sealed class CutFrame (
@DrawableRes val frameImageSrc: Int, // TODO: asset 에 추가 및 src 값을 넣어서 처리
val additionalFrameImageSrc: List<String>,
val photoPosition: List<PhotoPosition>
)

// TODO: add information of frames
class FourCutLightFrame: CutFrame(R.drawable.fourcut_frame_medium_light, emptyList(), emptyList())
class FourCurDarkFrame: CutFrame(R.drawable.fourcut_frame_medium_dark, emptyList(), emptyList())
class MakerFaireFrame: CutFrame(R.drawable.maker_faire_frame, emptyList(), emptyList())
class WeddingFrame1: CutFrame(R.drawable.maker_faire_frame, emptyList(), emptyList())
class WeddingFrame2: CutFrame(R.drawable.maker_faire_frame, emptyList(), emptyList())

class NoneFrame: CutFrame(0, emptyList(), emptyList())
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.foke.together.domain.interactor.entity

enum class CutFrameTypeV1 {
MAKER_FAIRE,
FOURCUT_LIGHT,
FOURCUT_DARK;

companion object {
fun findBy(name: String): CutFrameTypeV1 {
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): CutFrameTypeV1 {
return when (ordinal) {
MAKER_FAIRE.ordinal -> MAKER_FAIRE
FOURCUT_LIGHT.ordinal -> FOURCUT_LIGHT
FOURCUT_DARK.ordinal -> FOURCUT_DARK
else -> throw IllegalArgumentException("Unknown value: $ordinal")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.foke.together.domain.interactor.entity

data class PhotoPosition (
val x: Int,
val y: Int,
val height: Int,
val width: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.foke.together.domain.interactor.entity

data class SessionData (
val sessionId: SessionId? = null,
val cutFrame: CutFrame,
val status: Status
)

enum class Status {
INIT,
SELECT_FRAME,
CAPTURE,
GENERATE_PHOTO,
SHARE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.foke.together.domain.interactor.entity

data class SessionId (
val startAt: Long
) {
override fun toString(): String {
return startAt.toString()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.foke.together.domain.interactor.session

import com.foke.together.domain.output.SessionRepositoryInterface
import javax.inject.Inject

class ClearSessionUseCase @Inject constructor(
private val sessionRepository: SessionRepositoryInterface
) {
operator fun invoke() {
sessionRepository.clearSession()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.foke.together.domain.interactor.session

import com.foke.together.domain.output.SessionRepositoryInterface
import javax.inject.Inject

class CreateNewSessionUseCase @Inject constructor(
private val sessionRepository: SessionRepositoryInterface
) {
operator fun invoke() {
sessionRepository.createSession()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.foke.together.domain.interactor.session

import com.foke.together.domain.interactor.entity.SessionData
import com.foke.together.domain.output.SessionRepositoryInterface
import javax.inject.Inject

class GetCurrentSessionUseCase @Inject constructor(
private val sessionRepository: SessionRepositoryInterface
) {
operator fun invoke(): SessionData? {
return sessionRepository.getSession()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.foke.together.domain.interactor.session

import com.foke.together.domain.interactor.entity.CutFrame
import com.foke.together.domain.interactor.entity.Status
import com.foke.together.domain.output.SessionRepositoryInterface
import javax.inject.Inject

class UpdateSessionStatusUseCase @Inject constructor(
private val sessionRepository: SessionRepositoryInterface
) {
operator fun invoke(status: Status) {
sessionRepository.updateSession(status)
}

operator fun invoke(cutFrame: CutFrame) {
sessionRepository.updateSession(cutFrame)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ 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
import com.foke.together.domain.interactor.entity.CutFrameTypeV1

interface ImageRepositoryInterface {
fun getCutFrameType(): CutFrameType
fun getCutFrameType(): CutFrameTypeV1
suspend fun setCutFrameType(type: Int)
// 촬영한 사진들 모음
suspend fun cachingImage(image: Bitmap, fileName: String) : Uri
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package com.foke.together.domain.output

import com.foke.together.domain.interactor.entity.CutFrame
import com.foke.together.domain.interactor.entity.SessionData
import com.foke.together.domain.interactor.entity.Status

interface SessionRepositoryInterface {
suspend fun setSessionKey()
fun getSessionKey(): String
fun createSession()

fun getSession(): SessionData?

fun updateSession(cutFrame: CutFrame)
fun updateSession(status: Status)
fun updateSession(cutFrame: CutFrame, status: Status)

fun clearSession()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ 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.interactor.entity.CutFrameTypeV1
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
private var cutFrameType: CutFrameTypeV1 = CutFrameTypeV1.MAKER_FAIRE

override fun getCutFrameType(): CutFrameType = cutFrameType
override fun getCutFrameType(): CutFrameTypeV1 = cutFrameType
override suspend fun setCutFrameType(type: Int) {
cutFrameType = CutFrameType.findBy(type)
cutFrameType = CutFrameTypeV1.findBy(type)
}

override suspend fun cachingImage(image: Bitmap, fileName: String): Uri {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
package com.foke.together.external.repository

import com.foke.together.domain.interactor.entity.CutFrame
import com.foke.together.domain.interactor.entity.NoneFrame
import com.foke.together.domain.interactor.entity.SessionData
import com.foke.together.domain.interactor.entity.SessionId
import com.foke.together.domain.interactor.entity.Status
import com.foke.together.domain.output.SessionRepositoryInterface
import com.foke.together.util.AppLog
import com.foke.together.util.TimeUtil
import javax.inject.Inject

class SessionRepository @Inject constructor(): SessionRepositoryInterface {
private var sessionKey: String = ""
override suspend fun setSessionKey() {
sessionKey = TimeUtil.getCurrentTimeSec()

private var sessionData: SessionData? = null

override fun createSession() {
sessionData = SessionData(
SessionId(startAt = TimeUtil.getCurrentTimestamp()),
cutFrame = NoneFrame(),
status = Status.INIT
)
AppLog.i(TAG, "createSession", "sessionData: $sessionData")

// TODO: save session data to Pref.
}

override fun getSession(): SessionData? {
AppLog.i(TAG, "getSession", "sessionData: $sessionData")

return sessionData
// TODO: read session data to Pref.
}

override fun updateSession(cutFrame: CutFrame) {
sessionData = sessionData?.let {
SessionData(it.sessionId, cutFrame, it.status)
}
AppLog.i(TAG, "updateSession", "sessionData: $sessionData")

// TODO: save session data to Pref.
}

override fun updateSession(status: Status) {
sessionData = sessionData?.let {
SessionData(it.sessionId, it.cutFrame, status)
}
AppLog.i(TAG, "updateSession", "sessionData: $sessionData")

// TODO: save session data to Pref.
}

override fun updateSession(cutFrame: CutFrame, status: Status) {
sessionData = sessionData?.let {
SessionData(it.sessionId, cutFrame, status)
}
AppLog.i(TAG, "updateSession", "sessionData: $sessionData")

// TODO: save session data to Pref.
}

override fun clearSession() {
sessionData = null
AppLog.i(TAG, "clearSession", "sessionData: $sessionData")

// TODO: clear session data to Pref.
}

override fun getSessionKey(): String {
return sessionKey
companion object {
private val TAG = SessionRepository::class.java.simpleName
}
}
Loading

0 comments on commit e182e78

Please sign in to comment.