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

Commit e2ae865

Browse files
authored
Merge branch 'master' into chore/sdk-changes
2 parents f4f3123 + 62d12ce commit e2ae865

File tree

10 files changed

+343
-260
lines changed

10 files changed

+343
-260
lines changed

app/src/main/java/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class ChatRoomAdapter(
173173
notifyDataSetChanged()
174174
}
175175

176-
fun updateItem(message: BaseUiModel<*>): Boolean {
176+
// FIXME What's 0,1 and 2 means for here?
177+
fun updateItem(message: BaseUiModel<*>): Int {
177178
val index = dataSet.indexOfLast { it.messageId == message.messageId }
178179
val indexOfNext = dataSet.indexOfFirst { it.messageId == message.messageId }
179180
Timber.d("index: $index")
@@ -184,17 +185,23 @@ class ChatRoomAdapter(
184185
if (viewModel.nextDownStreamMessage == null) {
185186
viewModel.reactions = message.reactions
186187
}
187-
notifyItemChanged(ind)
188+
189+
if (ind > 0 &&
190+
dataSet[ind].message.timestamp > dataSet[ind - 1].message.timestamp) {
191+
return 2
192+
} else {
193+
notifyItemChanged(ind)
194+
}
188195
}
189196
}
190197
// Delete message only if current is a system message update, i.e.: Message Removed
191198
if (message.message.isSystemMessage() && indexOfNext > -1 && indexOfNext != index) {
192199
dataSet.removeAt(indexOfNext)
193200
notifyItemRemoved(indexOfNext)
194201
}
195-
return true
202+
return 0
196203
}
197-
return false
204+
return 1
198205
}
199206

