generated from ajou4095/template-android
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] RegistrationNavGraph & RegistrationDestination 만들기 (#14)
* [Feat]: RegistrationConstant 생성, NavGraph 기능 구현 * [Feat]: RegistrationViewModel 생성 * [Feat]: registrationNamingDestination 생성, Constant 작성 * [Feat]: registrationNaming UI 구현 * [Feat]: registrationNaming Model & State 생성 * [Feat]: registrationNaming Intent & Event 기능 구현 * [Feat]: RegistrationNamingScreen Sample Flow 구현 * [Feat]: route Destination 설정과 NavGraph 추가 * [Style]: 코드 포맷 수정 * [Fix]: 잘못된 파라미터 전달 수정 * [Refactor]: RegistrationNaming Intent & Event 재생성 * [Feat]: RegistrationCollecting Destination 생성, Constant 작성 * [Feat]: RegistrationCollecting Intent & Event 기능 구현 * [Feat]: RegistrationCollecting Model & State 생성 * [Feat]: RegistrationCollecting UI 기능 구현 * [Feat]: RegistrationCollecting NavGraph 연결 * [Style]: 코드 포맷 수정 * [Fix]: Preview 추가 & naming 수정 * [Fix] QA 후 수정
- Loading branch information
Showing
20 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...tlin/ac/dnd/bookkeeping/android/presentation/ui/main/registration/RegistrationConstant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration | ||
|
||
object RegistrationConstant { | ||
const val ROUTE = "/registration" | ||
} |
20 changes: 20 additions & 0 deletions
20
...tlin/ac/dnd/bookkeeping/android/presentation/ui/main/registration/RegistrationNavGraph.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration | ||
|
||
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting.registrationCollectingDestination | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming.RegistrationNamingConstant | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming.registrationNamingDestination | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.navigation | ||
|
||
fun NavGraphBuilder.registrationNavGraph( | ||
appState: ApplicationState | ||
) { | ||
navigation( | ||
startDestination = RegistrationNamingConstant.ROUTE, | ||
route = RegistrationConstant.ROUTE | ||
) { | ||
registrationNamingDestination(appState) | ||
registrationCollectingDestination(appState) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...lin/ac/dnd/bookkeeping/android/presentation/ui/main/registration/RegistrationViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration | ||
|
||
import ac.dnd.bookkeeping.android.presentation.common.base.BaseViewModel | ||
import androidx.lifecycle.SavedStateHandle | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class RegistrationViewModel @Inject constructor( | ||
private val savedStateHandle: SavedStateHandle | ||
): BaseViewModel() |
7 changes: 7 additions & 0 deletions
7
...ng/android/presentation/ui/main/registration/collecting/RegistrationCollectingConstant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationConstant | ||
|
||
object RegistrationCollectingConstant { | ||
const val ROUTE: String = "${RegistrationConstant.ROUTE}/collecting" | ||
} |
42 changes: 42 additions & 0 deletions
42
...android/presentation/ui/main/registration/collecting/RegistrationCollectingDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
import ac.dnd.bookkeeping.android.presentation.common.util.ErrorObserver | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationConstant | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationViewModel | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
|
||
fun NavGraphBuilder.registrationCollectingDestination( | ||
appState: ApplicationState | ||
) { | ||
composable( | ||
route = RegistrationCollectingConstant.ROUTE | ||
) { backStackEntry -> | ||
|
||
val parentEntry = remember(backStackEntry) { | ||
appState.navController.getBackStackEntry(RegistrationConstant.ROUTE) | ||
} | ||
val parentViewModel: RegistrationViewModel = hiltViewModel(parentEntry) | ||
val viewModel: RegistrationCollectingViewModel = hiltViewModel() | ||
|
||
val model: RegistrationCollectingModel = let { | ||
val state by viewModel.state.collectAsStateWithLifecycle() | ||
RegistrationCollectingModel(state = state) | ||
} | ||
|
||
ErrorObserver(viewModel) | ||
|
||
RegistrationCollectingScreen( | ||
appState = appState, | ||
model = model, | ||
event = viewModel.event, | ||
intent = viewModel::onIntent, | ||
handler = viewModel.handler | ||
) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...eping/android/presentation/ui/main/registration/collecting/RegistrationCollectingEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
sealed interface RegistrationCollectingEvent { | ||
data object GoToNextStep : RegistrationCollectingEvent | ||
} |
5 changes: 5 additions & 0 deletions
5
...ping/android/presentation/ui/main/registration/collecting/RegistrationCollectingIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
sealed interface RegistrationCollectingIntent { | ||
data object OnClickSubmit : RegistrationCollectingIntent | ||
} |
5 changes: 5 additions & 0 deletions
5
...eping/android/presentation/ui/main/registration/collecting/RegistrationCollectingModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
data class RegistrationCollectingModel( | ||
val state: RegistrationCollectingState, | ||
) |
90 changes: 90 additions & 0 deletions
90
...ping/android/presentation/ui/main/registration/collecting/RegistrationCollectingScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
import ac.dnd.bookkeeping.android.presentation.common.util.LaunchedEffectWithLifecycle | ||
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.EventFlow | ||
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.MutableEventFlow | ||
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.eventObserve | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.rememberApplicationState | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Surface | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
|
||
@Composable | ||
fun RegistrationCollectingScreen( | ||
appState: ApplicationState, | ||
model: RegistrationCollectingModel, | ||
event: EventFlow<RegistrationCollectingEvent>, | ||
intent: (RegistrationCollectingIntent) -> Unit, | ||
handler: CoroutineExceptionHandler | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(color = Color.Black), | ||
) { | ||
Text( | ||
text = "Collecting Screen", | ||
fontSize = 20.sp, | ||
color = Color.White, | ||
modifier = Modifier.align(Alignment.Center) | ||
) | ||
|
||
Surface( | ||
modifier = Modifier | ||
.align(Alignment.BottomCenter) | ||
.padding(30.dp) | ||
.fillMaxWidth() | ||
.clickable { | ||
intent(RegistrationCollectingIntent.OnClickSubmit) | ||
}, | ||
shape = RoundedCornerShape(10.dp), | ||
color = Color.White | ||
) { | ||
Text( | ||
text = "next", | ||
fontSize = 20.sp, | ||
color = Color.Black, | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.padding(5.dp) | ||
) | ||
} | ||
} | ||
|
||
LaunchedEffectWithLifecycle(event, handler) { | ||
event.eventObserve { event -> | ||
when (event) { | ||
is RegistrationCollectingEvent.GoToNextStep -> {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun RegistrationCollectingScreenPreview() { | ||
RegistrationCollectingScreen( | ||
appState = rememberApplicationState(), | ||
model = RegistrationCollectingModel( | ||
state = RegistrationCollectingState.Init | ||
), | ||
event = MutableEventFlow(), | ||
intent = {}, | ||
handler = CoroutineExceptionHandler { _, _ -> } | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
...eping/android/presentation/ui/main/registration/collecting/RegistrationCollectingState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
sealed interface RegistrationCollectingState { | ||
data object Init : RegistrationCollectingState | ||
} |
37 changes: 37 additions & 0 deletions
37
...g/android/presentation/ui/main/registration/collecting/RegistrationCollectingViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.collecting | ||
|
||
import ac.dnd.bookkeeping.android.presentation.common.base.BaseViewModel | ||
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.EventFlow | ||
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.MutableEventFlow | ||
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.asEventFlow | ||
import androidx.lifecycle.SavedStateHandle | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class RegistrationCollectingViewModel @Inject constructor( | ||
private val savedStateHandle: SavedStateHandle, | ||
) : BaseViewModel() { | ||
|
||
private val _state: MutableStateFlow<RegistrationCollectingState> = | ||
MutableStateFlow(RegistrationCollectingState.Init) | ||
val state: StateFlow<RegistrationCollectingState> = _state.asStateFlow() | ||
|
||
private val _event: MutableEventFlow<RegistrationCollectingEvent> = MutableEventFlow() | ||
val event: EventFlow<RegistrationCollectingEvent> = _event.asEventFlow() | ||
|
||
fun onIntent(intent: RegistrationCollectingIntent) { | ||
when (intent) { | ||
RegistrationCollectingIntent.OnClickSubmit -> goToNextStep() | ||
} | ||
} | ||
|
||
private fun goToNextStep() { | ||
launch { | ||
_event.emit(RegistrationCollectingEvent.GoToNextStep) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ookkeeping/android/presentation/ui/main/registration/naming/RegistrationNamingConstant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming | ||
|
||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationConstant | ||
|
||
object RegistrationNamingConstant { | ||
const val ROUTE: String = "${RegistrationConstant.ROUTE}/naming" | ||
} |
41 changes: 41 additions & 0 deletions
41
...keeping/android/presentation/ui/main/registration/naming/RegistrationNamingDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming | ||
|
||
import ac.dnd.bookkeeping.android.presentation.common.util.ErrorObserver | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationConstant | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationViewModel | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
|
||
fun NavGraphBuilder.registrationNamingDestination( | ||
appState: ApplicationState | ||
) { | ||
composable( | ||
route = RegistrationNamingConstant.ROUTE | ||
) { backStackEntry -> | ||
val parentEntry = remember(backStackEntry) { | ||
appState.navController.getBackStackEntry(RegistrationConstant.ROUTE) | ||
} | ||
val parentViewModel: RegistrationViewModel = hiltViewModel(parentEntry) | ||
val viewModel: RegistrationNamingViewModel = hiltViewModel() | ||
|
||
val model: RegistrationNamingModel = let { | ||
val state by viewModel.state.collectAsStateWithLifecycle() | ||
RegistrationNamingModel(state = state) | ||
} | ||
|
||
ErrorObserver(viewModel) | ||
|
||
RegistrationNamingScreen( | ||
appState = appState, | ||
model = model, | ||
event = viewModel.event, | ||
intent = viewModel::onIntent, | ||
handler = viewModel.handler | ||
) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...d/bookkeeping/android/presentation/ui/main/registration/naming/RegistrationNamingEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming | ||
|
||
sealed interface RegistrationNamingEvent { | ||
data object GoToNextStep : RegistrationNamingEvent | ||
} |
5 changes: 5 additions & 0 deletions
5
.../bookkeeping/android/presentation/ui/main/registration/naming/RegistrationNamingIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming | ||
|
||
sealed interface RegistrationNamingIntent { | ||
data object OnClickSubmit : RegistrationNamingIntent | ||
} |
5 changes: 5 additions & 0 deletions
5
...d/bookkeeping/android/presentation/ui/main/registration/naming/RegistrationNamingModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.naming | ||
|
||
data class RegistrationNamingModel( | ||
val state: RegistrationNamingState, | ||
) |
Oops, something went wrong.