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

feat : 그룹페이지 구현 및 QR페이지 연결 #58

Merged
merged 1 commit into from
Nov 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
53 changes: 3 additions & 50 deletions app/src/main/java/com/example/mhnfe/data/model/CCTV.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ data class CCTV(
val id: String,
val name: String,
)

//아무것도 없는거 테스트 할때
val emptyCCTVList = emptyList<CCTV>()

//CCTV 예시 데이터
val sampleCCTVList = listOf(
CCTV(
id = "1",
Expand All @@ -20,53 +23,3 @@ val sampleCCTVList = listOf(
name = "방1"
)
)
//원래는 도메인 모델에 넣어야함
enum class UserType {
MASTER,
VIEWER,
CCTV;

companion object {
fun fromString(type: String?): UserType {
return when (type?.lowercase()) {
"master" -> MASTER
"viewer" -> VIEWER
"cctv" -> CCTV
else -> VIEWER
}
}
}
}

enum class QRGenerateType {
CCTV,
VIEWER;

companion object {
fun fromString(type: String?): QRGenerateType {
return when (type?.lowercase()) {
"cctv" -> CCTV
"viewer" -> VIEWER
else -> CCTV // 기본값
}
}

fun fromUserType(userType: UserType): QRGenerateType {
return when (userType) {
UserType.CCTV -> CCTV
UserType.VIEWER -> VIEWER
else -> throw IllegalArgumentException("Invalid type for QR generation")
}
}
}

fun toTitle(): String = when (this) {
CCTV -> "CCTV 등록"
VIEWER -> "뷰어 등록"
}

fun toMessage(): String = when (this) {
CCTV -> "CCTV로 사용할 기기에서\nQR 인증을 해주세요"
VIEWER -> "뷰어로 사용할 기기에서\nQR 인증을 해주세요"
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/example/mhnfe/di/UserType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.mhnfe.di

enum class UserType {
MASTER,
VIEWER,
CCTV;

companion object {
fun fromString(type: String?): UserType {
return when (type?.lowercase()) {
"master" -> MASTER
"viewer" -> VIEWER
"cctv" -> CCTV
else -> VIEWER
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,22 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.mhnfe.R
import com.example.mhnfe.data.model.UserType
import com.example.mhnfe.ui.navigation.NavRoutes
//import com.example.mhnfe.ui.screens.master.GroupScreen
//import com.example.mhnfe.ui.screens.master.HomeScreen
//import com.example.mhnfe.ui.screens.mypage.MyPageScreen
//import com.example.mhnfe.ui.screens.report.ReportScreen
import com.example.mhnfe.ui.theme.Typography
import com.example.mhnfe.ui.theme.hoverYellow
import com.example.mhnfe.ui.theme.mainBlack
Expand Down
65 changes: 44 additions & 21 deletions app/src/main/java/com/example/mhnfe/ui/navigation/AppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.NavType
Expand All @@ -21,12 +19,12 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import androidx.navigation.navigation
import com.amazonaws.mobile.client.AWSMobileClient
import com.example.mhnfe.data.model.UserType
import com.example.mhnfe.di.UserType
import com.example.mhnfe.ui.bottombar.BottomNavigationBar
import com.example.mhnfe.ui.screens.auth.SelectScreen
import com.example.mhnfe.ui.screens.auth.StartUpScreen
import com.example.mhnfe.ui.screens.master.MasterMainScreen
import com.example.mhnfe.ui.screens.master.QRViewModel
import com.example.mhnfe.ui.screens.monitoring.GroupScreen
import com.example.mhnfe.ui.screens.qr.QRGenerateScreen
import com.example.mhnfe.ui.screens.qr.QRViewModel

sealed class NavRoutes(val route: String) {
object Auth : NavRoutes("auth") {
Expand All @@ -40,10 +38,12 @@ sealed class NavRoutes(val route: String) {
}

object Monitoring : NavRoutes("monitoring") {
object Group : NavRoutes("group")
object Group : NavRoutes("monitoring/group")
object DeviceInformation : NavRoutes("device_information")
object QRScanner : NavRoutes("qr_scanner")
object QRGenerate : NavRoutes("qr_generate")
object QRGenerate : NavRoutes("qr_generate/{userType}") { // monitoring/ 접두어 제거
fun createRoute(userType: UserType) = "qr_generate/${userType.name.lowercase()}"
}
}
object Report : NavRoutes("report") {
object ReportDetail : NavRoutes("report_detail")
Expand Down Expand Up @@ -96,7 +96,7 @@ fun AppNavigation() {
) { backStackEntry ->
val userType = UserType.fromString(backStackEntry.arguments?.getString("userType"))
MainContent(
navController = navController,
mainNavController = navController,
auth = auth,
userType = userType
)
Expand All @@ -116,7 +116,7 @@ fun AppNavigation() {

@Composable
fun MainContent(
navController: NavController,
mainNavController: NavController,
auth: AWSMobileClient,
userType: UserType
) {
Expand All @@ -132,12 +132,6 @@ fun MainContent(

val showBottomBar = currentRoute in mainScreens

// LaunchedEffect(Unit) {
// bottomNavController.navigate(NavRoutes.Monitoring.Group.route) {
// popUpTo(0) { inclusive = true }
// }
// }

Scaffold(
bottomBar = {
if (showBottomBar) {
Expand All @@ -146,27 +140,56 @@ fun MainContent(
}
) { innerPadding ->
NavHost(
navController = bottomNavController,
navController = bottomNavController, // 여기서는 bottomNavController 사용
startDestination = NavRoutes.Monitoring.route,
modifier = Modifier.padding(innerPadding)
) {
// QR Generate 화면을 별도의 navigation block 밖으로 이동
composable(
route = NavRoutes.Monitoring.QRGenerate.route,
arguments = listOf(
navArgument("userType") {
type = NavType.StringType
}
)
) { backStackEntry ->
val qrUserType = backStackEntry.arguments?.getString("userType")
QRGenerateScreen(
navController = bottomNavController, // bottomNavController 사용
userType = UserType.fromString(qrUserType)
)
}

// Monitoring Graph
navigation(
startDestination = NavRoutes.Monitoring.Group.route,
route = NavRoutes.Monitoring.route
) {
composable(NavRoutes.Monitoring.Group.route) {
TestContent()
// GroupScreen
GroupScreen(
userType = userType,
navController = bottomNavController // bottomNavController 전달
)
}
composable(NavRoutes.Monitoring.DeviceInformation.route) {
// DeviceInformationScreen
}
composable(NavRoutes.Monitoring.QRScanner.route) {
// QRScannerScreen
}
composable(NavRoutes.Monitoring.QRGenerate.route) {
// QRGenerateScreen
composable(
route = NavRoutes.Monitoring.QRGenerate.route,
arguments = listOf(
navArgument("userType") {
type = NavType.StringType
}
)
) { backStackEntry ->
val qrUserType = backStackEntry.arguments?.getString("userType")
QRGenerateScreen(
navController = bottomNavController,
userType = UserType.fromString(qrUserType)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.amazonaws.mobile.client.results.SignInState
import com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException
import com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException
import com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException
import com.example.mhnfe.data.model.UserType
import com.example.mhnfe.di.UserType
import com.example.mhnfe.ui.navigation.NavRoutes
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.mhnfe.ui.screens.qr.QRViewModel

@Composable
fun MasterMainScreen(
Expand Down

This file was deleted.

Loading