Skip to content

Commit

Permalink
[Identity] preserve states when activity is destroyed (#5252)
Browse files Browse the repository at this point in the history
* [Identity] Move injection to IdentityActivity

* lint

* rename component

* [Identity] preserve states when activity is destroyed

* fix rebase conflict
  • Loading branch information
ccen-stripe committed Jul 6, 2022
1 parent 238b362 commit f43009b
Show file tree
Hide file tree
Showing 22 changed files with 344 additions and 177 deletions.
50 changes: 41 additions & 9 deletions identity/api/identity.api
Expand Up @@ -98,6 +98,14 @@ public final class com/stripe/android/identity/IdentityVerificationSheetContract
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/identity/analytics/AnalyticsState$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/identity/analytics/AnalyticsState;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/identity/analytics/AnalyticsState;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/identity/analytics/FPSTracker_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/identity/analytics/FPSTracker_Factory;
Expand Down Expand Up @@ -323,7 +331,7 @@ public final class com/stripe/android/identity/navigation/IdentityFragmentFactor
public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/identity/navigation/IdentityFragmentFactory_Factory;
public fun get ()Lcom/stripe/android/identity/navigation/IdentityFragmentFactory;
public synthetic fun get ()Ljava/lang/Object;
public static fun newInstance (Lcom/stripe/android/camera/CameraPermissionEnsureable;Lcom/stripe/android/camera/AppSettingsOpenable;Lcom/stripe/android/identity/VerificationFlowFinishable;Lcom/stripe/android/identity/viewmodel/IdentityScanViewModel$IdentityScanViewModelFactory;Lcom/stripe/android/identity/viewmodel/IdentityUploadViewModel$FrontBackUploadViewModelFactory;Lcom/stripe/android/identity/viewmodel/ConsentFragmentViewModel$ConsentFragmentViewModelFactory;Lcom/stripe/android/identity/viewmodel/IdentityViewModel$IdentityViewModelFactory;Lcom/stripe/android/identity/FallbackUrlLauncher;)Lcom/stripe/android/identity/navigation/IdentityFragmentFactory;
public static fun newInstance (Lcom/stripe/android/camera/CameraPermissionEnsureable;Lcom/stripe/android/camera/AppSettingsOpenable;Lcom/stripe/android/identity/VerificationFlowFinishable;Lcom/stripe/android/identity/viewmodel/IdentityScanViewModel$IdentityScanViewModelFactory;Lcom/stripe/android/identity/viewmodel/ConsentFragmentViewModel$ConsentFragmentViewModelFactory;Lcom/stripe/android/identity/viewmodel/IdentityViewModel$IdentityViewModelFactory;Lcom/stripe/android/identity/FallbackUrlLauncher;Lcom/stripe/android/identity/utils/IdentityIO;)Lcom/stripe/android/identity/navigation/IdentityFragmentFactory;
}

public final class com/stripe/android/identity/networking/DefaultIdentityModelFetcher_Factory : dagger/internal/Factory {
Expand All @@ -342,6 +350,38 @@ public final class com/stripe/android/identity/networking/DefaultIdentityReposit
public static fun newInstance (Lcom/stripe/android/core/networking/StripeNetworkClient;Lcom/stripe/android/identity/utils/IdentityIO;)Lcom/stripe/android/identity/networking/DefaultIdentityRepository;
}

public final class com/stripe/android/identity/networking/DocumentUploadState$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/identity/networking/DocumentUploadState;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/identity/networking/DocumentUploadState;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/identity/networking/Resource$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/identity/networking/Resource;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/identity/networking/Resource;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/identity/networking/SelfieUploadState$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/identity/networking/SelfieUploadState;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/identity/networking/SelfieUploadState;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/identity/networking/UploadedResult$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/identity/networking/UploadedResult;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/identity/networking/UploadedResult;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/identity/utils/ContentUriResult {
public fun <init> (Landroid/net/Uri;Ljava/lang/String;)V
public final fun component1 ()Landroid/net/Uri;
Expand Down Expand Up @@ -379,11 +419,3 @@ public final class com/stripe/android/identity/viewmodel/IdentityScanViewModel_I
public static fun newInstance (Lcom/stripe/android/identity/analytics/ModelPerformanceTracker;Lkotlin/coroutines/CoroutineContext;)Lcom/stripe/android/identity/viewmodel/IdentityScanViewModel$IdentityScanViewModelFactory;
}

