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] LoginNavGraph & LoginMainDestination 만들기 (#12)
- Loading branch information
Showing
14 changed files
with
243 additions
and
219 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
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
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
29 changes: 4 additions & 25 deletions
29
...on/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/LoginNavGraph.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 |
---|---|---|
@@ -1,39 +1,18 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.login | ||
|
||
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState | ||
import androidx.compose.runtime.remember | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.login.main.LoginMainConstant | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.login.main.loginMainDestination | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.navigation | ||
|
||
fun NavGraphBuilder.loginNavGraph( | ||
appState: ApplicationState | ||
) { | ||
navigation( | ||
startDestination = LoginConstant.ROUTE_STEP_1, | ||
startDestination = LoginMainConstant.ROUTE, | ||
route = LoginConstant.ROUTE | ||
) { | ||
// TODO : 분리 | ||
composable( | ||
route = LoginConstant.ROUTE_STEP_1 | ||
) { | ||
val backStackEntry = remember(it) { | ||
appState.navController.getBackStackEntry(LoginConstant.ROUTE_STEP_1) | ||
} | ||
val loginViewModel: LoginViewModel = hiltViewModel(backStackEntry) | ||
LoginScreen(appState = appState, viewModel = loginViewModel) | ||
} | ||
|
||
// TODO : 분리 | ||
composable( | ||
route = LoginConstant.ROUTE_STEP_2 | ||
) { | ||
val backStackEntry = remember(it) { | ||
appState.navController.getBackStackEntry(LoginConstant.ROUTE) | ||
} | ||
val loginViewModel: LoginViewModel = hiltViewModel(backStackEntry) | ||
OnBoardScreen(appState = appState, viewModel = loginViewModel) | ||
} | ||
loginMainDestination(appState = appState) | ||
} | ||
} |
82 changes: 0 additions & 82 deletions
82
...tion/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/LoginScreen.kt
This file was deleted.
Oops, something went wrong.
72 changes: 0 additions & 72 deletions
72
...on/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/OnBoardScreen.kt
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...in/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/main/LoginMainConstant.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.login.main | ||
|
||
import ac.dnd.bookkeeping.android.presentation.ui.main.login.LoginConstant | ||
|
||
object LoginMainConstant { | ||
const val ROUTE: String = "${LoginConstant.ROUTE}/main" | ||
} |
44 changes: 44 additions & 0 deletions
44
...kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/main/LoginMainDestination.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,44 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.login.main | ||
|
||
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.login.LoginConstant | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.login.LoginViewModel | ||
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.loginMainDestination( | ||
appState: ApplicationState | ||
) { | ||
composable( | ||
route = LoginMainConstant.ROUTE | ||
) { backStackEntry -> | ||
val parentEntry = remember(backStackEntry) { | ||
appState.navController.getBackStackEntry(LoginConstant.ROUTE) | ||
} | ||
val parentViewModel: LoginViewModel = hiltViewModel(parentEntry) | ||
val viewModel: LoginMainViewModel = hiltViewModel() | ||
|
||
val model: LoginMainModel = let { | ||
val state by viewModel.state.collectAsStateWithLifecycle() | ||
|
||
LoginMainModel( | ||
state = state | ||
) | ||
} | ||
|
||
ErrorObserver(viewModel) | ||
|
||
LoginMainScreen( | ||
appState = appState, | ||
model = model, | ||
event = viewModel.event, | ||
intent = viewModel::onIntent, | ||
handler = viewModel.handler | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/main/LoginMainEvent.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.login.main | ||
|
||
import ac.dnd.bookkeeping.android.domain.model.error.ServerException | ||
|
||
sealed interface LoginMainEvent { | ||
sealed interface Login : LoginMainEvent { | ||
data object Success : Login | ||
data class Failure(val exception: ServerException) : Login | ||
data class Error(val exception: Throwable) : Login | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/main/LoginMainIntent.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.login.main | ||
|
||
sealed interface LoginMainIntent { | ||
data object Click : LoginMainIntent | ||
} |
5 changes: 5 additions & 0 deletions
5
.../main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/main/LoginMainModel.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.login.main | ||
|
||
data class LoginMainModel( | ||
val state: LoginMainState, | ||
) |
Oops, something went wrong.