From 50e736f5a2e381cd5f6855f4a04b1bda285b2b84 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 3 Aug 2018 12:21:23 +0300 Subject: [PATCH 01/16] parse new map locations --- .../src/net/osmand/telegram/helpers/ShowLocationHelper.kt | 3 +++ .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 7 +++++++ .../src/net/osmand/telegram/helpers/TelegramUiHelper.kt | 3 +++ 3 files changed, 13 insertions(+) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index 8c82b8665f..043edbc6fc 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -79,6 +79,9 @@ class ShowLocationHelper(private val app: TelegramApplication) { if (userName.isEmpty()) { userName = user.phoneNumber } + if (telegramHelper.isOsmAndBot(user.id)) { + userName = telegramHelper.getOsmAndBotDeviceName(message) + } photoPath = telegramHelper.getUserPhotoPath(user) } if (userName.isEmpty()) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 3cd053c849..f2b53239e2 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -253,6 +253,13 @@ class TelegramHelper private constructor() { } } + fun getOsmAndBotDeviceName(message: TdApi.Message): String { + val replyMarkup = + message.replyMarkup as TdApi.ReplyMarkupInlineKeyboard + val deviceName = replyMarkup.rows[0][1].text + return deviceName.split("\\s".toRegex())[1] + } + fun isOsmAndBot(userId: Int) = users[userId]?.username == OSMAND_BOT_USERNAME fun isBot(userId: Int) = users[userId]?.type is TdApi.UserTypeBot diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index 7837d145b3..96e9d28f30 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -131,6 +131,9 @@ object TelegramUiHelper { if (name.isEmpty()) { name = user.phoneNumber } + if (helper.isOsmAndBot(user.id)) { + name = helper.getOsmAndBotDeviceName(message) + } latLon = LatLon(content.location.latitude, content.location.longitude) photoPath = helper.getUserPhotoPath(user) placeholderId = R.drawable.img_user_picture From b1ea1e5db7e88c15655e0f0b09f7b47a2eb5fb3a Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 3 Aug 2018 13:06:36 +0300 Subject: [PATCH 02/16] Fix parsing of OsmAndBot`s location messages --- .../osmand/telegram/helpers/TelegramHelper.kt | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 3cd053c849..4b5c627824 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -7,7 +7,6 @@ import org.drinkless.td.libcore.telegram.Client import org.drinkless.td.libcore.telegram.Client.ResultHandler import org.drinkless.td.libcore.telegram.TdApi import org.drinkless.td.libcore.telegram.TdApi.AuthorizationState -import org.json.JSONObject import java.io.File import java.util.* import java.util.concurrent.ConcurrentHashMap @@ -28,6 +27,9 @@ class TelegramHelper private constructor() { private const val UPDATE_LIVE_MESSAGES_INTERVAL_SEC = 30L private const val MESSAGE_ACTIVE_TIME_SEC = 24 * 60 * 60 // 24 hours + private const val DEVICE_PREFIX = "Device: " + private const val LOCATION_PREFIX = "Location: " + // min and max values for the Telegram API const val MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 61 const val MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 60 * 60 * 24 - 1 // one day @@ -640,38 +642,40 @@ class TelegramHelper private constructor() { } } - private fun parseOsmAndBotLocation(json: String): MessageOsmAndBotLocation { - val obj = JSONObject(json) - return MessageOsmAndBotLocation( - obj.optString("name", ""), - obj.optDouble("lat", -1.0), - obj.optDouble("lon", -1.0), - obj.optDouble("alt", -1.0), - obj.optDouble("azi", -1.0), - obj.optDouble("spd", -1.0), - obj.optInt("updAgo", -1), - obj.optInt("locAgo", -1), - obj.optInt("updId", -1), - obj.optInt("updTime", -1) - ) + private fun parseOsmAndBotLocation(text: String): MessageOsmAndBotLocation { + val res = MessageOsmAndBotLocation() + for (s in text.lines()) { + when { + s.startsWith(DEVICE_PREFIX) -> { + res.name = s.removePrefix(DEVICE_PREFIX) + } + s.startsWith(LOCATION_PREFIX) -> { + val locStr = s.removePrefix(LOCATION_PREFIX) + try { + val (latS, lonS) = locStr.split(" ") + res.lat = latS.dropLast(1).toDouble() + res.lon = lonS.toDouble() + } catch (e: Exception) { + e.printStackTrace() + } + } + } + } + return res } - class MessageOsmAndBotLocation internal constructor( - val name: String, - val lat: Double, - val lon: Double, - val alt: Double, - val azi: Double, - val spd: Double, - val updAgo: Int, - val locAgo: Int, - val updId: Int, - val updTime: Int - ) : TdApi.MessageContent() { + class MessageOsmAndBotLocation : TdApi.MessageContent() { + + var name: String = "" + internal set + var lat: Double = Double.NaN + internal set + var lon: Double = Double.NaN + internal set override fun getConstructor() = -1 - fun isValid() = name != "" && lat != -1.0 && lon != -1.0 + fun isValid() = name != "" && lat != Double.NaN && lon != Double.NaN } class OrderedChat internal constructor(internal val order: Long, internal val chatId: Long, internal val isChannel: Boolean) : Comparable { From 5e191e268da39edd2af824021e0fa426f7203969 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 3 Aug 2018 13:30:38 +0300 Subject: [PATCH 03/16] Fix TdApi.Message.isAppropriate() --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 4b5c627824..3f8b0e142a 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -629,15 +629,7 @@ class TelegramHelper private constructor() { val content = content return when (content) { is TdApi.MessageLocation -> true - is TdApi.MessageText -> { - if (content.text.text.startsWith("{")) { - // TODO: get user from library if null - if (isOsmAndBot(senderUserId)) { - return true - } - } - false - } + is TdApi.MessageText -> isOsmAndBot(senderUserId) || isOsmAndBot(viaBotUserId) else -> false } } From 6e473384c149ecbaabdfa7940566cd1b94eeb5dc Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 3 Aug 2018 13:39:03 +0300 Subject: [PATCH 04/16] convert OsmAnd bot location messages to MessageOsmAndBotLocation --- .../telegram/helpers/ShowLocationHelper.kt | 3 --- .../osmand/telegram/helpers/TelegramHelper.kt | 20 +++++++++++++++++++ .../telegram/helpers/TelegramUiHelper.kt | 3 --- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index 043edbc6fc..8c82b8665f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -79,9 +79,6 @@ class ShowLocationHelper(private val app: TelegramApplication) { if (userName.isEmpty()) { userName = user.phoneNumber } - if (telegramHelper.isOsmAndBot(user.id)) { - userName = telegramHelper.getOsmAndBotDeviceName(message) - } photoPath = telegramHelper.getUserPhotoPath(user) } if (userName.isEmpty()) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index f2b53239e2..9786ef65b0 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -391,6 +391,8 @@ class TelegramHelper private constructor() { val oldContent = message.content if (oldContent is TdApi.MessageText) { message.content = parseOsmAndBotLocation(oldContent.text.text) + } else if (oldContent is TdApi.MessageLocation && isOsmAndBot(message.senderUserId)) { + message.content = parseOsmAndBotLocation(message) } removeOldMessages(message.senderUserId, message.chatId) usersLocationMessages[message.id] = message @@ -663,6 +665,22 @@ class TelegramHelper private constructor() { ) } + private fun parseOsmAndBotLocation(message: TdApi.Message): MessageOsmAndBotLocation { + val messageLocation = message.content as TdApi.MessageLocation + return MessageOsmAndBotLocation( + getOsmAndBotDeviceName(message), + messageLocation.location.latitude, + messageLocation.location.longitude, + -1.0, + -1.0, + -1.0, + -1, + -1, + -1, + -1 + ) + } + class MessageOsmAndBotLocation internal constructor( val name: String, val lat: Double, @@ -888,6 +906,8 @@ class TelegramHelper private constructor() { val newContent = updateMessageContent.newContent message.content = if (newContent is TdApi.MessageText) { parseOsmAndBotLocation(newContent.text.text) + } else if (newContent is TdApi.MessageLocation && isOsmAndBot(message.senderUserId)) { + parseOsmAndBotLocation(message) } else { newContent } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index 96e9d28f30..7837d145b3 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -131,9 +131,6 @@ object TelegramUiHelper { if (name.isEmpty()) { name = user.phoneNumber } - if (helper.isOsmAndBot(user.id)) { - name = helper.getOsmAndBotDeviceName(message) - } latLon = LatLon(content.location.latitude, content.location.longitude) photoPath = helper.getUserPhotoPath(user) placeholderId = R.drawable.img_user_picture From c65868f522a1e69eeefdf0779da2c0db7f90c033 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 3 Aug 2018 13:50:57 +0300 Subject: [PATCH 05/16] Merge branch 'master' of ssh://github.com/osmandapp/Osmand into TelegramUiImprovements # Conflicts: # OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index b96052321d..8044085dcc 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -643,6 +643,15 @@ class TelegramHelper private constructor() { } } + private fun parseOsmAndBotLocation(message: TdApi.Message): MessageOsmAndBotLocation { + val messageLocation = message.content as TdApi.MessageLocation + val res = MessageOsmAndBotLocation() + res.name = getOsmAndBotDeviceName(message) + res.lat = messageLocation.location.latitude + res.lon = messageLocation.location.longitude + return res + } + private fun parseOsmAndBotLocation(text: String): MessageOsmAndBotLocation { val res = MessageOsmAndBotLocation() for (s in text.lines()) { From a12f2eca5acdff96e4286c3d1ae4e9d46dceb717 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 3 Aug 2018 14:35:49 +0300 Subject: [PATCH 06/16] remove unnecessary check for OsmAnd bot --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 8044085dcc..b39b64b29b 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -256,8 +256,7 @@ class TelegramHelper private constructor() { } fun getOsmAndBotDeviceName(message: TdApi.Message): String { - val replyMarkup = - message.replyMarkup as TdApi.ReplyMarkupInlineKeyboard + val replyMarkup = message.replyMarkup as TdApi.ReplyMarkupInlineKeyboard val deviceName = replyMarkup.rows[0][1].text return deviceName.split("\\s".toRegex())[1] } @@ -393,7 +392,7 @@ class TelegramHelper private constructor() { val oldContent = message.content if (oldContent is TdApi.MessageText) { message.content = parseOsmAndBotLocation(oldContent.text.text) - } else if (oldContent is TdApi.MessageLocation && isOsmAndBot(message.senderUserId)) { + } else if (oldContent is TdApi.MessageLocation) { message.content = parseOsmAndBotLocation(message) } removeOldMessages(message.senderUserId, message.chatId) From 87879559bb4055e4a2074c5ed455f015bea570e6 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 3 Aug 2018 14:42:01 +0300 Subject: [PATCH 07/16] add check for Osmand bot --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index b39b64b29b..fdeb6c7461 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -392,7 +392,8 @@ class TelegramHelper private constructor() { val oldContent = message.content if (oldContent is TdApi.MessageText) { message.content = parseOsmAndBotLocation(oldContent.text.text) - } else if (oldContent is TdApi.MessageLocation) { + } else if (oldContent is TdApi.MessageLocation && + (isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) { message.content = parseOsmAndBotLocation(message) } removeOldMessages(message.senderUserId, message.chatId) From 37c8d2b9a01e3f58dde4543fdf6592c05c3724da Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 3 Aug 2018 14:55:07 +0300 Subject: [PATCH 08/16] add checks in getOsmAndBotDeviceName --- .../osmand/telegram/helpers/TelegramHelper.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index fdeb6c7461..a9a99d5def 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -256,9 +256,16 @@ class TelegramHelper private constructor() { } fun getOsmAndBotDeviceName(message: TdApi.Message): String { - val replyMarkup = message.replyMarkup as TdApi.ReplyMarkupInlineKeyboard - val deviceName = replyMarkup.rows[0][1].text - return deviceName.split("\\s".toRegex())[1] + var deviceName = "" + if (message.replyMarkup is TdApi.ReplyMarkupInlineKeyboard) { + val replyMarkup = message.replyMarkup as TdApi.ReplyMarkupInlineKeyboard + try { + deviceName = replyMarkup.rows[0][1].text.split("\\s".toRegex())[1] + } catch (e: Exception) { + + } + } + return deviceName } fun isOsmAndBot(userId: Int) = users[userId]?.username == OSMAND_BOT_USERNAME @@ -895,7 +902,8 @@ class TelegramHelper private constructor() { val newContent = updateMessageContent.newContent message.content = if (newContent is TdApi.MessageText) { parseOsmAndBotLocation(newContent.text.text) - } else if (newContent is TdApi.MessageLocation && isOsmAndBot(message.senderUserId)) { + } else if (newContent is TdApi.MessageLocation && + (isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) { parseOsmAndBotLocation(message) } else { newContent From c15f294dc4b93c416defca2f0f9acba5259d8036 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 3 Aug 2018 16:38:56 +0300 Subject: [PATCH 09/16] Fix "All" number for chat description --- .../osmand/telegram/helpers/TelegramHelper.kt | 80 ++++++++++++++++++- .../osmand/telegram/ui/LiveNowTabFragment.kt | 17 +++- 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index a9a99d5def..553f8fd28f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -85,6 +85,7 @@ class TelegramHelper private constructor() { var listener: TelegramListener? = null private val incomingMessagesListeners = HashSet() + private val fullInfoUpdatesListeners = HashSet() fun addIncomingMessagesListener(listener: TelegramIncomingMessagesListener) { incomingMessagesListeners.add(listener) @@ -94,6 +95,14 @@ class TelegramHelper private constructor() { incomingMessagesListeners.remove(listener) } + fun addFullInfoUpdatesListener(listener: FullInfoUpdatesListener) { + fullInfoUpdatesListeners.add(listener) + } + + fun removeFullInfoUpdatesListener(listener: FullInfoUpdatesListener) { + fullInfoUpdatesListeners.remove(listener) + } + fun getChatList(): TreeSet { synchronized(chatList) { return TreeSet(chatList.filter { !it.isChannel }) @@ -130,9 +139,21 @@ class TelegramHelper private constructor() { return res } - fun getBasicGroupFullInfo(id: Int) = basicGroupsFullInfo[id] + fun getBasicGroupFullInfo(id: Int): TdApi.BasicGroupFullInfo? { + val res = basicGroupsFullInfo[id] + if (res == null) { + requestBasicGroupFullInfo(id) + } + return res + } - fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id] + fun getSupergroupFullInfo(id: Int): TdApi.SupergroupFullInfo? { + val res = supergroupsFullInfo[id] + if (res == null) { + requestSupergroupFullInfo(id) + } + return res + } fun isGroup(chat: TdApi.Chat): Boolean { return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup @@ -180,6 +201,11 @@ class TelegramHelper private constructor() { fun updateLocationMessages() } + interface FullInfoUpdatesListener { + fun onBasicGroupFullInfoUpdated(groupId: Int, info: TdApi.BasicGroupFullInfo) + fun onSupergroupFullInfoUpdated(groupId: Int, info: TdApi.SupergroupFullInfo) + } + interface TelegramAuthorizationRequestListener { fun onRequestTelegramAuthenticationParameter(parameterType: TelegramAuthenticationParameterType) fun onTelegramAuthorizationRequestError(code: Int, message: String) @@ -366,6 +392,42 @@ class TelegramHelper private constructor() { listener?.onTelegramChatsRead() } + private fun requestBasicGroupFullInfo(id: Int) { + client?.send(TdApi.GetBasicGroupFullInfo(id)) { obj -> + when (obj.constructor) { + TdApi.Error.CONSTRUCTOR -> { + val error = obj as TdApi.Error + if (error.code != IGNORED_ERROR_CODE) { + listener?.onTelegramError(error.code, error.message) + } + } + TdApi.BasicGroupFullInfo.CONSTRUCTOR -> { + val info = obj as TdApi.BasicGroupFullInfo + basicGroupsFullInfo[id] = info + fullInfoUpdatesListeners.forEach { it.onBasicGroupFullInfoUpdated(id, info) } + } + } + } + } + + private fun requestSupergroupFullInfo(id: Int) { + client?.send(TdApi.GetSupergroupFullInfo(id)) { obj -> + when (obj.constructor) { + TdApi.Error.CONSTRUCTOR -> { + val error = obj as TdApi.Error + if (error.code != IGNORED_ERROR_CODE) { + listener?.onTelegramError(error.code, error.message) + } + } + TdApi.SupergroupFullInfo.CONSTRUCTOR -> { + val info = obj as TdApi.SupergroupFullInfo + supergroupsFullInfo[id] = info + fullInfoUpdatesListeners.forEach { it.onSupergroupFullInfoUpdated(id, info) } + } + } + } + } + private fun requestCurrentUser(){ client?.send(TdApi.GetMe()) { obj -> when (obj.constructor) { @@ -1013,11 +1075,21 @@ class TelegramHelper private constructor() { } TdApi.UpdateBasicGroupFullInfo.CONSTRUCTOR -> { val updateBasicGroupFullInfo = obj as TdApi.UpdateBasicGroupFullInfo - basicGroupsFullInfo[updateBasicGroupFullInfo.basicGroupId] = updateBasicGroupFullInfo.basicGroupFullInfo + val id = updateBasicGroupFullInfo.basicGroupId + if (basicGroupsFullInfo.containsKey(id)) { + val info = updateBasicGroupFullInfo.basicGroupFullInfo + basicGroupsFullInfo[id] = info + fullInfoUpdatesListeners.forEach { it.onBasicGroupFullInfoUpdated(id, info) } + } } TdApi.UpdateSupergroupFullInfo.CONSTRUCTOR -> { val updateSupergroupFullInfo = obj as TdApi.UpdateSupergroupFullInfo - supergroupsFullInfo[updateSupergroupFullInfo.supergroupId] = updateSupergroupFullInfo.supergroupFullInfo + val id = updateSupergroupFullInfo.supergroupId + if (supergroupsFullInfo.containsKey(id)) { + val info = updateSupergroupFullInfo.supergroupFullInfo + supergroupsFullInfo[id] = info + fullInfoUpdatesListeners.forEach { it.onSupergroupFullInfoUpdated(id, info) } + } } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index 34fbc8355c..ddaca35473 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -33,7 +33,7 @@ private const val CHAT_VIEW_TYPE = 0 private const val LOCATION_ITEM_VIEW_TYPE = 1 class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessagesListener, - TelegramLocationListener, TelegramCompassListener { + FullInfoUpdatesListener, TelegramLocationListener, TelegramCompassListener { private val app: TelegramApplication get() = activity?.application as TelegramApplication @@ -75,12 +75,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage locationViewCache = app.uiUtils.getUpdateLocationViewCache() updateList() telegramHelper.addIncomingMessagesListener(this) + telegramHelper.addFullInfoUpdatesListener(this) startLocationUpdate() } override fun onPause() { super.onPause() telegramHelper.removeIncomingMessagesListener(this) + telegramHelper.removeFullInfoUpdatesListener(this) stopLocationUpdate() } @@ -130,6 +132,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage override fun updateLocationMessages() {} + override fun onBasicGroupFullInfoUpdated(groupId: Int, info: TdApi.BasicGroupFullInfo) { + app.runInUIThread { updateList() } + } + + override fun onSupergroupFullInfoUpdated(groupId: Int, info: TdApi.SupergroupFullInfo) { + app.runInUIThread { updateList() } + } + override fun updateLocation(location: Location?) { val loc = this.location val newLocation = loc == null && location != null @@ -299,8 +309,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage item.privateChat -> "" // FIXME else -> { val live = getString(R.string.shared_string_live) -// val all = getString(R.string.shared_string_all) - "$live ${item.liveMembersCount}" + val all = getString(R.string.shared_string_all) + val liveStr = "$live ${item.liveMembersCount}" + if (item.membersCount > 0) "$liveStr • $all ${item.membersCount}" else liveStr } } } From 3e9f4ead06a8ac27555eee6ce6052f73563fcd8d Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 3 Aug 2018 18:44:42 +0300 Subject: [PATCH 10/16] Add the button for opening OsmAnd to "Live Now" screen --- .../res/layout/fragment_live_now_tab.xml | 30 +++++++++++++++---- OsmAnd-telegram/res/values/strings.xml | 1 + .../osmand/telegram/ui/LiveNowTabFragment.kt | 8 +++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/OsmAnd-telegram/res/layout/fragment_live_now_tab.xml b/OsmAnd-telegram/res/layout/fragment_live_now_tab.xml index b9b6feb1d9..0995bb0735 100644 --- a/OsmAnd-telegram/res/layout/fragment_live_now_tab.xml +++ b/OsmAnd-telegram/res/layout/fragment_live_now_tab.xml @@ -5,12 +5,30 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:layout_height="match_parent"> + + + +