Skip to content

Commit

Permalink
[feat/#76] camera preview 추가 + dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnseo committed Feb 5, 2024
1 parent 052db4e commit 397ef26
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>

<application
android:name=".KusitmsApp"
Expand Down
22 changes: 22 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ lottie-compose = "5.2.0"
#timber
timber = "5.0.1"

#camerax
camerax = "1.2.1"

#mlkit
mlkit = "17.2.0"

#retrofit2
okhttp3 = "4.10.0"
interceptor = "4.9.0"
Expand All @@ -67,6 +73,15 @@ junit = { group = "junit", name = "junit", version.ref = "junit" }
# timber
timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timber" }

# camera
camera2 = { group= "androidx.camera", name="camera-camera2", version.ref="camerax"}
camera2-lifecycle = { group= "androidx.camera", name="camera-lifecycle", version.ref="camerax"}
camera2-view = { group= "androidx.camera", name="camera-view", version.ref="camerax"}

#mlkit
mlkit = {group = "com.google.mlkit", name="barcode-scanning", version.ref="mlkit"}


# coroutines
coroutine = {group = "org.jetbrains.kotlinx", name="kotlinx-coroutines-android", version.ref="coroutines"}
# compose
Expand Down Expand Up @@ -136,6 +151,13 @@ coil = [
"coil-svg"
]

camerax=[
"camera2",
"camera2-lifecycle",
"camera2-view",
"mlkit"
]

lifecycle = [
"lifecycle-runtime",
"lifecycle-viewmodel"
Expand Down
3 changes: 3 additions & 0 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ dependencies {
implementation(libs.hilt)
kapt(libs.hilt.compile)

//camera2
implementation(libs.bundles.camerax)

implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation "io.coil-kt:coil-compose:2.1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kusitms.presentation.ui.home.attend

import androidx.compose.runtime.Composable

@Composable
fun AttendSnackBar() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.kusitms.presentation.ui.home.attend.camera

import android.util.Log
import android.view.ViewGroup
import androidx.camera.core.CameraSelector
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.view.PreviewView
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.ContextCompat

@Composable
fun CameraPreview() {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

AndroidView(factory = { context ->
PreviewView(context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
implementationMode = PreviewView.ImplementationMode.COMPATIBLE
}
}, update = { previewView ->
val cameraProviderFuture = ProcessCameraProvider.getInstance(context)
cameraProviderFuture.addListener({
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
val preview = Preview.Builder().build().also {
it.setSurfaceProvider(previewView.surfaceProvider)
}
try {
cameraProvider.unbindAll()
cameraProvider.bindToLifecycle(lifecycleOwner, CameraSelector.DEFAULT_BACK_CAMERA, preview)
} catch (e: Exception) {
Log.e("CameraPreview", "Use case binding failed", e)
}
}, ContextCompat.getMainExecutor(context))
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.kusitms.domain.model.home.AttendCurrentModel
import com.kusitms.presentation.common.ui.KusitmsMarginHorizontalSpacer
import com.kusitms.presentation.common.ui.KusitmsMarginVerticalSpacer
import com.kusitms.presentation.common.ui.theme.KusitmsColorPalette
import com.kusitms.presentation.common.ui.theme.KusitmsTypo
import com.kusitms.presentation.model.home.attend.AttendViewModel
Expand All @@ -34,6 +35,7 @@ fun CurriItem(
CurriTitleRow(model = model)
CurriBadge(model = model)
}
KusitmsMarginVerticalSpacer(size = 24)
}

@Composable
Expand Down

0 comments on commit 397ef26

Please sign in to comment.