Skip to content

Commit

Permalink
feat: shaping for api
Browse files Browse the repository at this point in the history
  • Loading branch information
triandamai committed Jun 20, 2023
1 parent 0e1c86b commit 93ab71e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 7 additions & 6 deletions ui/src/main/java/app/trian/mvi/ui/PageWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ inline fun <reified ViewModel : MviViewModel<*, *>> NavGraphBuilder.pageWrapper(
deepLinks = deepLinks
) {
val viewModel: ViewModel = (if (parent.isNullOrEmpty()) {
hiltViewModel()
hiltViewModel<ViewModel>().apply {
setController(controller)
}
} else {
val parentEntry = remember(controller.navigator.currentBackStackEntry) {
controller
.navigator
.getBackStackEntry(parent)
}
hiltViewModel(parentEntry)
})

LaunchedEffect(key1 = viewModel, block = {
viewModel.setController(controller)
hiltViewModel<ViewModel>(parentEntry).apply {
setController(controller)
}
})
content(viewModel)
}
}

13 changes: 11 additions & 2 deletions ui/src/main/java/app/trian/mvi/ui/viewModel/MviViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ abstract class MviViewModel<State : Parcelable, Action>(
when (it) {
is ResultState.Error -> error(
it.message.ifEmpty {
controller.getString(it.stringId)
try {
controller.getString(it.stringId)
}catch (e:Exception){
"Unknown error message"
}

}
)

Expand All @@ -111,7 +116,11 @@ abstract class MviViewModel<State : Parcelable, Action>(
when (it) {
is ResultStateData.Error -> error(
it.message.ifEmpty {
controller.getString(it.stringId)
try {
controller.getString(it.stringId)
}catch (e:Exception){
"Unknown error message"
}
}
)

Expand Down

0 comments on commit 93ab71e

Please sign in to comment.