Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit d4ebb4b

Browse files
committed
add markAsRead functionality
1 parent 56bc23c commit d4ebb4b

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

app/src/main/java/chat/rocket/android/chatrooms/adapter/RoomsAdapter.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package chat.rocket.android.chatrooms.adapter
22

3+
import android.util.Log
34
import android.view.MenuItem
45
import android.view.ViewGroup
56
import androidx.recyclerview.widget.RecyclerView
67
import chat.rocket.android.R
78
import chat.rocket.android.chatroom.uimodel.toViewType
89
import chat.rocket.android.chatrooms.adapter.model.RoomUiModel
910
import chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter
11+
import chat.rocket.android.util.extensions.ifNotNullNorEmpty
1012
import chat.rocket.android.util.extensions.inflate
13+
import chat.rocket.common.util.ifNull
1114

1215
class RoomsAdapter(private val listener: (RoomUiModel) -> Unit, presenter: ChatRoomsPresenter) :
1316
RecyclerView.Adapter<ViewHolder<*>>() {
@@ -85,7 +88,7 @@ class RoomsAdapter(private val listener: (RoomUiModel) -> Unit, presenter: ChatR
8588

8689
}
8790
R.id.action_read->{
88-
91+
this.unread.ifNotNullNorEmpty{ presenter.markRoomAsRead(this.id) }
8992
}
9093
R.id.action_hide_room->{
9194

app/src/main/java/chat/rocket/android/chatrooms/adapter/ViewHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class ViewHolder<T : ItemHolder<*>>(
5151
val menuItems = view.context.inflate(R.menu.chatrooms_action).toList()
5252
menuItems.find { it.itemId == R.id.action_favorite_room }?.apply {
5353
setTitle(if ((it as RoomUiModel).favorite == true) R.string.title_unfavorite_chat else R.string.title_favorite_chat)
54-
setIcon(if (it.favorite == true) R.drawable.ic_star_yellow_24dp else R.drawable.ic_star_border_black_24dp)
54+
setIcon(if (it.favorite == true) R.drawable.ic_star_black_24dp else R.drawable.ic_star_border_black_24dp)
5555
isChecked = (it.favorite==true)
5656
}
5757
view.context?.let {

app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import chat.rocket.common.model.roomTypeOf
2323
import chat.rocket.common.util.ifNull
2424
import chat.rocket.core.internal.realtime.createDirectMessage
2525
import chat.rocket.core.internal.rest.favorite
26+
import chat.rocket.core.internal.rest.markAsRead
2627
import chat.rocket.core.internal.rest.me
2728
import chat.rocket.core.internal.rest.show
2829
import kotlinx.coroutines.withTimeout
@@ -165,6 +166,17 @@ class ChatRoomsPresenter @Inject constructor(
165166
}
166167
}
167168

169+
fun markRoomAsRead(roomId: String) {
170+
launchUI(strategy) {
171+
try {
172+
retryIO(description = "markAsRead($roomId)") { client.markAsRead(roomId) }
173+
} catch (ex: RocketChatException) {
174+
view.showMessage(ex.message!!) // TODO Remove.
175+
Timber.e(ex) // FIXME: Right now we are only catching the exception with Timber.
176+
}
177+
}
178+
}
179+
168180
private suspend fun getCurrentUser(): User? {
169181
userHelper.user()?.let {
170182
return it
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
9+
</vector>

0 commit comments

Comments
 (0)