diff --git a/app/src/main/java/com/kickstarter/viewmodels/TwoFactorViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/TwoFactorViewModel.kt index 235e1352f4..7b46a1a1c2 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/TwoFactorViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/TwoFactorViewModel.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModelProvider import com.kickstarter.libs.Environment import com.kickstarter.libs.rx.transformers.Transformers import com.kickstarter.libs.utils.extensions.addToDisposable -import com.kickstarter.libs.utils.extensions.isNotNull import com.kickstarter.models.User import com.kickstarter.services.ApiClientTypeV2 import com.kickstarter.services.apiresponses.AccessTokenEnvelope @@ -50,7 +49,7 @@ interface TwoFactorViewModel { class TwoFactorViewModel( environment: Environment, - intent: Intent? = null + intent: Intent ) : ViewModel(), Inputs, Outputs { private val client: ApiClientTypeV2 = requireNotNull(environment.apiClientV2()) private val analytics = requireNotNull(environment.analytics()) @@ -155,15 +154,14 @@ interface TwoFactorViewModel { ) companion object { private fun isCodeValid(code: String?): Boolean { - return code != null && code.isNotEmpty() + return !code.isNullOrEmpty() } } init { val email = internalIntent - .map { it.getStringExtra(IntentKey.EMAIL) } - .filter { it.isNotNull() } + .map { it.getStringExtra(IntentKey.EMAIL) ?: "" } val fbAccessToken = internalIntent .map { it.getStringExtra(IntentKey.FACEBOOK_TOKEN) ?: "" } @@ -172,8 +170,7 @@ interface TwoFactorViewModel { .map { it.getBooleanExtra(IntentKey.FACEBOOK_LOGIN, false) } val password = internalIntent - .map { it.getStringExtra(IntentKey.PASSWORD) } - .filter { it.isNotNull() } + .map { it.getStringExtra(IntentKey.PASSWORD) ?: "" } val tfaData = Observable.combineLatest( email, @@ -198,7 +195,7 @@ interface TwoFactorViewModel { } this.code - .map { code: String? -> isCodeValid(code) } + .map { isCodeValid(it) } .subscribe { formIsValid.onNext(it) } .addToDisposable(disposables) @@ -264,7 +261,7 @@ interface TwoFactorViewModel { } } - class Factory(private val environment: Environment, private val intent: Intent? = null) : ViewModelProvider.Factory { + class Factory(private val environment: Environment, private val intent: Intent) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { return TwoFactorViewModel(environment, intent) as T }