Skip to content

Commit b16584c

Browse files
committed
kotlin tutorial tweaks
1 parent e185736 commit b16584c

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

samplekotlin/src/main/java/com/example/chattutorial/ChannelActivity3.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,16 @@ class ChannelActivity3 : AppCompatActivity() {
7878

7979
// Custom typing info header bar
8080
val nobodyTyping = "nobody is typing"
81-
binding.typingHeader.text = nobodyTyping
82-
83-
// Asynchronously obtain a ChannelController
84-
ChatDomain.instance().useCases.getChannelController(cid).enqueue {
85-
val channelController = it.data()
86-
// Get back to UI thread and observe typing users
87-
runOnUiThread {
88-
channelController.typing.observe(this) { users ->
89-
binding.typingHeader.text = when {
90-
users.isNotEmpty() -> users.joinToString(prefix = "typing: ") { user -> user.name }
91-
else -> nobodyTyping
92-
}
93-
}
81+
binding.typingHeaderView.text = nobodyTyping
82+
83+
// Obtain a ChannelController
84+
val channelController = ChatDomain.instance().useCases.getChannelController(cid).execute().data()
85+
86+
// Observe typing users
87+
channelController.typing.observe(this) { users ->
88+
binding.typingHeaderView.text = when {
89+
users.isNotEmpty() -> users.joinToString(prefix = "typing: ") { user -> user.name }
90+
else -> nobodyTyping
9491
}
9592
}
9693
}

samplekotlin/src/main/java/com/example/chattutorial/ChannelActivity4.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ChannelActivity4 : AppCompatActivity() {
8181

8282
// Custom typing info header bar
8383
val nobodyTyping = "nobody is typing"
84-
binding.typingHeader.text = nobodyTyping
84+
binding.typingHeaderView.text = nobodyTyping
8585

8686
val currentlyTyping = mutableSetOf<String>()
8787

@@ -96,7 +96,7 @@ class ChannelActivity4 : AppCompatActivity() {
9696
is TypingStopEvent -> currentlyTyping.remove(event.user.extraData["name"] as String)
9797
}
9898

99-
binding.typingHeader.text = when {
99+
binding.typingHeaderView.text = when {
100100
currentlyTyping.isNotEmpty() -> currentlyTyping.joinToString(prefix = "typing: ")
101101
else -> nobodyTyping
102102
}

samplekotlin/src/main/res/layout/activity_channel_3.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
app:layout_constraintTop_toTopOf="parent" />
1515

1616
<TextView
17-
android:id="@+id/typingHeader"
17+
android:id="@+id/typingHeaderView"
1818
android:layout_width="match_parent"
1919
android:layout_height="31dp"
2020
android:background="#CCCCCC"
@@ -30,7 +30,7 @@
3030
app:layout_constraintBottom_toTopOf="@+id/messageInputView"
3131
app:layout_constraintEnd_toEndOf="parent"
3232
app:layout_constraintStart_toStartOf="parent"
33-
app:layout_constraintTop_toBottomOf="@+id/typingHeader"
33+
app:layout_constraintTop_toBottomOf="@+id/typingHeaderView"
3434
android:clipToPadding="false"
3535
android:paddingBottom="16dp"
3636
android:background="#f3f5f8"

samplekotlin/src/main/res/layout/activity_channel_4.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
app:layout_constraintTop_toTopOf="parent" />
1515

1616
<TextView
17-
android:id="@+id/typingHeader"
17+
android:id="@+id/typingHeaderView"
1818
android:layout_width="match_parent"
1919
android:layout_height="31dp"
2020
android:background="#CCCCCC"
@@ -30,7 +30,7 @@
3030
app:layout_constraintBottom_toTopOf="@+id/messageInputView"
3131
app:layout_constraintEnd_toEndOf="parent"
3232
app:layout_constraintStart_toStartOf="parent"
33-
app:layout_constraintTop_toBottomOf="@+id/typingHeader"
33+
app:layout_constraintTop_toBottomOf="@+id/typingHeaderView"
3434
android:clipToPadding="false"
3535
android:paddingBottom="16dp"
3636
android:background="#f3f5f8"
@@ -48,4 +48,4 @@
4848
app:layout_constraintEnd_toEndOf="parent"
4949
app:layout_constraintStart_toStartOf="parent" />
5050

51-
</androidx.constraintlayout.widget.ConstraintLayout>
51+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)