-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FX-722] Add support for
derivedCardInfo.usState
to ElementState
…
…for `ForagePANEditText` (#133) ElementState previously only cared about values that were common to both PAN end PIN. We have reached a point where the states will need to diverage. * Update unit tests for usState support * Make ElementState an interface instead of data class However, Forage X had a conversation around this where we said we would be OK with risk of changing the type of `ElementState` to something other than `data class`. This opened the door for us to make `ElementState` an interface, which is decoupled from the actual Data Transfer Objects used to ferry the state of the ForageElement. The rest of the changes in this commit follow from making `ElementState` an interface. One upside of this approach is that we get rid of `PinDetails`, which was annoying
- Loading branch information
1 parent
f430751
commit 440d709
Showing
15 changed files
with
285 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
forage-android/src/main/java/com/joinforage/forage/android/core/element/ElementEvents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
package com.joinforage.forage.android.core.element | ||
|
||
import com.joinforage.forage.android.core.element.state.ElementState | ||
|
||
internal typealias SimpleElementListener = () -> Unit | ||
internal typealias StatefulElementListener = (state: ElementState) -> Unit | ||
internal typealias StatefulElementListener<T> = (state: T) -> Unit |
61 changes: 53 additions & 8 deletions
61
...ge-android/src/main/java/com/joinforage/forage/android/core/element/state/ElementState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,65 @@ | ||
package com.joinforage.forage.android.core.element.state | ||
|
||
import com.joinforage.forage.android.core.element.ElementValidationError | ||
import com.joinforage.forage.android.model.USState | ||
|
||
data class ElementState( | ||
val isFocused: Boolean, | ||
val isBlurred: Boolean, | ||
val isEmpty: Boolean, | ||
val isValid: Boolean, | ||
val isComplete: Boolean, | ||
interface ElementState { | ||
val isFocused: Boolean | ||
val isBlurred: Boolean | ||
val isEmpty: Boolean | ||
val isValid: Boolean | ||
val isComplete: Boolean | ||
val validationError: ElementValidationError? | ||
) | ||
internal val INITIAL_ELEMENT_STATE = ElementState( | ||
} | ||
|
||
interface PinElementState : ElementState | ||
|
||
data class PinElementStateDto( | ||
override val isFocused: Boolean, | ||
override val isBlurred: Boolean, | ||
override val isEmpty: Boolean, | ||
override val isValid: Boolean, | ||
override val isComplete: Boolean, | ||
override val validationError: ElementValidationError? | ||
) : PinElementState | ||
|
||
internal val INITIAL_PIN_ELEMENT_STATE = PinElementStateDto( | ||
isFocused = false, | ||
isBlurred = true, | ||
isEmpty = true, | ||
isValid = true, | ||
isComplete = false, | ||
validationError = null | ||
) | ||
|
||
interface DerivedCardInfo { | ||
val usState: USState? | ||
} | ||
|
||
data class DerivedCardInfoDto( | ||
override val usState: USState? = null | ||
) : DerivedCardInfo | ||
|
||
interface PanElementState : ElementState { | ||
val derivedCardInfo: DerivedCardInfo // the interface not the DTO | ||
} | ||
|
||
data class PanElementStateDto( | ||
override val isFocused: Boolean, | ||
override val isBlurred: Boolean, | ||
override val isEmpty: Boolean, | ||
override val isValid: Boolean, | ||
override val isComplete: Boolean, | ||
override val validationError: ElementValidationError?, | ||
override val derivedCardInfo: DerivedCardInfoDto | ||
) : PanElementState | ||
|
||
internal val INITIAL_PAN_ELEMENT_STATE = PanElementStateDto( | ||
isFocused = false, | ||
isBlurred = true, | ||
isEmpty = true, | ||
isValid = true, | ||
isComplete = false, | ||
validationError = null, | ||
derivedCardInfo = DerivedCardInfoDto() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.