This repository was archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathWelcomePresenter.kt
More file actions
95 lines (84 loc) · 3.1 KB
/
Copy pathWelcomePresenter.kt
File metadata and controls
95 lines (84 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package mozilla.lockbox.presenter
import io.reactivex.Observable
import io.reactivex.rxkotlin.addTo
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.service.fxa.sharing.ShareableAccount
import mozilla.lockbox.action.AccountAction
import mozilla.lockbox.action.AppWebPageAction
import mozilla.lockbox.action.DialogAction
import mozilla.lockbox.action.RouteAction
import mozilla.lockbox.flux.Dispatcher
import mozilla.lockbox.flux.Presenter
import mozilla.lockbox.store.AccountStore
import mozilla.lockbox.store.FingerprintStore
import mozilla.lockbox.support.FeatureFlags
interface WelcomeView {
val getStartedAutomaticallyClicks: Observable<Unit>
val getStartedManuallyClicks: Observable<Unit>
val learnMoreClicks: Observable<Unit>
val switchServiceClicks: Observable<Unit>
fun hideSwitchService()
fun showExistingAccount(email: String)
fun hideExistingAccount()
}
@ExperimentalCoroutinesApi
class WelcomePresenter(
private val view: WelcomeView,
private val chinaBuild: Boolean,
private val dispatcher: Dispatcher = Dispatcher.shared,
private val accountStore: AccountStore = AccountStore.shared,
private val fingerprintStore: FingerprintStore = FingerprintStore.shared
) : Presenter() {
override fun onViewReady() {
if (FeatureFlags.FXA_LOGIN_WITTH_AUTHPROVIDER) {
accountStore.shareableAccount()?.let { account ->
view.showExistingAccount(account.email)
view.getStartedAutomaticallyClicks
.map {
routeToExistingAccount(account)
}
.subscribe(dispatcher::dispatch)
.addTo(compositeDisposable)
} ?: view.hideExistingAccount()
} else {
view.hideExistingAccount()
}
if (!chinaBuild) {
view.hideSwitchService()
}
view.getStartedManuallyClicks
.map {
routeToLoginManually()
}
.subscribe(dispatcher::dispatch)
.addTo(compositeDisposable)
view.learnMoreClicks
.subscribe {
dispatcher.dispatch(AppWebPageAction.FaqWelcome)
}
.addTo(compositeDisposable)
view.switchServiceClicks
.map {
RouteAction.SettingList
}
.subscribe(dispatcher::dispatch)
.addTo(compositeDisposable)
}
private fun routeToExistingAccount(account: ShareableAccount) =
if (fingerprintStore.isKeyguardDeviceSecure) {
AccountAction.AutomaticLogin(account)
} else {
DialogAction.OnboardingSecurityDialogAutomatic(account)
}
private fun routeToLoginManually() =
if (fingerprintStore.isKeyguardDeviceSecure) {
RouteAction.Login
} else {
DialogAction.OnboardingSecurityDialogManual
}
}