Show locations from osmand_bot in "Live now" list

This commit is contained in:
Alex Sytnyk 2018-07-04 13:26:40 +03:00
parent 906abf1aef
commit 211a5fecf8
2 changed files with 17 additions and 5 deletions

View file

@ -20,12 +20,13 @@ import kotlin.collections.HashSet
class TelegramHelper private constructor() {
companion object {
const val OSMAND_BOT_USERNAME = "osmand_bot"
private val log = PlatformUtil.getLog(TelegramHelper::class.java)
private const val CHATS_LIMIT = 100
private const val IGNORED_ERROR_CODE = 406
private const val UPDATE_LIVE_MESSAGES_INTERVAL_SEC = 30L
private const val MESSAGE_ACTIVE_TIME_SEC = 24 * 60 * 60 // 24 hours
private const val OSMAND_BOT_USERNAME = "osmand_bot"
// min and max values for the Telegram API
const val MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 61

View file

@ -13,6 +13,7 @@ import android.widget.TextView
import android.widget.Toast
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.helpers.TelegramHelper
import net.osmand.telegram.helpers.TelegramHelper.*
import net.osmand.telegram.helpers.TelegramUiHelper
import org.drinkless.td.libcore.telegram.TdApi
@ -103,14 +104,19 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
private fun updateList() {
val res = mutableListOf<Any>()
for ((id, messages) in telegramHelper.getMessagesByChatIds()) {
telegramHelper.getChat(id)?.let { chat ->
telegramHelper.getChat(id)?.also { chat ->
res.add(chat)
if (chat.type is TdApi.ChatTypeBasicGroup || chat.type is TdApi.ChatTypeSupergroup) {
val type = chat.type
if (type is TdApi.ChatTypeBasicGroup || type is TdApi.ChatTypeSupergroup) {
messages.forEach { message ->
telegramHelper.getUser(message.senderUserId)?.let { user ->
res.add(user)
if (message.content is MessageOsmAndBotLocation) {
res.add(message.content)
} else {
telegramHelper.getUser(message.senderUserId)?.also { res.add(it) }
}
}
} else if (type is TdApi.ChatTypePrivate && telegramHelper.getUser(type.userId)?.username == TelegramHelper.OSMAND_BOT_USERNAME) {
res.addAll(messages.filter { it.content is MessageOsmAndBotLocation })
}
}
}
@ -195,6 +201,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.title?.text = "${item.firstName} ${item.lastName}"
holder.description?.text = "User description" // FIXME
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
} else if (item is MessageOsmAndBotLocation && holder is ContactViewHolder) {
holder.icon?.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_group))
holder.title?.text = item.name
holder.description?.text = "Location from osmand_bot" // FIXME
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
}
}