Skip to content

Commit

Permalink
Merge pull request #106 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Improved behavior with issuance resume from authorization, fixed issu…
  • Loading branch information
stzouvaras authored May 27, 2024
2 parents f685752 + 7b15968 commit cfe37be
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun RequestScreen(
ContentScreen(
navigatableAction = ScreenNavigateAction.NONE,
isLoading = state.isLoading,
onBack = { viewModel.setEvent(Event.GoBack) },
onBack = { viewModel.setEvent(Event.SecondaryButtonPressed) },
contentErrorConfig = state.error
) { paddingValues ->
Content(
Expand Down
21 changes: 21 additions & 0 deletions core-logic/src/main/java/eu/europa/ec/corelogic/util/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 European Commission
*
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European
* Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work
* except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the Licence for the specific language
* governing permissions and limitations under the Licence.
*/

package eu.europa.ec.corelogic.util

object CoreActions {
const val VCI_RESUME_ACTION = "vci.resume.eudi.action"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.navigation.NavController
import eu.europa.ec.commonfeature.model.DocumentOptionItemUi
import eu.europa.ec.corelogic.controller.IssuanceMethod
import eu.europa.ec.corelogic.model.DocumentType
import eu.europa.ec.corelogic.util.CoreActions
import eu.europa.ec.resourceslogic.R
import eu.europa.ec.resourceslogic.theme.values.allCorneredShapeSmall
import eu.europa.ec.resourceslogic.theme.values.backgroundDefault
Expand All @@ -52,6 +53,7 @@ import eu.europa.ec.uilogic.component.AppIcons
import eu.europa.ec.uilogic.component.IconData
import eu.europa.ec.uilogic.component.IssuanceButton
import eu.europa.ec.uilogic.component.IssuanceButtonData
import eu.europa.ec.uilogic.component.SystemBroadcastReceiver
import eu.europa.ec.uilogic.component.content.ContentScreen
import eu.europa.ec.uilogic.component.content.ContentTitle
import eu.europa.ec.uilogic.component.content.ScreenNavigateAction
Expand Down Expand Up @@ -129,6 +131,10 @@ fun AddDocumentScreen(
) {
viewModel.setEvent(Event.Init(context.getPendingDeepLink()))
}

SystemBroadcastReceiver(action = CoreActions.VCI_RESUME_ACTION) {
viewModel.setEvent(Event.OnResumeIssuance)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ sealed class Event : ViewEvent {
data class Init(val deepLink: Uri?) : Event()
data object Pop : Event()
data object OnPause : Event()
data object OnResumeIssuance : Event()
data object Finish : Event()
data object DismissError : Event()
data class IssueDocument(
Expand Down Expand Up @@ -141,6 +142,10 @@ class AddDocumentViewModel(
setState { copy(isLoading = false) }
}
}

is Event.OnResumeIssuance -> setState {
copy(isLoading = true)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import androidx.lifecycle.Lifecycle
import androidx.navigation.NavController
import eu.europa.ec.commonfeature.ui.request.DocumentCard
import eu.europa.ec.commonfeature.ui.request.model.DocumentItemUi
import eu.europa.ec.corelogic.util.CoreActions
import eu.europa.ec.resourceslogic.R
import eu.europa.ec.uilogic.component.ErrorInfo
import eu.europa.ec.uilogic.component.SystemBroadcastReceiver
import eu.europa.ec.uilogic.component.content.ContentGradient
import eu.europa.ec.uilogic.component.content.ContentScreen
import eu.europa.ec.uilogic.component.content.ContentTitle
Expand Down Expand Up @@ -86,7 +88,7 @@ fun DocumentOfferScreen(
isLoading = state.isLoading,
contentErrorConfig = state.error,
navigatableAction = ScreenNavigateAction.NONE,
onBack = { viewModel.setEvent(Event.Pop) },
onBack = { viewModel.setEvent(Event.SecondaryButtonPressed) },
) { paddingValues ->
Content(
state = state,
Expand Down Expand Up @@ -131,6 +133,10 @@ fun DocumentOfferScreen(
OneTimeLaunchedEffect {
viewModel.setEvent(Event.Init)
}

SystemBroadcastReceiver(action = CoreActions.VCI_RESUME_ACTION) {
viewModel.setEvent(Event.OnResumeIssuance)
}
}

private fun handleNavigationEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sealed class Event : ViewEvent {
data object Init : Event()
data object Pop : Event()
data object OnPause : Event()
data object OnResumeIssuance : Event()
data object DismissError : Event()

data class PrimaryButtonPressed(val context: Context) : Event()
Expand Down Expand Up @@ -173,6 +174,10 @@ class DocumentOfferViewModel(
setState { copy(isLoading = false) }
}
}

is Event.OnResumeIssuance -> setState {
copy(isLoading = true)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 European Commission
*
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European
* Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work
* except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the Licence for the specific language
* governing permissions and limitations under the Licence.
*/

package eu.europa.ec.uilogic.component

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat

@Composable
fun SystemBroadcastReceiver(
action: String,
onEvent: (intent: Intent?) -> Unit
) {
val context = LocalContext.current

// If either context or Action changes, unregister and register again
DisposableEffect(context, action) {
val intentFilter = IntentFilter(action)
val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
onEvent(intent)
}
}

ContextCompat.registerReceiver(
context,
broadcastReceiver,
intentFilter,
ContextCompat.RECEIVER_EXPORTED
)

// When the effect leaves the Composition, remove the callback
onDispose {
context.unregisterReceiver(broadcastReceiver)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.navigation.NavGraphBuilder
import com.chuckerteam.chucker.api.Chucker
import eu.europa.ec.businesslogic.controller.security.SecurityController
import eu.europa.ec.resourceslogic.theme.ThemeManager
import eu.europa.ec.uilogic.navigation.IssuanceScreens
import eu.europa.ec.uilogic.navigation.RouterHost
import eu.europa.ec.uilogic.navigation.helper.DeepLinkType
import eu.europa.ec.uilogic.navigation.helper.handleDeepLinkAction
Expand Down Expand Up @@ -111,6 +112,16 @@ open class EudiComponentActivity : FragmentActivity() {
routerHost.getNavController(),
it.link
)
} else if (
it.type == DeepLinkType.OPENID4VCI
&& !routerHost.currentFlowIsAfterOnBoarding()
&& routerHost.isScreenOnBackStackOrForeground(IssuanceScreens.AddDocument)
) {
cacheDeepLink(intent)
routerHost.getNavController().popBackStack(
route = IssuanceScreens.AddDocument.screenRoute,
inclusive = false
)
} else if (it.type != DeepLinkType.ISSUANCE) {
cacheDeepLink(intent)
if (routerHost.currentFlowIsAfterOnBoarding()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface RouterHost {
fun currentFlowIsAfterOnBoarding(): Boolean
fun popToLandingScreen()
fun getLandingScreen(): String
fun isScreenOnBackStackOrForeground(screen: Screen): Boolean

@Composable
fun StartFlow(builder: NavGraphBuilder.(NavController) -> Unit)
Expand Down Expand Up @@ -81,6 +82,19 @@ class RouterHostImpl(
}
}

override fun isScreenOnBackStackOrForeground(screen: Screen): Boolean {
val screenRoute = screen.screenRoute
try {
if (navController.currentDestination?.route == screenRoute) {
return true
}
navController.getBackStackEntry(screenRoute)
return true
} catch (e: Exception) {
return false
}
}

override fun popToLandingScreen() {
navController.popBackStack(
route = getLandingScreen(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
import androidx.navigation.NavController
import eu.europa.ec.corelogic.util.CoreActions
import eu.europa.ec.eudi.wallet.EudiWallet
import eu.europa.ec.uilogic.BuildConfig
import eu.europa.ec.uilogic.container.EudiComponentActivity
Expand Down Expand Up @@ -83,7 +84,11 @@ fun hasDeepLink(deepLinkUri: Uri?): DeepLinkAction? {
}
}

fun handleDeepLinkAction(navController: NavController, uri: Uri, arguments: String? = null) {
fun handleDeepLinkAction(
navController: NavController,
uri: Uri,
arguments: String? = null
) {
hasDeepLink(uri)?.let { action ->

val screen: Screen
Expand All @@ -99,6 +104,7 @@ fun handleDeepLinkAction(navController: NavController, uri: Uri, arguments: Stri

DeepLinkType.ISSUANCE -> {
EudiWallet.resumeOpenId4VciWithAuthorization(action.link)
notifyOnResumeIssuance(navController.context)
return@let
}

Expand Down Expand Up @@ -147,4 +153,12 @@ enum class DeepLinkType(val host: String? = null) {
else -> EXTERNAL
}
}
}

private fun notifyOnResumeIssuance(context: Context) {
Intent().also { intent ->
intent.setAction(CoreActions.VCI_RESUME_ACTION)
intent.putExtra("data", "Nothing to see here, move along.")
context.sendBroadcast(intent)
}
}

0 comments on commit cfe37be

Please sign in to comment.