Skip to content

Commit

Permalink
Merge pull request #102 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Improvements for State and UI Management for Issuance
  • Loading branch information
stzouvaras authored May 25, 2024
2 parents 04f57f9 + 340ef95 commit f685752
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ sealed class IssueDocumentPartialState {
val crypto: BiometricCrypto,
val resultHandler: DeviceAuthenticationResult
) : IssueDocumentPartialState()

data object Start : IssueDocumentPartialState()
}

sealed class IssueDocumentsPartialState {
Expand All @@ -67,6 +69,8 @@ sealed class IssueDocumentsPartialState {
val crypto: BiometricCrypto,
val resultHandler: DeviceAuthenticationResult
) : IssueDocumentsPartialState()

data object Start : IssueDocumentsPartialState()
}

sealed class AddSampleDataPartialState {
Expand Down Expand Up @@ -211,11 +215,15 @@ class WalletCoreDocumentsControllerImpl(
)
)

is IssueDocumentsPartialState.PartialSuccess -> {
is IssueDocumentsPartialState.PartialSuccess -> emit(
IssueDocumentPartialState.Success(
response.documentIds.first()
)
}
)

is IssueDocumentsPartialState.Start -> emit(
IssueDocumentPartialState.Start
)
}
}
}
Expand Down Expand Up @@ -434,6 +442,9 @@ class WalletCoreDocumentsControllerImpl(

is IssueEvent.Started -> {
totalDocumentsToBeIssued = event.total
trySendBlocking(
IssueDocumentsPartialState.Start
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ sealed class IssueDocumentsInteractorPartialState {
val crypto: BiometricCrypto,
val resultHandler: DeviceAuthenticationResult
) : IssueDocumentsInteractorPartialState()

data object Start : IssueDocumentsInteractorPartialState()
}

interface DocumentOfferInteractor {
Expand Down Expand Up @@ -193,6 +195,8 @@ class DocumentOfferInteractorImpl(
resultHandler = response.resultHandler
)
}

is IssueDocumentsPartialState.Start -> IssueDocumentsInteractorPartialState.Start
}
}.collect {
emit(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ fun AddDocumentScreen(
)
}

LifecycleEffect(
lifecycleOwner = LocalLifecycleOwner.current,
lifecycleEvent = Lifecycle.Event.ON_PAUSE
) {
viewModel.setEvent(Event.OnPause)
}

LifecycleEffect(
lifecycleOwner = LocalLifecycleOwner.current,
lifecycleEvent = Lifecycle.Event.ON_RESUME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ data class State(
sealed class Event : ViewEvent {
data class Init(val deepLink: Uri?) : Event()
data object Pop : Event()
data object OnPause : Event()
data object Finish : Event()
data object DismissError : Event()
data class IssueDocument(
Expand All @@ -85,8 +86,7 @@ sealed class Effect : ViewSideEffect {
data object Pop : Navigation()
data object Finish : Navigation()
data class SwitchScreen(val screenRoute: String, val inclusive: Boolean) : Navigation()
data class OpenDeepLinkAction(val deepLinkUri: Uri, val arguments: String?) :
Navigation()
data class OpenDeepLinkAction(val deepLinkUri: Uri, val arguments: String?) : Navigation()
}
}

Expand All @@ -107,11 +107,10 @@ class AddDocumentViewModel(
override fun handleEvents(event: Event) {
when (event) {
is Event.Init -> {
if (viewState.value.isInitialised) {
setState { copy(isLoading = false) }
}
if (viewState.value.options.isEmpty()) {
getOptions(event, event.deepLink)
} else {
handleDeepLink(event.deepLink)
}
}

Expand All @@ -136,14 +135,21 @@ class AddDocumentViewModel(
is Event.Finish -> setEffect { Effect.Navigation.Finish }

is Event.GoToQrScan -> navigateToQrScanScreen()

is Event.OnPause -> {
if (viewState.value.isInitialised) {
setState { copy(isLoading = false) }
}
}
}
}

private fun getOptions(event: Event, deepLinkUri: Uri?) {

setState {
copy(
isLoading = true
isLoading = true,
error = null
)
}

Expand Down Expand Up @@ -186,12 +192,6 @@ class AddDocumentViewModel(
docType: String,
context: Context
) {
setState {
copy(
isLoading = true
)
}

viewModelScope.launch {
addDocumentInteractor.issueDocument(
issuanceMethod = issuanceMethod,
Expand Down Expand Up @@ -240,6 +240,13 @@ class AddDocumentViewModel(
)
)
}

is IssueDocumentPartialState.Start -> setState {
copy(
isLoading = true,
error = null
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import eu.europa.ec.uilogic.component.content.ContentTitle
import eu.europa.ec.uilogic.component.content.GradientEdge
import eu.europa.ec.uilogic.component.content.ScreenNavigateAction
import eu.europa.ec.uilogic.component.utils.LifecycleEffect
import eu.europa.ec.uilogic.component.utils.OneTimeLaunchedEffect
import eu.europa.ec.uilogic.component.utils.SPACING_EXTRA_LARGE
import eu.europa.ec.uilogic.component.utils.SPACING_MEDIUM
import eu.europa.ec.uilogic.component.utils.SPACING_SMALL
Expand Down Expand Up @@ -122,8 +123,12 @@ fun DocumentOfferScreen(

LifecycleEffect(
lifecycleOwner = LocalLifecycleOwner.current,
lifecycleEvent = Lifecycle.Event.ON_RESUME
lifecycleEvent = Lifecycle.Event.ON_PAUSE
) {
viewModel.setEvent(Event.OnPause)
}

OneTimeLaunchedEffect {
viewModel.setEvent(Event.Init)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ data class State(
sealed class Event : ViewEvent {
data object Init : Event()
data object Pop : Event()
data object OnPause : Event()
data object DismissError : Event()

data class PrimaryButtonPressed(val context: Context) : Event()
Expand Down Expand Up @@ -128,12 +129,7 @@ class DocumentOfferViewModel(
override fun handleEvents(event: Event) {
when (event) {
is Event.Init -> {
if (viewState.value.isInitialised) {
setState { copy(isLoading = false) }
}
if (viewState.value.documents.isEmpty()) {
resolveDocumentOffer(offerUri = viewState.value.offerUiConfig.offerURI)
}
resolveDocumentOffer(offerUri = viewState.value.offerUiConfig.offerURI)
}

is Event.Pop -> {
Expand Down Expand Up @@ -171,6 +167,12 @@ class DocumentOfferViewModel(
hideBottomSheet()
doNavigation(viewState.value.offerUiConfig.onCancelNavigation)
}

is Event.OnPause -> {
if (viewState.value.isInitialised) {
setState { copy(isLoading = false) }
}
}
}
}

Expand All @@ -181,7 +183,6 @@ class DocumentOfferViewModel(
error = null
)
}

viewModelScope.launch {
documentOfferInteractor.resolveDocumentOffer(
offerUri = offerUri
Expand Down Expand Up @@ -236,13 +237,6 @@ class DocumentOfferViewModel(
}

private fun issueDocuments(offerUri: String, issuerName: String, context: Context) {
setState {
copy(
isLoading = true,
error = null
)
}

viewModelScope.launch {
documentOfferInteractor.issueDocuments(
offerUri = offerUri,
Expand Down Expand Up @@ -279,6 +273,13 @@ class DocumentOfferViewModel(
resultHandler = response.resultHandler
)
}

is IssueDocumentsInteractorPartialState.Start -> setState {
copy(
isLoading = true,
error = null
)
}
}
}
}
Expand Down

0 comments on commit f685752

Please sign in to comment.