Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Autocomplete address screen #5248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 67 additions & 0 deletions payments-ui-core/api/payments-ui-core.api
Expand Up @@ -584,6 +584,73 @@ public final class com/stripe/android/ui/core/elements/TranslationId$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/autocomplete/PlacesClientProxy$Companion {
public final fun create (Landroid/content/Context;Ljava/lang/String;Lcom/stripe/android/ui/core/elements/autocomplete/IsPlacesAvailable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/stripe/android/ui/core/elements/autocomplete/PlacesClientProxy;
public static synthetic fun create$default (Lcom/stripe/android/ui/core/elements/autocomplete/PlacesClientProxy$Companion;Landroid/content/Context;Ljava/lang/String;Lcom/stripe/android/ui/core/elements/autocomplete/IsPlacesAvailable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/stripe/android/ui/core/elements/autocomplete/PlacesClientProxy;
public final fun getPlacesPoweredByGoogleDrawable (ZLcom/stripe/android/ui/core/elements/autocomplete/IsPlacesAvailable;)Ljava/lang/Integer;
public static synthetic fun getPlacesPoweredByGoogleDrawable$default (Lcom/stripe/android/ui/core/elements/autocomplete/PlacesClientProxy$Companion;ZLcom/stripe/android/ui/core/elements/autocomplete/IsPlacesAvailable;ILjava/lang/Object;)Ljava/lang/Integer;
}

public final class com/stripe/android/ui/core/elements/autocomplete/model/AddressComponent$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field $stable I
public static final field INSTANCE Lcom/stripe/android/ui/core/elements/autocomplete/model/AddressComponent$$serializer;
public static final synthetic field descriptor Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/stripe/android/ui/core/elements/autocomplete/model/AddressComponent;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/stripe/android/ui/core/elements/autocomplete/model/AddressComponent;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/autocomplete/model/AddressComponent$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/autocomplete/model/Place$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field $stable I
public static final field INSTANCE Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$$serializer;
public static final synthetic field descriptor Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/stripe/android/ui/core/elements/autocomplete/model/Place;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/stripe/android/ui/core/elements/autocomplete/model/Place;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/autocomplete/model/Place$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/autocomplete/model/Place$Type : java/lang/Enum {
public static final field ADMINISTRATIVE_AREA_LEVEL_1 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field ADMINISTRATIVE_AREA_LEVEL_2 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field ADMINISTRATIVE_AREA_LEVEL_3 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field ADMINISTRATIVE_AREA_LEVEL_4 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field COUNTRY Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field LOCALITY Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field NEIGHBORHOOD Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field POSTAL_CODE Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field POSTAL_TOWN Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field PREMISE Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field ROUTE Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field STREET_NUMBER Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field SUBLOCALITY Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field SUBLOCALITY_LEVEL_1 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field SUBLOCALITY_LEVEL_2 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field SUBLOCALITY_LEVEL_3 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static final field SUBLOCALITY_LEVEL_4 Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public final fun getValue ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
public static fun values ()[Lcom/stripe/android/ui/core/elements/autocomplete/model/Place$Type;
}

public final class com/stripe/android/ui/core/elements/autocomplete/model/TransformGoogleToStripeAddressKt {
}

public final class com/stripe/android/ui/core/elements/menu/CheckboxKt {
}

Expand Down
2 changes: 2 additions & 0 deletions payments-ui-core/res/values/colors.xml
Expand Up @@ -49,4 +49,6 @@

<!-- CardFormView -->

<color name="stripe_paymentsheet_shipping_address_background">#1A1A1A0D</color>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talking to Clarissa about this color


</resources>
4 changes: 4 additions & 0 deletions payments-ui-core/res/values/totranslate.xml
Expand Up @@ -7,4 +7,8 @@
<string name="stripe_paymentsheet_ach_something_went_wrong">Something went wrong when linking your account.\nPlease try again later.</string>
<string name="stripe_paymentsheet_pay_with_bank_title">Pay with your bank account in just a few steps.</string>
<string name="stripe_paymentsheet_remove_bank_account_title">Remove bank account</string>

<!-- Shipping Address Element -->
<string name="stripe_paymentsheet_enter_address_manually">Enter address manually</string>
<string name="stripe_paymentsheet_autocomplete_no_results_found">No results found</string>
</resources>
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.ui.core.elements.autocomplete
import android.content.Context
import android.graphics.Typeface
import android.text.style.StyleSpan
import androidx.annotation.RestrictTo
import com.google.android.libraries.places.api.Places
import com.google.android.libraries.places.api.model.AutocompleteSessionToken
import com.google.android.libraries.places.api.model.TypeFilter
Expand All @@ -18,7 +19,8 @@ import com.stripe.android.ui.core.elements.autocomplete.model.FindAutocompletePr
import com.stripe.android.ui.core.elements.autocomplete.model.Place
import kotlinx.coroutines.tasks.await

internal interface PlacesClientProxy {
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
interface PlacesClientProxy {
suspend fun findAutocompletePredictions(
query: String?,
country: String,
Expand Down Expand Up @@ -166,7 +168,8 @@ internal class UnsupportedPlacesClientProxy : PlacesClientProxy {
}
}

internal interface IsPlacesAvailable {
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
interface IsPlacesAvailable {
operator fun invoke(): Boolean
}

Expand Down
@@ -1,25 +1,30 @@
package com.stripe.android.ui.core.elements.autocomplete.model

import android.text.SpannableString
import androidx.annotation.RestrictTo
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

internal data class FindAutocompletePredictionsResponse(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class FindAutocompletePredictionsResponse(
val autocompletePredictions: List<AutocompletePrediction>
)

internal data class AutocompletePrediction(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class AutocompletePrediction(
val primaryText: SpannableString,
val secondaryText: SpannableString,
val placeId: String
)

internal data class FetchPlaceResponse(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class FetchPlaceResponse(
val place: Place
)

@Serializable
internal data class Place(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class Place(
@SerialName("address_components") val addressComponents: List<AddressComponent>?
) {
enum class Type(val value: String) {
Expand All @@ -44,7 +49,8 @@ internal data class Place(
}

@Serializable
internal data class AddressComponent(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class AddressComponent(
@SerialName("short_name") val shortName: String?,
@SerialName("long_name") val longName: String,
@SerialName("types") val types: List<String>
Expand Down
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.ui.core.elements.autocomplete.model

import android.content.Context
import android.os.Build
import androidx.annotation.RestrictTo
import java.util.Locale

// Largely duplicated from
Expand Down Expand Up @@ -176,7 +177,8 @@ internal fun Address.modifyStripeAddressByCountry(place: Place): Address {
return newAddress
}

internal fun Place.transformGoogleToStripeAddress(
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun Place.transformGoogleToStripeAddress(
context: Context
): com.stripe.android.model.Address {
var address = Address()
Expand Down
1 change: 1 addition & 0 deletions paymentsheet-example/build.gradle
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation project(':stripecardscan')
implementation project(':financial-connections')

implementation "com.google.android.libraries.places:places:$placesVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$androidxLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$androidxLifecycleVersion"
implementation "androidx.preference:preference-ktx:$androidxPreferenceVersion"
Expand Down
27 changes: 12 additions & 15 deletions paymentsheet/api/paymentsheet.api
Expand Up @@ -798,20 +798,24 @@ public final class com/stripe/android/paymentsheet/addresselement/AddressElement
public static fun injectViewModel (Lcom/stripe/android/paymentsheet/addresselement/AddressElementViewModel$Factory;Lcom/stripe/android/paymentsheet/addresselement/AddressElementViewModel;)V
}

public final class com/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel_Factory : dagger/internal/Factory {
public fun <init> (Ljavax/inject/Provider;Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel_Factory;
public fun get ()Lcom/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel;
public final class com/stripe/android/paymentsheet/addresselement/AutocompleteScreenKt {
public static final field TEST_TAG_ATTRIBUTION_DRAWABLE Ljava/lang/String;
}

public final class com/stripe/android/paymentsheet/addresselement/AutocompleteViewModel_Factory : dagger/internal/Factory {
public fun <init> (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/paymentsheet/addresselement/AutocompleteViewModel_Factory;
public fun get ()Lcom/stripe/android/paymentsheet/addresselement/AutocompleteViewModel;
public synthetic fun get ()Ljava/lang/Object;
public static fun newInstance (Lcom/stripe/android/paymentsheet/addresselement/AddressElementActivityContract$Args;Lcom/stripe/android/paymentsheet/addresselement/AddressElementNavigator;)Lcom/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel;
public static fun newInstance (Lcom/stripe/android/paymentsheet/addresselement/AddressElementActivityContract$Args;Lcom/stripe/android/paymentsheet/addresselement/AddressElementNavigator;Landroid/app/Application;)Lcom/stripe/android/paymentsheet/addresselement/AutocompleteViewModel;
}

public final class com/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel_Factory_MembersInjector : dagger/MembersInjector {
public final class com/stripe/android/paymentsheet/addresselement/AutocompleteViewModel_Factory_MembersInjector : dagger/MembersInjector {
public fun <init> (Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;)Ldagger/MembersInjector;
public fun injectMembers (Lcom/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel$Factory;)V
public fun injectMembers (Lcom/stripe/android/paymentsheet/addresselement/AutocompleteViewModel$Factory;)V
public synthetic fun injectMembers (Ljava/lang/Object;)V
public static fun injectSubComponentBuilderProvider (Lcom/stripe/android/paymentsheet/addresselement/AutoCompleteViewModel$Factory;Ljavax/inject/Provider;)V
public static fun injectSubComponentBuilderProvider (Lcom/stripe/android/paymentsheet/addresselement/AutocompleteViewModel$Factory;Ljavax/inject/Provider;)V
}

public final class com/stripe/android/paymentsheet/addresselement/ComposableSingletons$AddressElementActivityKt {
Expand All @@ -821,13 +825,6 @@ public final class com/stripe/android/paymentsheet/addresselement/ComposableSing
public final fun getLambda-1$paymentsheet_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/paymentsheet/addresselement/ComposableSingletons$AutoCompleteScreenKt {
public static final field INSTANCE Lcom/stripe/android/paymentsheet/addresselement/ComposableSingletons$AutoCompleteScreenKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public fun <init> ()V
public final fun getLambda-1$paymentsheet_release ()Lkotlin/jvm/functions/Function3;
}

public final class com/stripe/android/paymentsheet/addresselement/ComposableSingletons$InputAddressScreenKt {
public static final field INSTANCE Lcom/stripe/android/paymentsheet/addresselement/ComposableSingletons$InputAddressScreenKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
Expand Down
1 change: 1 addition & 0 deletions paymentsheet/build.gradle
Expand Up @@ -81,6 +81,7 @@ dependencies {
testImplementation "androidx.arch.core:core-testing:$androidxArchCoreVersion"
testImplementation "androidx.fragment:fragment-testing:$androidxFragmentVersion"

androidTestImplementation "com.google.android.libraries.places:places:$placesVersion"
androidTestImplementation "androidx.test.ext:junit:$androidTestJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation ("androidx.test.espresso:espresso-contrib:$espressoVersion") {
Expand Down