Skip to content
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

add usecase to set external camera ip [#55] #57

Merged
merged 4 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.foke.together.data.datasource.local.datastore
import androidx.datastore.core.Serializer
import com.foke.together.AppPreferences
import com.foke.together.util.AppLog
import com.foke.together.util.AppPolicy
import java.io.InputStream
import java.io.OutputStream
import javax.inject.Inject
Expand All @@ -13,7 +14,8 @@ class AppPreferencesSerializer @Inject constructor(): Serializer<AppPreferences>
// Add proto datastore default value here.
// You need to check default value of each types from link below
// https://protobuf.dev/programming-guides/proto3/
// ex> isDebugMode = true
// e.g. isDebugMode = true
externalCameraIp = AppPolicy.DEFAULT_EXTERNAL_CAMERA_IP
build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.datastore.core.DataStore
import com.foke.together.AppPreferences
import com.foke.together.CameraSource
import com.foke.together.domain.interactor.entity.CameraSourceType
import com.foke.together.domain.interactor.entity.ExternalCameraIP
import com.foke.together.domain.output.AppPreferenceInterface
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -39,6 +40,19 @@ class AppPreferencesRepository @Inject constructor(
}
}

override fun getExternalCameraIP(): Flow<ExternalCameraIP> =
appPreferencesFlow.map {
ExternalCameraIP(it.externalCameraIp)
}

override suspend fun setExternalCameraIP(ip: ExternalCameraIP) {
appPreferences.updateData {
it.toBuilder()
.setExternalCameraIp(ip.address)
.build()
}
}

Copy link
Member Author

@fetiu fetiu Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

특히 이부분 동작을 어떻게 확인해야하는지 모르겠습니다... 프로토 버프 잘 저장되려나요?ㅋㅋㅋ @DokySp

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정상동작 확인했습니다~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대신 검증해주셔서 감사합니다!

override suspend fun clearAll() {
appPreferences.updateData {
it.toBuilder().clear().build()
Expand Down
1 change: 1 addition & 0 deletions data/src/main/proto/app_preferences.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message AppPreferences {
// * Max size of field number is 536870911

CameraSource camera_source = 10;
string external_camera_ip = 11;

// TODO: sample code. remove later.
string sample_id = 999997;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.foke.together.domain.input

import com.foke.together.domain.interactor.entity.ExternalCameraIP
import kotlinx.coroutines.flow.Flow

interface GetExternalCameraIPInterface {
operator fun invoke(): Flow<ExternalCameraIP>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.foke.together.domain.interactor


import com.foke.together.domain.input.GetExternalCameraIPInterface
import com.foke.together.domain.interactor.entity.ExternalCameraIP
import com.foke.together.domain.output.AppPreferenceInterface
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class GetExternalCameraIPUseCase @Inject constructor(
private val appPreference: AppPreferenceInterface
): GetExternalCameraIPInterface {
override fun invoke(): Flow<ExternalCameraIP> =
appPreference.getExternalCameraIP().map { it }
}


Copy link
Member Author

@fetiu fetiu Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String 하나만 박아도 괜찮을까 싶긴 했지만, 다른걸 뭘 넣어야할지 아직 불확실해서 이대로 두었습니다.

예를들면 정상 String검증, Uint32타입으로의 변환, Port필드 추가 등의 아이디어는 있었지만, 현시점 구현에서 불필요할 것이라고도 생각되서요...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 일단 이대로 가는게 어떨지 싶습니다 ㅎㅎ
정상 String검증이 아마 ip 타입 형태의 string 포맷인지 아닌지 검사 여부를 의미하는 것으로 이해했는데요,
필요한 기능이긴 하나 해당 코드위치에 대한 고민이 필요할 것 같고 ExternalCameraIP.kt 를 나중에 삭제해도 되니 우선은 지금처럼 가도되지 않을까 싶습니다 ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExternalCameraIP를 지금 당장 지우고 raw String으로 바꾸는 것도 잠깐 고민했는데, 혹시 모를 확장성을 위해 남겨두도록 하겠습니다! 나중에 잘 판단해서 작업 부탁드립니다ㅎㅎ

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.foke.together.domain.interactor.entity

data class ExternalCameraIP (
val address: String,
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.foke.together.domain.output

import com.foke.together.domain.interactor.entity.CameraSourceType
import com.foke.together.domain.interactor.entity.ExternalCameraIP
import kotlinx.coroutines.flow.Flow

interface AppPreferenceInterface {
fun getCameraSourceType(): Flow<CameraSourceType>
suspend fun setCameraSourceType(type: CameraSourceType)

fun getExternalCameraIP(): Flow<ExternalCameraIP>
suspend fun setExternalCameraIP(ip: ExternalCameraIP)

suspend fun clearAll()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.foke.together.presenter.theme

// Defines commonly used or recycled values
// ex> https://github.com/android/compose-samples/blob/main/JetNews/app/src/main/java/com/example/jetnews/ui/theme/Shape.kt
// e.g. https://github.com/android/compose-samples/blob/main/JetNews/app/src/main/java/com/example/jetnews/ui/theme/Shape.kt
5 changes: 5 additions & 0 deletions util/src/main/java/com/foke/together/util/AppPolicy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.foke.together.util

object AppPolicy {
const val DEFAULT_EXTERNAL_CAMERA_IP = "0.0.0.0"
}