Skip to content

Commit

Permalink
Merge pull request #44 from meongmory/refactor/mypage
Browse files Browse the repository at this point in the history
[refactor/mypage] 마이페이지 화면 뷰모델로 리팩토링
  • Loading branch information
arinming authored Aug 14, 2023
2 parents 97894b4 + 64d0db7 commit b1580bc
Show file tree
Hide file tree
Showing 20 changed files with 876 additions and 351 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buildscript {
google()
mavenCentral()
gradlePluginPortal()
maven("https://naver.jfrog.io/artifactory/maven/")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ enum class MeongMoryRoute(val route: String) {
MAP("map"),
HOME("home"),
MY_PAGE("my-page"),
EDIT_NICKNAME("edit-nickname"),
QUESTION("question"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import com.meongmoryteam.presentation.ui.theme.GRAY100
Expand Down Expand Up @@ -48,7 +49,7 @@ fun MeongMoryBottomNavigation(
}
)
},
selected = currentDestination?.route == bottomItem.route,
selected = currentDestination?.hierarchy?.any { it.route == bottomItem.route } == true,
onClick = { navigateToScreen(bottomItem) },
colors = NavigationBarItemDefaults.colors(indicatorColor = Color.White),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package com.meongmoryteam.presentation.ui.main

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.meongmoryteam.presentation.ui.bottom.MeongMoryRoute
import com.meongmoryteam.presentation.ui.theme.MeongmoryTheme
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -29,8 +21,16 @@ class MainActivity : ComponentActivity() {
private fun setMainScreen() {
setContent {
MeongmoryTheme {
MainScreen()
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = MeongMoryRoute.HOME.route,
) {
composable(route = MeongMoryRoute.HOME.route) {
MainScreen()
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.meongmoryteam.presentation.ui.main

import com.meongmoryteam.presentation.base.ViewEvent
import com.meongmoryteam.presentation.base.ViewSideEffect
import com.meongmoryteam.presentation.base.ViewState

class MainContract {
data class MainViewState(
val loginState: LoginState = LoginState.NONE,
) : ViewState

sealed class MainSideEffect : ViewSideEffect {
}

sealed class MainEvent : ViewEvent {
}

enum class LoginState {
NONE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,85 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.meongmoryteam.presentation.ui.bottom.BottomNavigation
import com.meongmoryteam.presentation.ui.bottom.MeongMoryBottomNavigation
import com.meongmoryteam.presentation.ui.bottom.MeongMoryRoute
import com.meongmoryteam.presentation.ui.bottom.navigateBottomNavigationScreen
import com.meongmoryteam.presentation.ui.home.HomeScreen
import com.meongmoryteam.presentation.ui.map.MapScreen
import com.meongmoryteam.presentation.ui.myPage.MyPageProfileButton
import com.meongmoryteam.presentation.ui.myPage.MyPageScreen
import com.meongmoryteam.presentation.ui.myPage.profile.MypageProfileScreen
import com.meongmoryteam.presentation.ui.myPage.profile.MyPageProfileScreen
import com.meongmoryteam.presentation.ui.myPage.question.MyPageQuestionScreen

@Composable
fun MainScreen(
navController: NavHostController = rememberNavController(),
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
var bottomBarState by rememberSaveable { mutableStateOf(true) }

Scaffold(
bottomBar = {
MeongMoryBottomNavigation(
currentDestination = currentDestination,
navigateToScreen = { navigationItem ->
navigateBottomNavigationScreen(
navController = navController,
navigationItem = navigationItem,
)
}
)
if (bottomBarState) {
MeongMoryBottomNavigation(
currentDestination = currentDestination,
navigateToScreen = { navigationItem ->
navigateBottomNavigationScreen(
navController = navController,
navigationItem = navigationItem,
)
}
)
}
}
) { padding ->
NavHost(
modifier = Modifier.padding(padding),
navController = navController,
startDestination = BottomNavigation.HOME.route,
startDestination = MeongMoryRoute.HOME.route,
) {
composable(route = BottomNavigation.HOME.route) {
composable(route = MeongMoryRoute.HOME.route) {
HomeScreen()
}
composable(route = BottomNavigation.MAP.route) {
composable(route = MeongMoryRoute.MAP.route) {
MapScreen()
}
composable(route = BottomNavigation.MY_PAGE.route) {
MyPageScreen()
composable(route = MeongMoryRoute.MY_PAGE.route) {
MyPageScreen(
navigateToEditNickNameScreen = { navController.navigate(MeongMoryRoute.EDIT_NICKNAME.route) },
navigateToQuestionScreen = { navController.navigate(MeongMoryRoute.QUESTION.route) },
)
}
composable(route = MeongMoryRoute.EDIT_NICKNAME.route) {
MyPageProfileScreen(
navigateToPrevious = { navController.navigate(MeongMoryRoute.MY_PAGE.route) }
)
}
composable(route = MeongMoryRoute.QUESTION.route) {
MyPageQuestionScreen(
navigateToPrevious = { navController.navigate(MeongMoryRoute.MY_PAGE.route)}
)
}
}
}

// 바텀 네비게이션 보이기, 숨기기
bottomBarState = when (currentDestination?.route) {
MeongMoryRoute.HOME.route -> true
MeongMoryRoute.MAP.route -> true
MeongMoryRoute.MY_PAGE.route -> true
else -> false
}
}

@Preview
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.meongmoryteam.presentation.ui.main

import com.meongmoryteam.presentation.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import com.meongmoryteam.presentation.ui.main.MainContract.*

@HiltViewModel
class MainViewModel @Inject constructor(
) : BaseViewModel<MainViewState, MainSideEffect, MainEvent>(
MainViewState()
) {
override fun handleEvents(event: MainEvent) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package com.meongmoryteam.presentation.ui.map
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.meongmoryteam.presentation.ui.theme.MeongmoryTheme

@Composable
fun MapScreen(

) {
fun MapScreen() {
Text(
text = "MapScreen",
)
}

@Preview
@Preview(showBackground = true)

@Composable
fun MapScreenPreview() {
MapScreen()
MeongmoryTheme {
MapScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.meongmoryteam.presentation.ui.myPage

import com.meongmoryteam.presentation.base.LoadState
import com.meongmoryteam.presentation.base.ViewEvent
import com.meongmoryteam.presentation.base.ViewSideEffect
import com.meongmoryteam.presentation.base.ViewState

class MyPageContract {
data class MyPageViewState(
val loadState: LoadState = LoadState.SUCCESS,
val nickName: String = "",
val isDialogVisible: Boolean = false
) : ViewState

sealed class MyPageSideEffect : ViewSideEffect {
object NavigateToEditProfile : MyPageSideEffect()
object NavigateToQuestion : MyPageSideEffect()
}

sealed class MyPageEvent : ViewEvent {
object InitMyPageScreen : MyPageEvent()
object OnClickProfileEditButtonClicked : MyPageEvent()
object OnQuestionClicked : MyPageEvent()
}
}
Loading

0 comments on commit b1580bc

Please sign in to comment.