Merge pull request #5905 from osmandapp/UiImprovements

Add locHistoryTime setting to LiveNowTabFragment
This commit is contained in:
Alexander Sytnyk 2018-08-28 12:00:41 +03:00 committed by GitHub
commit 420e50d48c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 19 deletions

View file

@ -144,15 +144,17 @@ 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) {
var messages = res[message.chatId]
if (messages != null) {
messages.add(message)
} else {
messages = mutableListOf(message)
res[message.chatId] = messages
if (System.currentTimeMillis() / 1000 - getLastUpdatedTime(message) < messageExpTime) {
var messages = res[message.chatId]
if (messages != null) {
messages.add(message)
} else {
messages = mutableListOf(message)
res[message.chatId] = messages
}
}
}
return res
@ -178,9 +180,18 @@ 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

View file

@ -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()) {

View file

@ -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