Skip to content

Commit c23e69c

Browse files
authored
Merge branch 'master' into develop/binding
2 parents 1308d80 + f69f754 commit c23e69c

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed

demoapp/src/main/java/com/mushare/demoapp/data/LoginDataSource.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ class LoginDataSource {
1717
//pluto?.registerByEmail(username, password, "Test", {
1818
//pluto?.resendValidationEmail(username, {
1919
pluto?.loginWithAccount(username, password, {
20-
pluto.myInfo({
21-
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), it.name)
22-
onComplete(Result.Success(fakeUser))
23-
}, {
24-
onComplete(Result.Error(IOException("Error getting account info $it")))
25-
Log.e("getInfo", "failed $it")
26-
})
20+
pluto.myInfo(
21+
success = {
22+
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), it.name)
23+
onComplete(Result.Success(fakeUser))
24+
},
25+
error = {
26+
onComplete(Result.Error(IOException("Error getting account info $it")))
27+
Log.e("getInfo", "failed $it")
28+
}
29+
)
2730
}, {
2831
onComplete(Result.Error(IOException("Error logging in $it")))
2932
Log.e("login", "failed $it")

demoapp/src/main/java/com/mushare/demoapp/ui/login/ProfileActivity.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,17 @@ class ProfileActivity : AppCompatActivity() {
114114
}
115115

116116
private fun updateUserInfo(completion: (() -> Unit)? = null) {
117-
Pluto.getInstance()?.myInfo(success = { user ->
118-
nameEditText.get()?.setText(user.name)
119-
userIdEditText.get()?.setText(user.userId)
120-
avatarImageView.get()?.let {
121-
Glide.with(this).load(user.avatar).into(it)
117+
Pluto.getInstance()?.myInfo(
118+
isForceRefresh = false,
119+
success = { user ->
120+
nameEditText.get()?.setText(user.name)
121+
userIdEditText.get()?.setText(user.userId)
122+
avatarImageView.get()?.let {
123+
Glide.with(this).load(user.avatar).into(it)
124+
}
125+
completion?.let { it() }
122126
}
123-
completion?.let { it() }
124-
})
127+
)
125128

126129
}
127130
}

pluto-kotlin-client-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'maven-publish'
55

66
buildscript {
77
ext.versionCode = 13
8-
ext.versionName = '0.5.1'
8+
ext.versionName = '0.6.1'
99
}
1010

1111
android {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@ import retrofit2.Response
99
import java.io.ByteArrayOutputStream
1010
import java.io.File
1111

12+
val Pluto.currentUser: PlutoUser?
13+
get() {
14+
if (state != Pluto.State.signin) {
15+
return null
16+
}
17+
return data.user
18+
}
19+
1220
fun Pluto.myInfo(
21+
isForceRefresh: Boolean = false,
1322
success: (PlutoUser) -> Unit,
1423
error: ((PlutoError) -> Unit)? = null,
1524
handler: Pluto.PlutoRequestHandler? = null
1625
) {
26+
val currentUser = data.user
27+
if (!isForceRefresh && currentUser != null) {
28+
success(currentUser)
29+
return
30+
}
1731
getAuthorizationHeader(
1832
completion = { header ->
1933
if (header == null) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class Pluto private constructor() {
4646

4747
internal val data by lazy { PlutoModel(context) }
4848

49-
val state: MutableLiveData<State> by lazy { MutableLiveData(State.loading) }
49+
val state: MutableLiveData<State> by lazy {
50+
MutableLiveData(if (data.isTokenNull) State.notSignin else State.signin)
51+
}
5052

5153
internal val gson: Gson by lazy { GsonBuilder().serializeNulls().create() }
5254
internal val plutoService: PlutoService by lazy {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ internal class PlutoModel(context: Context) {
7777
infoJSONString = gson.toJson(value)
7878
}
7979

80+
val isTokenNull: Boolean
81+
get() = accessToken == null || refreshToken == null
82+
8083
fun updateAccessToken(jwt: String): Boolean {
8184
val body = JwtUtils.decodeBody(jwt) ?: return false
8285
return try {

0 commit comments

Comments
 (0)