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 UseCases for external camera [#58] #64

Merged
merged 1 commit into from
Oct 8, 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
@@ -0,0 +1,31 @@
package com.foke.together.domain.interactor

import com.foke.together.domain.output.ExternalCameraRepositoryInterface
import com.foke.together.util.AppLog
import javax.inject.Inject

class CaptureWithExternalCameraUseCase @Inject constructor(
private val externalCameraRepository: ExternalCameraRepositoryInterface
) {
suspend operator fun invoke(): Result<Unit> {
externalCameraRepository.capture()
.onSuccess {
// TODO: save Bitmap to internal storage
AppLog.i(TAG, "capture", "success: $it")

// TODO: implement file save code here ...

return Result.success(Unit)
}
.onFailure {
// TODO: handle network error
AppLog.i(TAG, "capture", "failure: $it")
return Result.failure(it)
}
return Result.failure(Exception("Unknown error"))
}

companion object {
private val TAG = CaptureWithExternalCameraUseCase::class.java.simpleName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.foke.together.domain.interactor

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

class GetExternalCameraPreviewUrlUseCase @Inject constructor(
private val externalCameraRepository: ExternalCameraRepositoryInterface
) {
operator fun invoke() = externalCameraRepository.getPreviewUrl()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.foke.together.domain.interactor

import com.foke.together.domain.output.AppPreferenceInterface
import com.foke.together.domain.output.ExternalCameraRepositoryInterface
import kotlinx.coroutines.flow.firstOrNull
import javax.inject.Inject

class InitExternalCameraIPUseCase @Inject constructor(
private val appPreference: AppPreferenceInterface,
private val externalCameraRepository: ExternalCameraRepositoryInterface
) {
suspend operator fun invoke() {
appPreference.getExternalCameraIP().firstOrNull()?.let { externalCameraIP ->
externalCameraRepository.setCameraSourceUrl(externalCameraIP.address)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.foke.together.domain.interactor

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

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


externalCameraRepository.setCameraSourceUrl(externalCameraIP.address)
}
}