Skip to content

Commit

Permalink
[feat/#76] usecase(attend) cnrk
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnseo committed Feb 5, 2024
1 parent 397ef26 commit 893ae81
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.kusitms.data.repository

import android.os.Build.VERSION_CODES.P
import com.kusitms.data.remote.api.KusitmsApi
import com.kusitms.data.remote.entity.response.home.toModel
import com.kusitms.domain.model.home.CurriculumRecentModel
import com.kusitms.domain.model.home.HomeProfileModel
import com.kusitms.domain.model.home.MemberInfoDetailModel
import com.kusitms.domain.model.home.NoticeRecentModel
import com.kusitms.domain.model.home.TeamMatchingModel
import com.kusitms.domain.model.home.*
import com.kusitms.domain.model.profile.ProfileModel
import com.kusitms.domain.repository.HomeRepository
import javax.inject.Inject

class HomeRepositoryImpl @Inject constructor(
private val kusitmsApi: KusitmsApi,
) : HomeRepository {


override suspend fun getMemberInfoHome(): Result<HomeProfileModel> {
return try {
val response = kusitmsApi.getMemberInfoHome()
Expand Down Expand Up @@ -99,4 +94,31 @@ class HomeRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun getAttendCurrentList(): Result<List<AttendCurrentModel>> {
return try {
val response = kusitmsApi.getAttendCurrentList()

if(response.result.code == 200) {
Result.success(response.payload.map {it.toModel()})
} else {
Result.failure(RuntimeException("출석 리스트 조회 실패: ${response.result.message}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}

override suspend fun getAttendInfo(): Result<AttendInfoModel> {
return try {
val response = kusitmsApi.getAttendInfo()
if(response.result.code == 200) {
Result.success(response.payload.toModel())
} else {
Result.failure(RuntimeException("출석 리스트 조회 실패: ${response.result.message}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ interface HomeRepository {
teamId: Int
): Result<List<ProfileModel>>
suspend fun getAttendCurrentList(): Result<List<AttendCurrentModel>>
suspend fun getAttendInfo(): Result<AttendInfoModel>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kusitms.domain.usecase.home

import com.kusitms.domain.model.home.AttendInfoModel
import com.kusitms.domain.repository.HomeRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class GetAttendInfoUseCase @Inject constructor(
private val homeRepository: HomeRepository
) {
operator fun invoke(): Flow<AttendInfoModel> = flow {
homeRepository.getAttendInfo()
.onSuccess {
emit(it)
}.onFailure {
throw it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.kusitms.presentation.model.signIn.SignInViewModel
import com.kusitms.presentation.model.signIn.SplashViewModel
import com.kusitms.presentation.ui.home.HomeScreen
import com.kusitms.presentation.ui.home.attend.AttendScreen
import com.kusitms.presentation.ui.home.attend.camera.CameraPreview
import com.kusitms.presentation.ui.home.profile.MyProfileScreen
import com.kusitms.presentation.ui.home.team.HomeTeamDetailScreen
import com.kusitms.presentation.ui.login.LoginScreen
Expand Down Expand Up @@ -232,7 +233,13 @@ fun MainNavigation() {
}

kusitmsComposableWithAnimation(NavRoutes.AttendanceScreen.route) {
AttendScreen()
AttendScreen(
navController
)
}

kusitmsComposableWithAnimation(NavRoutes.CameraPreview.route) {
CameraPreview()
}

//HomeScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ sealed class NavRoutes(

object AttendanceScreen: NavRoutes("Attendance")

object CameraPreview: NavRoutes("CameraPreview")


object SettingMember : NavRoutes("SettingMember")
object SettingNonMember : NavRoutes("SettingNonMember")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.kusitms.presentation.R
import com.kusitms.presentation.common.ui.theme.KusitmsColorPalette
import com.kusitms.presentation.common.ui.theme.KusitmsTypo
import com.kusitms.presentation.navigation.NavRoutes

@Composable
fun AttendBtnOn() {
fun AttendBtnOn(navController: NavHostController) {
Button(
modifier = Modifier
.wrapContentWidth()
.height(64.dp) ,
colors = ButtonDefaults.buttonColors(containerColor = KusitmsColorPalette.current.Main600) ,
shape = RoundedCornerShape(size = 12.dp),
onClick = { /*TODO*/ }
onClick = { navController.navigate(NavRoutes.CameraPreview.route) }
) {
Text(text = stringResource(R.string.attend_btn_attend), style = KusitmsTypo.current.Text_Semibold, color = KusitmsColorPalette.current.White, maxLines = 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role.Companion.Image
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.kusitms.presentation.common.ui.KusitmsMarginVerticalSpacer
import com.kusitms.presentation.common.ui.theme.KusitmsColorPalette
import com.kusitms.presentation.R
Expand All @@ -30,9 +31,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@Preview
@Composable
fun AttendScreen(
viewModel: AttendViewModel,
navController: NavHostController
) {
val scrollState = rememberScrollState()
Box(
Expand All @@ -51,12 +53,14 @@ fun AttendScreen(
) {
AttendTopBar()
KusitmsMarginVerticalSpacer(size = 8)
AttendPreColumn()
AttendPreColumn(navController)
KusitmsMarginVerticalSpacer(size = 24)
AttendRecordColumn()
KusitmsMarginVerticalSpacer(size = 32)
AttendNotAttend()
Spacer(modifier = Modifier.weight(1f).background(color = KusitmsColorPalette.current.Grey800))
Spacer(modifier = Modifier
.weight(1f)
.background(color = KusitmsColorPalette.current.Grey800))
}
}
ScrollBtn(scrollState = scrollState)
Expand All @@ -81,7 +85,7 @@ fun AttendTopBar() {
}

@Composable
fun AttendPreColumn() {
fun AttendPreColumn(navController: NavHostController) {
Box(modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp)
Expand All @@ -105,7 +109,7 @@ fun AttendPreColumn() {
KusitmsMarginVerticalSpacer(size = 4)
Text(text = stringResource(R.string.attend_box1_subTitle), style = KusitmsTypo.current.SubTitle1_Semibold, color = KusitmsColorPalette.current.White)
}
AttendBtnOff()
AttendBtnOn(navController)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,77 @@
package com.kusitms.presentation.ui.home.attend.camera

import android.util.Log
import android.view.Surface
import android.view.ViewGroup
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.view.PreviewView
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode.Companion.Overlay
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.ContextCompat
import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.common.InputImage
import com.kusitms.presentation.common.ui.theme.KusitmsColorPalette

@Composable
fun CameraPreviewWithOverlay() {
Box {
CameraPreview()
Overlay()
}
}

@androidx.compose.ui.tooling.preview.Preview
@Composable
fun Overlay() {
Surface {
Box(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
Canvas(
modifier = Modifier
.align(Alignment.Center)
.size(200.dp)
) {
val strokeWidth = 4.dp.toPx()
val inset = strokeWidth / 2
drawRect(
color = Color.Black,
topLeft = this.center.copy(x = inset, y = inset),
size = Size(size.width - strokeWidth, size.height - strokeWidth),
)
drawRect(
color = Color.White,
size = this.size,
style = Stroke(width = strokeWidth)
)
}
}
}
}

@Composable
@androidx.annotation.OptIn(androidx.camera.core.ExperimentalGetImage::class)
fun CameraPreview() {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
Expand Down Expand Up @@ -40,4 +99,32 @@ fun CameraPreview() {
}
}, ContextCompat.getMainExecutor(context))
})

val imageAnalysis = ImageAnalysis.Builder()
.build()
.also {
it.setAnalyzer(ContextCompat.getMainExecutor(context)) { imageProxy ->
val mediaImage = imageProxy.image
if (mediaImage != null) {
val inputImage =
InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)
// 바코드 스캐너 인스턴스 생성
val scanner = BarcodeScanning.getClient()
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
for (barcode in barcodes) {
val rawValue = barcode.rawValue
// QR 코드 값을 사용
}
}
.addOnFailureListener {
// 처리 실패
}
.addOnCompleteListener {
imageProxy.close()
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fun SplashScreen(viewModel: SplashViewModel, navController: NavController) {

LaunchedEffect(tokenStatus) {
viewModel.verifyToken()
Log.d("tokenStatus", tokenStatus.toString())
when (tokenStatus) {
TokenStatus.VALID -> {
delay(2000)
Expand Down

0 comments on commit 893ae81

Please sign in to comment.