Skip to content

Commit de9bd94

Browse files
committed
Add completion for logout
1 parent f554548 commit de9bd94

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/Pluto+Login.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fun Pluto.loginWithAccount(
8484
error: ((PlutoError) -> Unit)? = null,
8585
handler: Pluto.PlutoRequestHandler? = null
8686
) {
87-
state.postValue(Pluto.State.loading)
87+
state.value = Pluto.State.loading
8888
val deviceId = data.deviceID
8989
if (deviceId == null) {
9090
error?.invoke(PlutoError.badRequest)
@@ -106,7 +106,7 @@ fun Pluto.loginWithGoogle(
106106
error: ((PlutoError) -> Unit)? = null,
107107
handler: Pluto.PlutoRequestHandler? = null
108108
) {
109-
state.postValue(Pluto.State.loading)
109+
state.value = Pluto.State.loading
110110
val deviceId = data.deviceID
111111
if (deviceId == null) {
112112
error?.invoke(PlutoError.badRequest)
@@ -128,7 +128,7 @@ fun Pluto.loginWithWeChat(
128128
error: ((PlutoError) -> Unit)? = null,
129129
handler: Pluto.PlutoRequestHandler? = null
130130
) {
131-
state.postValue(Pluto.State.loading)
131+
state.value = Pluto.State.loading
132132
val deviceId = data.deviceID
133133
if (deviceId == null) {
134134
error?.invoke(PlutoError.badRequest)
@@ -180,9 +180,10 @@ fun Pluto.resetPassword(
180180
}
181181
}
182182

183-
fun Pluto.logout() {
183+
fun Pluto.logout(completion: (() -> Unit)? = null) {
184184
data.clear()
185-
state.postValue(Pluto.State.notSignIn)
185+
state.value = Pluto.State.notSignIn
186+
completion?.invoke()
186187
}
187188

188189
private fun Pluto.handleLoginCallback(
@@ -214,7 +215,7 @@ private fun Pluto.handleLoginCallback(
214215
error?.invoke(PlutoError.parseError)
215216
return
216217
}
217-
state.postValue(Pluto.State.signIn)
218+
state.value = Pluto.State.signIn
218219
success?.invoke()
219220
} else {
220221
error?.invoke(plutoResponse.errorCode())

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/Pluto.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,7 @@ class Pluto private constructor() {
8383

8484
init {
8585
getAccessToken(completion = {
86-
state.postValue(
87-
if (it == null) {
88-
State.notSignIn
89-
} else {
90-
State.signIn
91-
}
92-
)
86+
state.value = if (it == null) State.notSignIn else State.signIn
9387
})
9488
}
9589

0 commit comments

Comments
 (0)