-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for pin entry sad paths.
- Loading branch information
1 parent
afb9b76
commit 62414e7
Showing
7 changed files
with
274 additions
and
56 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
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
32 changes: 32 additions & 0 deletions
32
...main/java/org/thoughtcrime/securesms/registration/viewmodel/ReRegisterWithPinViewModel.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.thoughtcrime.securesms.registration.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers | ||
import io.reactivex.rxjava3.core.Observable | ||
import io.reactivex.rxjava3.subjects.BehaviorSubject | ||
import org.thoughtcrime.securesms.pin.TokenData | ||
|
||
/** | ||
* Used during re-registration flow when pin entry is required to skip SMS verification. Mostly tracks | ||
* guesses remaining in both the local and remote check flows. | ||
*/ | ||
class ReRegisterWithPinViewModel : ViewModel() { | ||
var isLocalVerification: Boolean = false | ||
private set | ||
|
||
var hasIncorrectGuess: Boolean = false | ||
|
||
private val _triesRemaining: BehaviorSubject<Int> = BehaviorSubject.createDefault(10) | ||
val triesRemaining: Observable<Int> = _triesRemaining.observeOn(AndroidSchedulers.mainThread()) | ||
|
||
fun updateTokenData(tokenData: TokenData?) { | ||
if (tokenData == null) { | ||
isLocalVerification = true | ||
if (hasIncorrectGuess) { | ||
_triesRemaining.onNext((_triesRemaining.value!! - 1).coerceAtLeast(0)) | ||
} | ||
} else { | ||
_triesRemaining.onNext(tokenData.triesRemaining) | ||
} | ||
} | ||
} |
Oops, something went wrong.