From 066560b48e3129c86dacfd6beab1ad5bce32e7ff Mon Sep 17 00:00:00 2001 From: Oscar Spruit Date: Tue, 28 Jan 2025 11:46:47 +0100 Subject: [PATCH 1/2] Don't expose channel in AddressLookupDelegate COAND-1062 --- .../checkout/ui/core/internal/ui/AddressLookupDelegate.kt | 3 --- .../ui/core/internal/ui/DefaultAddressLookupDelegate.kt | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/AddressLookupDelegate.kt b/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/AddressLookupDelegate.kt index 6102ebe3f9..d313284c63 100644 --- a/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/AddressLookupDelegate.kt +++ b/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/AddressLookupDelegate.kt @@ -13,10 +13,8 @@ import com.adyen.checkout.components.core.AddressLookupCallback import com.adyen.checkout.components.core.AddressLookupResult import com.adyen.checkout.components.core.LookupAddress import com.adyen.checkout.components.core.internal.ui.model.AddressInputModel -import com.adyen.checkout.ui.core.internal.ui.model.AddressLookupEvent import com.adyen.checkout.ui.core.internal.ui.model.AddressLookupState import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @@ -25,7 +23,6 @@ interface AddressLookupDelegate { val addressDelegate: AddressDelegate val addressLookupStateFlow: Flow - val addressLookupEventChannel: Channel val addressLookupSubmitFlow: Flow val addressLookupErrorPopupFlow: Flow diff --git a/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/DefaultAddressLookupDelegate.kt b/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/DefaultAddressLookupDelegate.kt index c7d583ef18..4d74f016d3 100644 --- a/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/DefaultAddressLookupDelegate.kt +++ b/ui-core/src/main/java/com/adyen/checkout/ui/core/internal/ui/DefaultAddressLookupDelegate.kt @@ -61,7 +61,7 @@ class DefaultAddressLookupDelegate( private val currentAddressLookupState get() = mutableAddressLookupStateFlow.value - override val addressLookupEventChannel = bufferedChannel() + private val addressLookupEventChannel = bufferedChannel() private val addressLookupEventFlow: Flow = addressLookupEventChannel.receiveAsFlow() override val addressOutputData: AddressOutputData From 25010bcff794f3123804f8efd4bef07aafc113ac Mon Sep 17 00:00:00 2001 From: Oscar Spruit Date: Tue, 28 Jan 2025 11:48:59 +0100 Subject: [PATCH 2/2] Use a channel instead of a StateFlow to handle address queries in the example app COAND-1062 --- .../example/repositories/AddressLookupRepository.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/example-app/src/main/java/com/adyen/checkout/example/repositories/AddressLookupRepository.kt b/example-app/src/main/java/com/adyen/checkout/example/repositories/AddressLookupRepository.kt index 9a89d1931f..a36163441e 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/repositories/AddressLookupRepository.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/repositories/AddressLookupRepository.kt @@ -16,12 +16,12 @@ import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.debounce -import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.receiveAsFlow import javax.inject.Inject class AddressLookupRepository @Inject constructor( @@ -37,18 +37,18 @@ class AddressLookupRepository @Inject constructor( mockAddressLookupOptions = adapter.fromJson(json)?.options.orEmpty() } - private val addressLookupQueryFlow = MutableStateFlow(null) + private val addressLookupQueryChannel = Channel(Channel.BUFFERED) @OptIn(FlowPreview::class) - val addressLookupOptionsFlow: Flow> = addressLookupQueryFlow - .filterNotNull() + val addressLookupOptionsFlow: Flow> = addressLookupQueryChannel + .receiveAsFlow() .debounce(ADDRESS_LOOKUP_QUERY_DEBOUNCE_DURATION) .map { query -> queryAddressLookupOptions(query) } fun onQuery(query: String) { - addressLookupQueryFlow.tryEmit(query) + addressLookupQueryChannel.trySend(query) } suspend fun onAddressLookupCompleted(lookupAddress: LookupAddress): AddressLookupCompletionResult {