@@ -35,6 +35,8 @@ import com.nextcloud.talk.R
3535import com.nextcloud.talk.chat.UnreadMessagesPopup
3636import com.nextcloud.talk.chat.data.model.ChatMessage
3737import com.nextcloud.talk.chat.viewmodels.ChatViewModel
38+ import com.nextcloud.talk.chat.viewmodels.ChatViewModel.ChatItem.DateHeaderItem
39+ import com.nextcloud.talk.chat.viewmodels.ChatViewModel.ChatItem.MessageItem
3840import com.nextcloud.talk.data.user.model.User
3941import kotlinx.coroutines.Dispatchers
4042import kotlinx.coroutines.delay
@@ -128,11 +130,53 @@ fun GetNewChatView(
128130 LazyColumn (
129131 state = listState,
130132 verticalArrangement = Arrangement .spacedBy(8 .dp),
131- reverseLayout = true ,
133+ reverseLayout = false ,
132134 modifier = Modifier
133135 .padding(16 .dp)
134136 .fillMaxSize()
135137 ) {
138+ stickyHeader {
139+ if (chatItems.isEmpty()) {
140+ Column (
141+ verticalArrangement = Arrangement .Center ,
142+ horizontalAlignment = Alignment .CenterHorizontally ,
143+ modifier = Modifier .fillMaxSize()
144+ ) {
145+ ShimmerGroup ()
146+ }
147+ } else {
148+ val item = chatItems[listState.firstVisibleItemIndex]
149+ val dateString = when (item) {
150+ is MessageItem -> formatTime(item.message.timestamp * LONG_1000 )
151+ is DateHeaderItem -> formatTime(item.date)
152+ }
153+ val color = colorScheme.onSurfaceVariant
154+ val backgroundColor =
155+ LocalResources .current.getColor(R .color.bg_message_list_incoming_bubble, null )
156+ Row (
157+ horizontalArrangement = Arrangement .Absolute .Center ,
158+ verticalAlignment = Alignment .CenterVertically
159+ ) {
160+ Spacer (modifier = Modifier .weight(1f ))
161+ Text (
162+ dateString,
163+ fontSize = AUTHOR_TEXT_SIZE ,
164+ color = color,
165+ modifier = Modifier
166+ .padding(8 .dp)
167+ .shadow(
168+ 16 .dp,
169+ spotColor = colorScheme.primary,
170+ ambientColor = colorScheme.primary
171+ )
172+ .background(color = Color (backgroundColor), shape = RoundedCornerShape (8 .dp))
173+ .padding(8 .dp)
174+ )
175+ Spacer (modifier = Modifier .weight(1f ))
176+ }
177+ }
178+ }
179+
136180 items(
137181 displayedChatItems,
138182 key = {
@@ -364,8 +408,17 @@ private fun ChatMessage.shouldFilter(): Boolean =
364408fun formatTime (timestampMillis : Long ): String {
365409 val instant = Instant .ofEpochMilli(timestampMillis)
366410 val dateTime = instant.atZone(ZoneId .systemDefault()).toLocalDate()
411+ return formatTime(dateTime)
412+ }
413+
414+ fun formatTime (localDate : LocalDate ): String {
367415 val formatter = DateTimeFormatter .ofPattern(" MMM dd, yyyy" )
368- return dateTime.format(formatter)
416+ val text = when (localDate) {
417+ LocalDate .now() -> " Today"
418+ LocalDate .now().minusDays(1 ) -> " Yesterday"
419+ else -> localDate.format(formatter)
420+ }
421+ return text
369422}
370423
371424fun searchMessages (messages : List <ChatMessage >, searchId : String ): Int {
0 commit comments