Skip to content

Commit 16b0e9e

Browse files
committed
Test updating user name
1 parent 4641667 commit 16b0e9e

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LoginActivity : AppCompatActivity() {
3030

3131
Pluto.initialize(
3232
this,
33-
"https://staging.easyjapanese-api-gateway.mushare.cn/pluto-master/",
33+
"https://beta-pluto.kaboocha.com/",
3434
"org.mushare.easyjapanese"
3535
)
3636

@@ -104,9 +104,14 @@ class LoginActivity : AppCompatActivity() {
104104
}
105105
}
106106

107-
if (Pluto.getInstance()?.state == Pluto.State.signin) {
108-
startActivity(Intent(this, ProfileActivity::class.java))
109-
}
107+
Pluto.getInstance()?.state?.observe(this, Observer {
108+
when (it) {
109+
Pluto.State.signin -> {
110+
startActivity(Intent(this, ProfileActivity::class.java))
111+
}
112+
}
113+
})
114+
110115
}
111116

112117
private fun updateUiWithUser(model: LoggedInUserView) {

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
11
package com.mushare.demoapp.ui.login;
22

33
import android.os.Bundle
4+
import android.util.Log
45
import android.widget.Button
6+
import android.widget.EditText
57
import android.widget.TextView
68
import android.widget.Toast
79
import androidx.appcompat.app.AppCompatActivity
810
import com.mushare.demoapp.R
911
import com.mushare.plutosdk.Pluto
1012
import com.mushare.plutosdk.getToken
1113
import com.mushare.plutosdk.myInfo
14+
import com.mushare.plutosdk.updateName
15+
import java.lang.ref.WeakReference
1216

1317
class ProfileActivity : AppCompatActivity() {
1418

19+
companion object {
20+
private val TAG = ProfileActivity::class.java.simpleName
21+
}
22+
23+
private lateinit var nameEditText: WeakReference<EditText>
24+
1525
override fun onCreate(savedInstanceState: Bundle?) {
1626
super.onCreate(savedInstanceState)
1727

1828
setContentView(R.layout.activity_profile)
1929

30+
nameEditText = WeakReference(findViewById<EditText>(R.id.profile_name))
31+
2032
Pluto.getInstance()?.myInfo(success = {
21-
findViewById<TextView>(R.id.profile_name).text = it.name
33+
nameEditText.get()?.setText(it.name)
2234
})
2335

2436
Pluto.getInstance()?.getToken(completion = {
2537
findViewById<TextView>(R.id.profile_access_token).text = it ?: "Refresh failed"
2638
})
2739

40+
findViewById<Button>(R.id.profile_update_name).setOnClickListener {
41+
val name = nameEditText.get()?.text.toString() ?: return@setOnClickListener
42+
Pluto.getInstance()?.updateName(
43+
name = name,
44+
success = {
45+
Pluto.getInstance()?.myInfo(success = {
46+
Toast.makeText(this, "Name updated", Toast.LENGTH_SHORT).show()
47+
})
48+
},
49+
error = {
50+
Log.d(TAG, "Error updating username $it")
51+
}
52+
)
53+
}
54+
2855
findViewById<Button>(R.id.profile_refresh_token).setOnClickListener {
2956
Pluto.getInstance()?.getToken(isForceRefresh = true, completion = {
3057
findViewById<TextView>(R.id.profile_access_token).text = it ?: "Refresh failed"

demoapp/src/main/res/layout/activity_profile.xml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@
44
android:layout_height="match_parent"
55
xmlns:app="http://schemas.android.com/apk/res-auto">
66

7-
<TextView
7+
<EditText
88
android:id="@+id/profile_name"
99
android:layout_width="match_parent"
1010
android:layout_height="wrap_content"
1111
app:layout_constraintTop_toTopOf="parent"
1212
android:layout_marginStart="20dp"
1313
android:layout_marginTop="20dp"
1414
android:layout_marginEnd="20dp"
15-
android:text="Username"/>
15+
android:hint="Username"/>
1616

1717
<Button
18-
android:id="@+id/profile_refresh_token"
18+
android:id="@+id/profile_update_name"
1919
android:layout_width="match_parent"
2020
android:layout_height="wrap_content"
2121
app:layout_constraintTop_toBottomOf="@id/profile_name"
2222
android:layout_marginStart="20dp"
23-
android:layout_marginTop="20dp"
23+
android:layout_marginTop="10dp"
24+
android:layout_marginEnd="20dp"
25+
android:text="Update Username"
26+
/>
27+
28+
<Button
29+
android:id="@+id/profile_refresh_token"
30+
android:layout_width="match_parent"
31+
android:layout_height="wrap_content"
32+
app:layout_constraintTop_toBottomOf="@id/profile_update_name"
33+
android:layout_marginStart="20dp"
34+
android:layout_marginTop="10dp"
2435
android:layout_marginEnd="20dp"
2536
android:text="Refresh Token"/>
2637

0 commit comments

Comments
 (0)