Merge pull request #5905 from osmandapp/UiImprovements
Add locHistoryTime setting to LiveNowTabFragment
This commit is contained in:
commit
420e50d48c
3 changed files with 28 additions and 19 deletions
|
@ -144,9 +144,10 @@ class TelegramHelper private constructor() {
|
|||
|
||||
fun getChatLiveMessages() = chatLiveMessages
|
||||
|
||||
fun getMessagesByChatIds(): Map<Long, List<TdApi.Message>> {
|
||||
fun getMessagesByChatIds(messageExpTime: Long): Map<Long, List<TdApi.Message>> {
|
||||
val res = mutableMapOf<Long, MutableList<TdApi.Message>>()
|
||||
for (message in usersLocationMessages.values) {
|
||||
if (System.currentTimeMillis() / 1000 - getLastUpdatedTime(message) < messageExpTime) {
|
||||
var messages = res[message.chatId]
|
||||
if (messages != null) {
|
||||
messages.add(message)
|
||||
|
@ -155,6 +156,7 @@ class TelegramHelper private constructor() {
|
|||
res[message.chatId] = messages
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -178,10 +180,19 @@ class TelegramHelper private constructor() {
|
|||
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
|
||||
}
|
||||
|
||||
fun getLastUpdatedTime(message: TdApi.Message) = Math.max(message.editDate, message.date)
|
||||
fun getLastUpdatedTime(message: TdApi.Message): Int {
|
||||
val content = message.content
|
||||
return if (content is MessageOsmAndBotLocation) {
|
||||
content.lastUpdated
|
||||
} else {
|
||||
Math.max(message.editDate, message.date)
|
||||
}
|
||||
}
|
||||
|
||||
fun isPrivateChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypePrivate
|
||||
|
||||
fun isSecretChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypeSecret
|
||||
|
||||
private fun isChannel(chat: TdApi.Chat): Boolean {
|
||||
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
|
||||
}
|
||||
|
@ -322,6 +333,12 @@ class TelegramHelper private constructor() {
|
|||
return deviceName
|
||||
}
|
||||
|
||||
fun getUserIdFromChatType(type: TdApi.ChatType) = when (type) {
|
||||
is TdApi.ChatTypePrivate -> type.userId
|
||||
is TdApi.ChatTypeSecret -> type.userId
|
||||
else -> 0
|
||||
}
|
||||
|
||||
fun isOsmAndBot(userId: Int) = users[userId]?.username == OSMAND_BOT_USERNAME
|
||||
|
||||
fun isBot(userId: Int) = users[userId]?.type is TdApi.UserTypeBot
|
||||
|
@ -882,8 +899,6 @@ class TelegramHelper private constructor() {
|
|||
internal set
|
||||
var lastUpdated: Int = 0
|
||||
internal set
|
||||
var created: Int = 0
|
||||
internal set
|
||||
|
||||
override fun getConstructor() = -1
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ object TelegramUiHelper {
|
|||
}
|
||||
val type = chat.type
|
||||
if (type is TdApi.ChatTypePrivate || type is TdApi.ChatTypeSecret) {
|
||||
val userId = getUserIdFromChatType(type)
|
||||
val userId = helper.getUserIdFromChatType(type)
|
||||
val chatWithBot = helper.isBot(userId)
|
||||
res.privateChat = true
|
||||
res.chatWithBot = chatWithBot
|
||||
|
@ -82,12 +82,6 @@ object TelegramUiHelper {
|
|||
return res
|
||||
}
|
||||
|
||||
private fun getUserIdFromChatType(type: TdApi.ChatType) = when (type) {
|
||||
is TdApi.ChatTypePrivate -> type.userId
|
||||
is TdApi.ChatTypeSecret -> type.userId
|
||||
else -> 0
|
||||
}
|
||||
|
||||
fun getUserName(user: TdApi.User): String {
|
||||
var name = "${user.firstName} ${user.lastName}".trim()
|
||||
if (name.isEmpty()) {
|
||||
|
|
|
@ -212,13 +212,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
|
||||
private fun updateLocationUi() {
|
||||
if (locationUiUpdateAllowed) {
|
||||
app.runInUIThread { adapter.notifyDataSetChanged() }
|
||||
app.runInUIThread { updateList() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateList() {
|
||||
val res = mutableListOf<ListItem>()
|
||||
for ((id, messages) in telegramHelper.getMessagesByChatIds()) {
|
||||
for ((id, messages) in telegramHelper.getMessagesByChatIds(settings.locHistoryTime)) {
|
||||
telegramHelper.getChat(id)?.also { chat ->
|
||||
res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
||||
val type = chat.type
|
||||
|
|
Loading…
Reference in a new issue