200207
fun removeItem(messageId: String) {

app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,13 @@ class ChatRoomPresenter @Inject constructor(
359359
val id = UUID.randomUUID().toString()
360360
val username = userHelper.username()
361361
val user = userHelper.user()
362+
val timestamp = maxOf(getTimeStampOfLastMessageInRoom() + 1,
363+
Instant.now().toEpochMilli())
362364
val newMessage = Message(
363365
id = id,
364366
roomId = chatRoomId,
365367
message = text,
366-
timestamp = Instant.now().toEpochMilli(),
368+
timestamp = timestamp,
367369
sender = SimpleUser(user?.id, user?.username ?: username, user?.name),
368370
attachments = null,
369371
avatar = currentServer.avatarUrl(
@@ -1389,4 +1391,12 @@ class ChatRoomPresenter @Inject constructor(
13891391
fun getDraftUnfinishedMessage(): String? {
13901392
return localRepository.get(draftKey)
13911393
}
1394+
1395+
private suspend fun getTimeStampOfLastMessageInRoom(): Long {
1396+
return withContext(Dispatchers.IO + strategy.jobs) {
1397+
chatRoomId?.let {
1398+
dbManager.messageDao().getRecentMessagesByRoomId(it, 1).first().message.message.timestamp
1399+
}
1400+
} ?: 0
1401+
}
13921402
}

app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt

+16-6
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
536536
if (newMessageCount <= 99) {
537537
text_count.text = newMessageCount.toString()
538538
} else {
539-
text_count.text = "99+"
539+
text_count.text = getString(R.string.msg_more_than_ninety_nine_unread_messages)
540540
}
541541
text_count.isVisible = true
542542
} else if (!button_fab.isVisible) {
@@ -553,12 +553,22 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
553553
// TODO - investigate WHY we get a empty list here
554554
if (message.isEmpty()) return@ui
555555

556-
if (chatRoomAdapter.updateItem(message.last())) {
557-
if (message.size > 1) {
558-
chatRoomAdapter.prependData(listOf(message.first()))
556+
when (chatRoomAdapter.updateItem(message.last())) {
557+
// FIXME: What's 0,1 and 2 means for here?
558+
0 -> {
559+
if (message.size > 1) {
560+
chatRoomAdapter.prependData(listOf(message.first()))
561+
}
562+
}
563+
1 -> showNewMessage(message, true)
564+
2 -> {
565+
// Position of new sent message is wrong because of device local time is behind server time
566+
with(chatRoomAdapter) {
567+
removeItem(message.last().messageId)
568+
prependData(listOf(message.last()))
569+
notifyDataSetChanged()
570+
}
559571
}
560-
} else {
561-
showNewMessage(message, true)
562572
}
563573
dismissEmojiKeyboard()
564574
}

app/src/main/java/chat/rocket/android/directory/ui/DirectorySortingBottomSheetFragment.kt

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package chat.rocket.android.directory.ui
22

33
import DrawableHelper
4-
import android.content.DialogInterface
54
import android.graphics.drawable.Drawable
65
import android.os.Bundle
76
import android.view.LayoutInflater
@@ -10,6 +9,8 @@ import android.view.ViewGroup
109
import android.widget.TextView
1110
import androidx.fragment.app.FragmentManager
1211
import chat.rocket.android.R
12+
import com.google.android.material.bottomsheet.BottomSheetBehavior
13+
import com.google.android.material.bottomsheet.BottomSheetDialog
1314
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
1415
import kotlinx.android.synthetic.main.bottom_sheet_fragment_directory_sorting.*
1516

@@ -67,10 +68,6 @@ class DirectorySortingBottomSheetFragment : BottomSheetDialogFragment() {
6768
setupListeners()
6869
}
6970

70-
override fun onCancel(dialog: DialogInterface?) {
71-
super.onCancel(dialog)
72-
}
73-
7471
private fun setupView() {
7572
if (isSortByChannels) {
7673
checkSelection(text_channels, hashtagDrawable)
@@ -82,6 +79,15 @@ class DirectorySortingBottomSheetFragment : BottomSheetDialogFragment() {
8279
}
8380

8481
private fun setupListeners() {
82+
dialog.setOnShowListener { dialog ->
83+
val bottomSheet = (dialog as BottomSheetDialog).findViewById<View>(
84+
com.google.android.material.R.id.design_bottom_sheet
85+
)
86+
bottomSheet?.let {
87+
BottomSheetBehavior.from(bottomSheet).peekHeight = bottomSheet.height
88+
}
89+
}
90+
8591
text_channels.setOnClickListener {
8692
checkSelection(text_channels, hashtagDrawable)
8793
uncheckSelection(text_users, userDrawable)

app/src/main/java/chat/rocket/android/servers/ui/ServersBottomSheetFragment.kt

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import chat.rocket.android.servers.adapter.ServersAdapter
1212
import chat.rocket.android.servers.presentation.ServersPresenter
1313
import chat.rocket.android.servers.presentation.ServersView
1414
import chat.rocket.android.util.extensions.showToast
15+
import com.google.android.material.bottomsheet.BottomSheetBehavior
16+
import com.google.android.material.bottomsheet.BottomSheetDialog
1517
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
1618
import dagger.android.support.AndroidSupportInjection
1719
import kotlinx.android.synthetic.main.bottom_sheet_fragment_servers.*
@@ -38,6 +40,18 @@ class ServersBottomSheetFragment : BottomSheetDialogFragment(), ServersView {
3840
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3941
super.onViewCreated(view, savedInstanceState)
4042
presenter.getAllServers()
43+
setupListeners()
44+
}
45+
46+
private fun setupListeners() {
47+
dialog.setOnShowListener { dialog ->
48+
val bottomSheet = (dialog as BottomSheetDialog).findViewById<View>(
49+
com.google.android.material.R.id.design_bottom_sheet
50+
)
51+
bottomSheet?.let {
52+
BottomSheetBehavior.from(bottomSheet).peekHeight = bottomSheet.height
53+
}
54+
}
4155
}
4256

4357
override fun showServerList(serverList: List<Account>, currentServerUrl: String) {

app/src/main/java/chat/rocket/android/sortingandgrouping/ui/SortingAndGroupingBottomSheetFragment.kt

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import chat.rocket.android.chatrooms.ui.ChatRoomsFragment
1313
import chat.rocket.android.chatrooms.ui.TAG_CHAT_ROOMS_FRAGMENT
1414
import chat.rocket.android.sortingandgrouping.presentation.SortingAndGroupingPresenter
1515
import chat.rocket.android.sortingandgrouping.presentation.SortingAndGroupingView
16+
import com.google.android.material.bottomsheet.BottomSheetBehavior
17+
import com.google.android.material.bottomsheet.BottomSheetDialog
1618
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
1719
import dagger.android.support.AndroidSupportInjection
1820
import kotlinx.android.synthetic.main.bottom_sheet_fragment_sort_by.*
@@ -89,6 +91,15 @@ class SortingAndGroupingBottomSheetFragment : BottomSheetDialogFragment(), Sorti
8991
}
9092

9193
private fun setupListeners() {
94+
dialog.setOnShowListener { dialog ->
95+
val bottomSheet = (dialog as BottomSheetDialog).findViewById<View>(
96+
com.google.android.material.R.id.design_bottom_sheet
97+
)
98+
bottomSheet?.let {
99+
BottomSheetBehavior.from(bottomSheet).peekHeight = bottomSheet.height
100+
}
101+
}
102+
92103
text_name.setOnClickListener {
93104
changeSortByTitle(getString(R.string.msg_sort_by_name))
94105
checkSelection(text_name, filterDrawable)
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
6+
android:layout_height="wrap_content"
7+
android:orientation="vertical"
78
tools:context=".directory.ui.DirectorySortingBottomSheetFragment">
89

910
<TextView
@@ -16,96 +17,106 @@
1617
android:text="@string/msg_sort_by"
1718
android:textColor="#9EA2A8"
1819
android:textSize="17sp"
19-
android:textStyle="normal"
20-
app:layout_constraintStart_toStartOf="parent"
21-
app:layout_constraintTop_toTopOf="parent" />
20+
android:textStyle="normal" />
2221

2322
<View
2423
android:id="@+id/view_divider_one"
2524
android:layout_width="match_parent"
2625
android:layout_height="1dp"
2726
android:layout_marginTop="16dp"
28-
android:background="#1F000000"
29-
app:layout_constraintTop_toBottomOf="@+id/text_sort_by" />
27+
android:background="#1F000000" />
3028

31-
<TextView
32-
android:id="@+id/text_channels"
29+
<androidx.core.widget.NestedScrollView
3330
android:layout_width="match_parent"
34-
android:layout_height="wrap_content"
35-
android:drawableStart="@drawable/ic_hashtag_16dp"
36-
android:drawablePadding="16dp"
37-
android:paddingStart="16dp"
38-
android:paddingTop="16dp"
39-
android:paddingEnd="16dp"
40-
android:paddingBottom="16dp"
41-
android:text="@string/msg_channels"
42-
android:textColor="#2F343D"
43-
android:textSize="16sp"
44-
android:textStyle="normal"
45-
app:layout_constraintTop_toBottomOf="@+id/view_divider_one" />
31+
android:layout_height="wrap_content">
4632

47-
<TextView
48-
android:id="@+id/text_users"
49-
android:layout_width="match_parent"
50-
android:layout_height="wrap_content"
51-
android:drawableStart="@drawable/ic_user_16dp"
52-
android:drawablePadding="16dp"
53-
android:paddingStart="16dp"
54-
android:paddingTop="16dp"
55-
android:paddingEnd="16dp"
56-
android:paddingBottom="16dp"
57-
android:text="@string/msg_users"
58-
android:textColor="#2F343D"
59-
android:textSize="16sp"
60-
android:textStyle="normal"
61-
app:layout_constraintTop_toBottomOf="@+id/text_channels" />
33+
<androidx.constraintlayout.widget.ConstraintLayout
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content">
6236

63-
<View
64-
android:id="@+id/view_divider_two"
65-
android:layout_width="match_parent"
66-
android:layout_height="1dp"
67-
android:layout_marginStart="16dp"
68-
android:layout_marginEnd="16dp"
69-
android:background="#1F000000"
70-
app:layout_constraintTop_toBottomOf="@+id/text_users" />
37+
<TextView
38+
android:id="@+id/text_channels"
39+
android:layout_width="match_parent"
40+
android:layout_height="wrap_content"
41+
android:drawableStart="@drawable/ic_hashtag_16dp"
42+
android:drawablePadding="16dp"
43+
android:paddingStart="16dp"
44+
android:paddingTop="16dp"
45+
android:paddingEnd="16dp"
46+
android:paddingBottom="16dp"
47+
android:text="@string/msg_channels"
48+
android:textColor="#2F343D"
49+
android:textSize="16sp"
50+
android:textStyle="normal"
51+
app:layout_constraintStart_toStartOf="parent"
52+
app:layout_constraintTop_toTopOf="parent" />
7153

72-
<TextView
73-
android:id="@+id/text_search_for_global_users"
74-
android:layout_width="wrap_content"
75-
android:layout_height="wrap_content"
76-
android:paddingStart="16dp"
77-
android:paddingTop="16dp"
78-
android:paddingEnd="16dp"
79-
android:text="@string/msg_search_for_global_users"
80-
android:textColor="#2F343D"
81-
android:textSize="16sp"
82-
android:textStyle="normal"
83-
app:layout_constraintStart_toStartOf="parent"
84-
app:layout_constraintTop_toBottomOf="@+id/view_divider_two" />
54+
<TextView
55+
android:id="@+id/text_users"
56+
android:layout_width="match_parent"
57+
android:layout_height="wrap_content"
58+
android:drawableStart="@drawable/ic_user_16dp"
59+
android:drawablePadding="16dp"
60+
android:paddingStart="16dp"
61+
android:paddingTop="16dp"
62+
android:paddingEnd="16dp"
63+
android:paddingBottom="16dp"
64+
android:text="@string/msg_users"
65+
android:textColor="#2F343D"
66+
android:textSize="16sp"
67+
android:textStyle="normal"
68+
app:layout_constraintTop_toBottomOf="@+id/text_channels" />
8569

86-
<Switch
87-
android:id="@+id/switch_global_users"
88-
android:layout_width="wrap_content"
89-
android:layout_height="wrap_content"
90-
android:layout_marginTop="16dp"
91-
android:layout_marginEnd="16dp"
92-
android:checked="false"
93-
app:layout_constraintBottom_toBottomOf="@+id/text_search_for_global_users"
94-
app:layout_constraintEnd_toEndOf="parent"
95-
app:layout_constraintTop_toTopOf="@+id/text_search_for_global_users" />
70+
<View
71+
android:id="@+id/view_divider_two"
72+
android:layout_width="match_parent"
73+
android:layout_height="1dp"
74+
android:layout_marginStart="16dp"
75+
android:layout_marginEnd="16dp"
76+
android:background="#1F000000"
77+
app:layout_constraintTop_toBottomOf="@+id/text_users" />
9678

97-
<TextView
98-
android:id="@+id/text_search_for_global_users_description"
99-
android:layout_width="wrap_content"
100-
android:layout_height="wrap_content"
101-
android:paddingStart="16dp"
102-
android:paddingEnd="16dp"
103-
android:paddingBottom="16dp"
104-
android:text="@string/msg_search_for_global_users_description"
105-
android:textColor="#9EA2A8"
106-
android:textSize="14sp"
107-
android:textStyle="normal"
108-
app:layout_constraintStart_toStartOf="parent"
109-
app:layout_constraintTop_toBottomOf="@+id/text_search_for_global_users" />
79+
<TextView
80+
android:id="@+id/text_search_for_global_users"
81+
android:layout_width="wrap_content"
82+
android:layout_height="wrap_content"
83+
android:paddingStart="16dp"
84+
android:paddingTop="16dp"
85+
android:paddingEnd="16dp"
86+
android:text="@string/msg_search_for_global_users"
87+
android:textColor="#2F343D"
88+
android:textSize="16sp"
89+
android:textStyle="normal"
90+
app:layout_constraintStart_toStartOf="parent"
91+
app:layout_constraintTop_toBottomOf="@+id/view_divider_two" />
92+
93+
<Switch
94+
android:id="@+id/switch_global_users"
95+
android:layout_width="wrap_content"
96+
android:layout_height="wrap_content"
97+
android:layout_marginTop="16dp"
98+
android:layout_marginEnd="16dp"
99+
android:checked="false"
100+
app:layout_constraintBottom_toBottomOf="@+id/text_search_for_global_users"
101+
app:layout_constraintEnd_toEndOf="parent"
102+
app:layout_constraintTop_toTopOf="@+id/text_search_for_global_users" />
103+
104+
<TextView
105+
android:id="@+id/text_search_for_global_users_description"
106+
android:layout_width="wrap_content"
107+
android:layout_height="wrap_content"
108+
android:paddingStart="16dp"
109+
android:paddingEnd="16dp"
110+
android:paddingBottom="16dp"
111+
android:text="@string/msg_search_for_global_users_description"
112+
android:textColor="#9EA2A8"
113+
android:textSize="14sp"
114+
android:textStyle="normal"
115+
app:layout_constraintStart_toStartOf="parent"
116+
app:layout_constraintTop_toBottomOf="@+id/text_search_for_global_users" />
117+
118+
</androidx.constraintlayout.widget.ConstraintLayout>
119+
120+
</androidx.core.widget.NestedScrollView>
110121

111-
</androidx.constraintlayout.widget.ConstraintLayout>
122+
</LinearLayout>

0 commit comments

Comments
 (0)