Skip to content

Commit a2c4ffa

Browse files
feat: Show draft message in case the conversation has one attached to it
also fixing the issue that before when fetching the conversations from the server, the server-state has been exposed to the UI, not the upserted state from DB including the client-side only data. AI-assistant: Claude Code v2.1.76 (Claude Sonnet 4.6) Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent c525e03 commit a2c4ffa

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ class ConversationItem(
246246
}
247247

248248
private fun setLastMessage(holder: ConversationItemViewHolder, appContext: Context) {
249+
val draftText = model.messageDraft?.messageText?.takeIf { it.isNotBlank() }
250+
if (draftText != null) {
251+
showDraft(holder, appContext, draftText)
252+
return
253+
}
254+
255+
holder.binding.dialogLastMessage.setTextColor(
256+
ContextCompat.getColor(context, R.color.textColorMaxContrast)
257+
)
258+
249259
if (chatMessage != null) {
250260
holder.binding.dialogDate.visibility = View.VISIBLE
251261
holder.binding.dialogDate.text = DateUtils.getRelativeTimeSpanString(
@@ -277,6 +287,19 @@ class ConversationItem(
277287
}
278288
}
279289

290+
private fun showDraft(holder: ConversationItemViewHolder, appContext: Context, draftText: String) {
291+
holder.binding.dialogDate.visibility = View.VISIBLE
292+
holder.binding.dialogDate.text = DateUtils.getRelativeTimeSpanString(
293+
model.lastActivity * MILLIES,
294+
System.currentTimeMillis(),
295+
0,
296+
DateUtils.FORMAT_ABBREV_RELATIVE
297+
)
298+
299+
val label = String.format(appContext.getString(R.string.nc_draft_prefix), draftText)
300+
viewThemeUtils.talk.themeDraftSubline(holder.binding.dialogLastMessage, label, draftText)
301+
}
302+
280303
private fun calculateRegularLastMessageText(appContext: Context): CharSequence =
281304
if (chatMessage?.actorId == user.userId) {
282305
String.format(

app/src/main/java/com/nextcloud/talk/conversationlist/data/network/OfflineFirstConversationsRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class OfflineFirstConversationsRepository @Inject constructor(
5858
if (networkMonitor.isOnline.value) {
5959
val conversationEntitiesFromSync = getRoomsFromServer(user)
6060
if (!conversationEntitiesFromSync.isNullOrEmpty()) {
61-
val conversationModelsFromSync = conversationEntitiesFromSync.map(ConversationEntity::asModel)
61+
val conversationModelsFromSync = getListOfConversations(user.id!!)
6262
_roomListFlow.emit(conversationModelsFromSync)
6363
}
6464
}

app/src/main/java/com/nextcloud/talk/ui/theme/TalkSpecificViewThemeUtils.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,28 @@ class TalkSpecificViewThemeUtils @Inject constructor(
325325
}
326326
}
327327

328+
fun themeDraftSubline(textView: TextView, fullText: String, draftText: String) {
329+
withScheme(textView) { scheme ->
330+
val prefixEnd = fullText.length - draftText.length
331+
val spannable = android.text.SpannableStringBuilder(fullText)
332+
spannable.setSpan(
333+
StyleSpan(Typeface.BOLD),
334+
0,
335+
prefixEnd,
336+
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
337+
)
338+
spannable.setSpan(
339+
ForegroundColorSpan(dynamicColor.primary().getArgb(scheme)),
340+
0,
341+
prefixEnd,
342+
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
343+
)
344+
textView.setTypeface(null, Typeface.NORMAL)
345+
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.textColorMaxContrast))
346+
textView.setText(spannable, TextView.BufferType.SPANNABLE)
347+
}
348+
}
349+
328350
fun themeForegroundColorSpan(context: Context): ForegroundColorSpan {
329351
return withScheme(context) { scheme ->
330352
return@withScheme ForegroundColorSpan(dynamicColor.primary().getArgb(scheme))

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ How to translate with transifex:
465465
<string name="nc_message_quote_cancel_reply">Cancel reply</string>
466466
<!-- When translating to German, please use non-formal variant -->
467467
<string name="nc_formatted_message_you">You: %1$s</string>
468+
<string name="nc_draft_prefix">Draft: %1$s</string>
468469
<string name="nc_message_read">Message read</string>
469470
<string name="nc_message_sent">Message sent</string>
470471
<string name="nc_message_added_to_notes">Message added to notes</string>

0 commit comments

Comments
 (0)