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 all 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,7 @@
package com.foke.together.domain.input

import com.foke.together.domain.interactor.entity.ExternalCameraIP

interface SetExternalCameraIPInterface {
suspend operator fun invoke(externalCameraIP: 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 operator fun invoke(): Flow<ExternalCameraIP> =
appPreference.getExternalCameraIP().map { it }
}


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


import com.foke.together.domain.input.SetExternalCameraIPInterface
import com.foke.together.domain.interactor.entity.ExternalCameraIP
import com.foke.together.domain.output.AppPreferenceInterface
import javax.inject.Inject

class SetExternalCameraIPUseCase @Inject constructor(
private val appPreference: AppPreferenceInterface
): SetExternalCameraIPInterface {
override suspend operator fun invoke(externalCameraIP: ExternalCameraIP)=
appPreference.setExternalCameraIP(externalCameraIP)
}


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"
}