forked from github/szkolny
Merge pull request #91 from szkolny-eu/hotfix/messages
[UI] Various messages fixes.
This commit is contained in:
commit
a6aca42c8c
@ -146,25 +146,34 @@ class MessageFragment : Fragment(), CoroutineScope {
|
|||||||
else
|
else
|
||||||
app.db.messageDao().getByIdNow(App.profileId, messageId)
|
app.db.messageDao().getByIdNow(App.profileId, messageId)
|
||||||
|
|
||||||
|
if (msg == null)
|
||||||
|
return@withContext null
|
||||||
|
|
||||||
|
// make recipients ID-unique
|
||||||
|
// this helps when multiple profiles receive the same message
|
||||||
|
// (there are multiple -1 recipients for the same message ID)
|
||||||
|
val recipientsDistinct =
|
||||||
|
msg.recipients?.distinctBy { it.id } ?: return@withContext null
|
||||||
|
msg.recipients?.clear()
|
||||||
|
msg.recipients?.addAll(recipientsDistinct)
|
||||||
|
|
||||||
// load recipients in sent messages
|
// load recipients in sent messages
|
||||||
val teachers by lazy { app.db.teacherDao().getAllNow(App.profileId) }
|
val teachers by lazy { app.db.teacherDao().getAllNow(App.profileId) }
|
||||||
msg?.recipients?.forEach { recipient ->
|
msg.recipients?.forEach { recipient ->
|
||||||
if (recipient.fullName == null) {
|
if (recipient.fullName == null) {
|
||||||
recipient.fullName = teachers.firstOrNull { it.id == recipient.id }?.fullName ?: ""
|
recipient.fullName = teachers.firstOrNull { it.id == recipient.id }?.fullName ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg?.type == TYPE_SENT && msg.senderName == null) {
|
if (msg.type == TYPE_SENT && msg.senderName == null) {
|
||||||
msg.senderName = app.profile.accountName ?: app.profile.studentNameLong
|
msg.senderName = app.profile.accountName ?: app.profile.studentNameLong
|
||||||
}
|
}
|
||||||
|
|
||||||
msg?.also {
|
//msg.recipients = app.db.messageRecipientDao().getAllByMessageId(msg.profileId, msg.id)
|
||||||
//it.recipients = app.db.messageRecipientDao().getAllByMessageId(it.profileId, it.id)
|
if (msg.body != null && !msg.seen) {
|
||||||
if (it.body != null && !it.seen) {
|
app.db.metadataDao().setSeen(msg.profileId, msg, true)
|
||||||
app.db.metadataDao().setSeen(it.profileId, it, true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return@withContext msg
|
||||||
} ?: run {
|
} ?: run {
|
||||||
activity.navigateUp()
|
activity.navigateUp()
|
||||||
return@launch
|
return@launch
|
||||||
|
@ -62,10 +62,12 @@ class MessagesComposeChipCreator(
|
|||||||
Teacher.TYPE_EDUCATOR,
|
Teacher.TYPE_EDUCATOR,
|
||||||
Teacher.TYPE_STUDENT
|
Teacher.TYPE_STUDENT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val adapter = nacho.adapter as? MessagesComposeSuggestionAdapter ?: return null
|
||||||
val teachers = if (sortByCategory)
|
val teachers = if (sortByCategory)
|
||||||
teacherList.sortedBy { it.typeDescription }
|
adapter.originalList.sortedBy { it.typeDescription }
|
||||||
else
|
else
|
||||||
teacherList
|
adapter.originalList
|
||||||
|
|
||||||
val category = mutableListOf<Teacher>()
|
val category = mutableListOf<Teacher>()
|
||||||
val categoryNames = mutableListOf<CharSequence>()
|
val categoryNames = mutableListOf<CharSequence>()
|
||||||
|
@ -6,7 +6,6 @@ package pl.szczodrzynski.edziennik.ui.modules.views
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
@ -68,7 +67,10 @@ class AttachmentsView @JvmOverloads constructor(
|
|||||||
|
|
||||||
attachmentIds.forEachIndexed { index, id ->
|
attachmentIds.forEachIndexed { index, id ->
|
||||||
val name = attachmentNames[index] ?: return@forEachIndexed
|
val name = attachmentNames[index] ?: return@forEachIndexed
|
||||||
val size = attachmentSizes?.getOrNull(index)
|
var size = attachmentSizes?.getOrNull(index)
|
||||||
|
// hide the size if less than 1 byte
|
||||||
|
if (size?.compareTo(1) == -1)
|
||||||
|
size = null
|
||||||
|
|
||||||
val item = AttachmentAdapter.Item(profileId, owner, id, name, size)
|
val item = AttachmentAdapter.Item(profileId, owner, id, name, size)
|
||||||
adapter.items += item
|
adapter.items += item
|
||||||
@ -100,6 +102,8 @@ class AttachmentsView @JvmOverloads constructor(
|
|||||||
val fileUrl = item.name.substringAfter(":", missingDelimiterValue = "")
|
val fileUrl = item.name.substringAfter(":", missingDelimiterValue = "")
|
||||||
// update file name with the downloaded one
|
// update file name with the downloaded one
|
||||||
item.name = attachmentFile.name
|
item.name = attachmentFile.name
|
||||||
|
// update file size (useful for items with no defined size)
|
||||||
|
item.size = attachmentFile.length()
|
||||||
// save the download url back
|
// save the download url back
|
||||||
if (fileUrl != "")
|
if (fileUrl != "")
|
||||||
item.name += ":$fileUrl"
|
item.name += ":$fileUrl"
|
||||||
|
Loading…
Reference in New Issue
Block a user