public final class com/stripe/android/identity/viewmodel/IdentityUploadViewModel_FrontBackUploadViewModelFactory_Factory : dagger/internal/Factory {
public fun <init> (Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;)Lcom/stripe/android/identity/viewmodel/IdentityUploadViewModel_FrontBackUploadViewModelFactory_Factory;
public fun get ()Lcom/stripe/android/identity/viewmodel/IdentityUploadViewModel$FrontBackUploadViewModelFactory;
public synthetic fun get ()Ljava/lang/Object;
public static fun newInstance (Lcom/stripe/android/identity/utils/IdentityIO;)Lcom/stripe/android/identity/viewmodel/IdentityUploadViewModel$FrontBackUploadViewModelFactory;
}

@@ -1,8 +1,11 @@
package com.stripe.android.identity.analytics

import android.os.Parcelable
import com.stripe.android.identity.networking.models.DocumentUploadParam
import com.stripe.android.identity.states.IdentityScanState
import kotlinx.parcelize.Parcelize

@Parcelize
internal data class AnalyticsState(
val scanType: IdentityScanState.ScanType? = null,
val requireSelfie: Boolean? = null,
Expand All @@ -14,4 +17,4 @@ internal data class AnalyticsState(
val docFrontModelScore: Float? = null,
val docBackModelScore: Float? = null,
val selfieModelScore: Float? = null
)
) : Parcelable
Expand Up @@ -17,7 +17,6 @@ import com.stripe.android.identity.analytics.IdentityAnalyticsRequestFactory.Com
import com.stripe.android.identity.databinding.ConsentFragmentBinding
import com.stripe.android.identity.networking.models.ClearDataParam
import com.stripe.android.identity.networking.models.CollectedDataParam
import com.stripe.android.identity.networking.models.VerificationPage.Companion.isMissingBiometricConsent
import com.stripe.android.identity.networking.models.VerificationPage.Companion.isUnsupportedClient
import com.stripe.android.identity.networking.models.VerificationPage.Companion.requireSelfie
import com.stripe.android.identity.networking.models.VerificationPageStaticContentConsentPage
Expand Down Expand Up @@ -75,7 +74,7 @@ internal class ConsentFragment(
if (verificationPage.isUnsupportedClient()) {
Log.e(TAG, "Unsupported client, launching fallback url")
fallbackUrlLauncher.launchFallbackUrl(verificationPage.fallbackUrl)
} else if (verificationPage.isMissingBiometricConsent()) {
} else {
setLoadingFinishedUI()
bindViewData(
verificationPage.biometricConsent,
Expand All @@ -85,8 +84,6 @@ internal class ConsentFragment(
lifecycleScope.launch(identityViewModel.workContext) {
identityViewModel.screenTracker.screenTransitionFinish(SCREEN_NAME_CONSENT)
}
} else {
navigateToDocSelection()
}
},
onFailure = {
Expand Down
Expand Up @@ -3,14 +3,15 @@ package com.stripe.android.identity.navigation
import androidx.lifecycle.ViewModelProvider
import com.stripe.android.identity.R
import com.stripe.android.identity.states.IdentityScanState
import com.stripe.android.identity.utils.IdentityIO

/**
* Fragment to upload Driver license.
*/
internal class DriverLicenseUploadFragment(
identityUploadViewModelFactory: ViewModelProvider.Factory,
identityIO: IdentityIO,
identityViewModelFactory: ViewModelProvider.Factory
) : IdentityUploadFragment(identityUploadViewModelFactory, identityViewModelFactory) {
) : IdentityUploadFragment(identityIO, identityViewModelFactory) {
override val titleRes = R.string.file_upload
override val contextRes = R.string.file_upload_content_dl
override val frontTextRes = R.string.front_of_dl
Expand All @@ -20,4 +21,5 @@ internal class DriverLicenseUploadFragment(
override val frontScanType = IdentityScanState.ScanType.DL_FRONT
override var backScanType: IdentityScanState.ScanType? = IdentityScanState.ScanType.DL_BACK
override val fragmentId = R.id.driverLicenseUploadFragment
override val presentedId = "DRIVER_LICENSE_UPLOAD_PRESENTED"
}
Expand Up @@ -3,14 +3,15 @@ package com.stripe.android.identity.navigation
import androidx.lifecycle.ViewModelProvider
import com.stripe.android.identity.R
import com.stripe.android.identity.states.IdentityScanState
import com.stripe.android.identity.utils.IdentityIO

/**
* Fragment to upload ID.
*/
internal class IDUploadFragment(
identityUploadViewModelFactory: ViewModelProvider.Factory,
identityIO: IdentityIO,
identityViewModelFactory: ViewModelProvider.Factory
) : IdentityUploadFragment(identityUploadViewModelFactory, identityViewModelFactory) {
) : IdentityUploadFragment(identityIO, identityViewModelFactory) {
override val titleRes = R.string.file_upload
override val contextRes = R.string.file_upload_content_id
override val frontTextRes = R.string.front_of_id
Expand All @@ -20,4 +21,5 @@ internal class IDUploadFragment(
override val frontScanType = IdentityScanState.ScanType.ID_FRONT
override var backScanType: IdentityScanState.ScanType? = IdentityScanState.ScanType.ID_BACK
override val fragmentId = R.id.IDUploadFragment
override val presentedId = "ID_UPLOAD_PRESENTED"
}
Expand Up @@ -231,7 +231,7 @@ internal abstract class IdentityCameraScanFragment(
identityScanViewModel.scanStatePrevious = null

identityViewModel.fpsTracker.start()
identityScanViewModel.identityScanFlow.startFlow(
identityScanViewModel.identityScanFlow?.startFlow(
context = requireContext(),
imageStream = cameraAdapter.getImageStream(),
viewFinder = cameraView.viewFinderWindowView.asRect(),
Expand All @@ -245,14 +245,14 @@ internal abstract class IdentityCameraScanFragment(
* Stop scanning, may start again later.
*/
protected fun stopScanning() {
identityScanViewModel.identityScanFlow.resetFlow()
identityScanViewModel.identityScanFlow?.resetFlow()
cameraAdapter.unbindFromLifecycle(this)
}

override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "Cancelling IdentityScanFlow")
identityScanViewModel.identityScanFlow.cancelFlow()
identityScanViewModel.identityScanFlow?.cancelFlow()
}

internal companion object {
Expand Down
Expand Up @@ -6,9 +6,9 @@ import com.stripe.android.camera.AppSettingsOpenable
import com.stripe.android.camera.CameraPermissionEnsureable
import com.stripe.android.identity.FallbackUrlLauncher
import com.stripe.android.identity.VerificationFlowFinishable
import com.stripe.android.identity.utils.IdentityIO
import com.stripe.android.identity.viewmodel.ConsentFragmentViewModel
import com.stripe.android.identity.viewmodel.IdentityScanViewModel
import com.stripe.android.identity.viewmodel.IdentityUploadViewModel
import com.stripe.android.identity.viewmodel.IdentityViewModel
import javax.inject.Inject

Expand All @@ -20,10 +20,10 @@ internal class IdentityFragmentFactory @Inject constructor(
private val appSettingsOpenable: AppSettingsOpenable,
private val verificationFlowFinishable: VerificationFlowFinishable,
private val identityScanViewModelFactory: IdentityScanViewModel.IdentityScanViewModelFactory,
private val identityUploadViewModelFactory: IdentityUploadViewModel.FrontBackUploadViewModelFactory,
private val consentFragmentViewModelFactory: ConsentFragmentViewModel.ConsentFragmentViewModelFactory,
internal val identityViewModelFactory: IdentityViewModel.IdentityViewModelFactory,
private val fallbackUrlLauncher: FallbackUrlLauncher
private val fallbackUrlLauncher: FallbackUrlLauncher,
private val identityIO: IdentityIO
) : FragmentFactory() {

override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
Expand All @@ -49,15 +49,15 @@ internal class IdentityFragmentFactory @Inject constructor(
identityViewModelFactory
)
IDUploadFragment::class.java.name -> IDUploadFragment(
identityUploadViewModelFactory,
identityIO,
identityViewModelFactory
)
DriverLicenseUploadFragment::class.java.name -> DriverLicenseUploadFragment(
identityUploadViewModelFactory,
identityIO,
identityViewModelFactory
)
PassportUploadFragment::class.java.name -> PassportUploadFragment(
identityUploadViewModelFactory,
identityIO,
identityViewModelFactory
)
ConsentFragment::class.java.name -> ConsentFragment(
Expand Down

0 comments on commit f43009b

Please sign in to comment.