Merge pull request #5666 from osmandapp/MoveFromChatTitleToChatId
Change chatTitle to chatId
This commit is contained in:
commit
aff56654b3
7 changed files with 103 additions and 104 deletions
|
@ -246,9 +246,9 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReceiveChatLocationMessages(chatTitle: String, vararg messages: TdApi.Message) {
|
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
|
||||||
val app = app()
|
val app = app()
|
||||||
if (app.settings.isShowingChatOnMap(chatTitle)) {
|
if (app.settings.isShowingChatOnMap(chatId)) {
|
||||||
ShowMessagesTask(app).executeOnExecutor(executor, *messages)
|
ShowMessagesTask(app).executeOnExecutor(executor, *messages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,12 @@ private const val SEND_MY_LOCATION_INTERVAL_DEFAULT = 5L * 1000 // 5 seconds
|
||||||
private const val USER_LOCATION_EXPIRE_TIME_KEY = "user_location_expire_time"
|
private const val USER_LOCATION_EXPIRE_TIME_KEY = "user_location_expire_time"
|
||||||
private const val USER_LOCATION_EXPIRE_TIME_DEFAULT = 15L * 60 * 1000 // 15 minutes
|
private const val USER_LOCATION_EXPIRE_TIME_DEFAULT = 15L * 60 * 1000 // 15 minutes
|
||||||
|
|
||||||
|
private const val TITLES_REPLACED_WITH_IDS = "changed_to_chat_id"
|
||||||
|
|
||||||
class TelegramSettings(private val app: TelegramApplication) {
|
class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
private var shareLocationChats: Set<String> = emptySet()
|
private var shareLocationChats: Set<Long> = emptySet()
|
||||||
private var showOnMapChats: Set<String> = emptySet()
|
private var showOnMapChats: Set<Long> = emptySet()
|
||||||
|
|
||||||
var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS
|
var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS
|
||||||
var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR
|
var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR
|
||||||
|
@ -30,33 +32,34 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
var userLocationExpireTime = USER_LOCATION_EXPIRE_TIME_DEFAULT
|
var userLocationExpireTime = USER_LOCATION_EXPIRE_TIME_DEFAULT
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
updatePrefs()
|
||||||
read()
|
read()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasAnyChatToShareLocation() = shareLocationChats.isNotEmpty()
|
fun hasAnyChatToShareLocation() = shareLocationChats.isNotEmpty()
|
||||||
|
|
||||||
fun isSharingLocationToChat(chatTitle: String) = shareLocationChats.contains(chatTitle)
|
fun isSharingLocationToChat(chatId: Long) = shareLocationChats.contains(chatId)
|
||||||
|
|
||||||
fun hasAnyChatToShowOnMap() = showOnMapChats.isNotEmpty()
|
fun hasAnyChatToShowOnMap() = showOnMapChats.isNotEmpty()
|
||||||
|
|
||||||
fun isShowingChatOnMap(chatTitle: String) = showOnMapChats.contains(chatTitle)
|
fun isShowingChatOnMap(chatId: Long) = showOnMapChats.contains(chatId)
|
||||||
|
|
||||||
fun removeNonexistingChats(presentChatTitles: List<String>) {
|
fun removeNonexistingChats(presentChatIds: List<Long>) {
|
||||||
val shareLocationChats = shareLocationChats.toMutableList()
|
val shareLocationChats = shareLocationChats.toMutableList()
|
||||||
shareLocationChats.intersect(presentChatTitles)
|
shareLocationChats.intersect(presentChatIds)
|
||||||
this.shareLocationChats = shareLocationChats.toHashSet()
|
this.shareLocationChats = shareLocationChats.toHashSet()
|
||||||
|
|
||||||
val showOnMapChats = showOnMapChats.toMutableList()
|
val showOnMapChats = showOnMapChats.toMutableList()
|
||||||
showOnMapChats.intersect(presentChatTitles)
|
showOnMapChats.intersect(presentChatIds)
|
||||||
this.showOnMapChats = showOnMapChats.toHashSet()
|
this.showOnMapChats = showOnMapChats.toHashSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shareLocationToChat(chatTitle: String, share: Boolean) {
|
fun shareLocationToChat(chatId: Long, share: Boolean) {
|
||||||
val shareLocationChats = shareLocationChats.toMutableList()
|
val shareLocationChats = shareLocationChats.toMutableList()
|
||||||
if (share) {
|
if (share) {
|
||||||
shareLocationChats.add(chatTitle)
|
shareLocationChats.add(chatId)
|
||||||
} else {
|
} else {
|
||||||
shareLocationChats.remove(chatTitle)
|
shareLocationChats.remove(chatId)
|
||||||
}
|
}
|
||||||
this.shareLocationChats = shareLocationChats.toHashSet()
|
this.shareLocationChats = shareLocationChats.toHashSet()
|
||||||
}
|
}
|
||||||
|
@ -65,12 +68,12 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
this.shareLocationChats = emptySet()
|
this.shareLocationChats = emptySet()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showChatOnMap(chatTitle: String, show: Boolean) {
|
fun showChatOnMap(chatId: Long, show: Boolean) {
|
||||||
val showOnMapChats = showOnMapChats.toMutableList()
|
val showOnMapChats = showOnMapChats.toMutableList()
|
||||||
if (show) {
|
if (show) {
|
||||||
showOnMapChats.add(chatTitle)
|
showOnMapChats.add(chatId)
|
||||||
} else {
|
} else {
|
||||||
showOnMapChats.remove(chatTitle)
|
showOnMapChats.remove(chatId)
|
||||||
}
|
}
|
||||||
this.showOnMapChats = showOnMapChats.toHashSet()
|
this.showOnMapChats = showOnMapChats.toHashSet()
|
||||||
}
|
}
|
||||||
|
@ -87,15 +90,15 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
val shareLocationChatsSet = mutableSetOf<String>()
|
val shareLocationChatsSet = mutableSetOf<String>()
|
||||||
val shareLocationChats = ArrayList(shareLocationChats)
|
val shareLocationChats = ArrayList(shareLocationChats)
|
||||||
for (chatTitle in shareLocationChats) {
|
for (chatId in shareLocationChats) {
|
||||||
shareLocationChatsSet.add(chatTitle)
|
shareLocationChatsSet.add(chatId.toString())
|
||||||
}
|
}
|
||||||
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, shareLocationChatsSet)
|
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, shareLocationChatsSet)
|
||||||
|
|
||||||
val showOnMapChatsSet = mutableSetOf<String>()
|
val showOnMapChatsSet = mutableSetOf<String>()
|
||||||
val showOnMapChats = ArrayList(showOnMapChats)
|
val showOnMapChats = ArrayList(showOnMapChats)
|
||||||
for (chatTitle in showOnMapChats) {
|
for (chatId in showOnMapChats) {
|
||||||
showOnMapChatsSet.add(chatTitle)
|
showOnMapChatsSet.add(chatId.toString())
|
||||||
}
|
}
|
||||||
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, showOnMapChatsSet)
|
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, showOnMapChatsSet)
|
||||||
|
|
||||||
|
@ -110,17 +113,17 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
fun read() {
|
fun read() {
|
||||||
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val shareLocationChats = mutableSetOf<String>()
|
val shareLocationChats = mutableSetOf<Long>()
|
||||||
val shareLocationChatsSet = prefs.getStringSet(SHARE_LOCATION_CHATS_KEY, mutableSetOf())
|
val shareLocationChatsSet = prefs.getStringSet(SHARE_LOCATION_CHATS_KEY, mutableSetOf())
|
||||||
for (chatTitle in shareLocationChatsSet) {
|
for (chatId in shareLocationChatsSet) {
|
||||||
shareLocationChats.add(chatTitle)
|
shareLocationChats.add(chatId.toLong())
|
||||||
}
|
}
|
||||||
this.shareLocationChats = shareLocationChats
|
this.shareLocationChats = shareLocationChats
|
||||||
|
|
||||||
val showOnMapChats = mutableSetOf<String>()
|
val showOnMapChats = mutableSetOf<Long>()
|
||||||
val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf())
|
val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf())
|
||||||
for (chatTitle in showOnMapChatsSet) {
|
for (chatId in showOnMapChatsSet) {
|
||||||
showOnMapChats.add(chatTitle)
|
showOnMapChats.add(chatId.toLong())
|
||||||
}
|
}
|
||||||
this.showOnMapChats = showOnMapChats
|
this.showOnMapChats = showOnMapChats
|
||||||
|
|
||||||
|
@ -136,4 +139,18 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
userLocationExpireTime =
|
userLocationExpireTime =
|
||||||
prefs.getLong(USER_LOCATION_EXPIRE_TIME_KEY, USER_LOCATION_EXPIRE_TIME_DEFAULT)
|
prefs.getLong(USER_LOCATION_EXPIRE_TIME_KEY, USER_LOCATION_EXPIRE_TIME_DEFAULT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updatePrefs() {
|
||||||
|
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
||||||
|
val idsInUse = prefs.getBoolean(TITLES_REPLACED_WITH_IDS, false)
|
||||||
|
if (!idsInUse) {
|
||||||
|
val edit = prefs.edit()
|
||||||
|
|
||||||
|
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, emptySet())
|
||||||
|
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, emptySet())
|
||||||
|
edit.putBoolean(TITLES_REPLACED_WITH_IDS, true)
|
||||||
|
|
||||||
|
edit.apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,11 +53,10 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
execOsmandApi {
|
execOsmandApi {
|
||||||
val messages = telegramHelper.getMessages()
|
val messages = telegramHelper.getMessages()
|
||||||
for (message in messages) {
|
for (message in messages) {
|
||||||
val chatTitle = telegramHelper.getChat(message.chatId)?.title
|
|
||||||
val date = Math.max(message.date, message.editDate) * 1000L
|
val date = Math.max(message.date, message.editDate) * 1000L
|
||||||
val expired = System.currentTimeMillis() - date > app.settings.userLocationExpireTime
|
val expired = System.currentTimeMillis() - date > app.settings.userLocationExpireTime
|
||||||
if (chatTitle != null && expired) {
|
if (expired) {
|
||||||
removeMapPoint(chatTitle, message)
|
removeMapPoint(message.chatId, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +64,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
|
|
||||||
fun addLocationToMap(message: TdApi.Message) {
|
fun addLocationToMap(message: TdApi.Message) {
|
||||||
execOsmandApi {
|
execOsmandApi {
|
||||||
|
val chatId = message.chatId
|
||||||
val chatTitle = telegramHelper.getChat(message.chatId)?.title
|
val chatTitle = telegramHelper.getChat(message.chatId)?.title
|
||||||
val content = message.content
|
val content = message.content
|
||||||
if (chatTitle != null && content is TdApi.MessageLocation) {
|
if (chatTitle != null && content is TdApi.MessageLocation) {
|
||||||
|
@ -86,33 +86,33 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
setupMapLayer()
|
setupMapLayer()
|
||||||
val params = generatePhotoParams(photoPath)
|
val params = generatePhotoParams(photoPath)
|
||||||
osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatTitle}_${message.senderUserId}", userName, userName,
|
osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatId}_${message.senderUserId}", userName, userName,
|
||||||
chatTitle, Color.RED, ALatLon(content.location.latitude, content.location.longitude), null, params)
|
chatTitle, Color.RED, ALatLon(content.location.latitude, content.location.longitude), null, params)
|
||||||
} else if (chatTitle != null && content is MessageOsmAndBotLocation && content.isValid()) {
|
} else if (chatTitle != null && content is MessageOsmAndBotLocation && content.isValid()) {
|
||||||
val name = content.name
|
val name = content.name
|
||||||
setupMapLayer()
|
setupMapLayer()
|
||||||
osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatTitle}_$name", name, name,
|
osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatId}_$name", name, name,
|
||||||
chatTitle, Color.RED, ALatLon(content.lat, content.lon), null, null)
|
chatTitle, Color.RED, ALatLon(content.lat, content.lon), null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showChatMessages(chatTitle: String) {
|
fun showChatMessages(chatId: Long) {
|
||||||
execOsmandApi {
|
execOsmandApi {
|
||||||
val messages = telegramHelper.getChatMessages(chatTitle)
|
val messages = telegramHelper.getChatMessages(chatId)
|
||||||
for (message in messages) {
|
for (message in messages) {
|
||||||
addLocationToMap(message)
|
addLocationToMap(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hideChatMessages(chatTitle: String) {
|
fun hideChatMessages(chatId: Long) {
|
||||||
execOsmandApi {
|
execOsmandApi {
|
||||||
val messages = telegramHelper.getChatMessages(chatTitle)
|
val messages = telegramHelper.getChatMessages(chatId)
|
||||||
for (message in messages) {
|
for (message in messages) {
|
||||||
val user = telegramHelper.getUser(message.senderUserId)
|
val user = telegramHelper.getUser(message.senderUserId)
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
removeMapPoint(chatTitle, message)
|
removeMapPoint(chatId, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,12 +145,12 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
return mapOf(AMapPoint.POINT_IMAGE_URI_PARAM to photoUri.toString())
|
return mapOf(AMapPoint.POINT_IMAGE_URI_PARAM to photoUri.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeMapPoint(chatTitle: String, message: TdApi.Message) {
|
private fun removeMapPoint(chatId: Long, message: TdApi.Message) {
|
||||||
val content = message.content
|
val content = message.content
|
||||||
if (content is TdApi.MessageLocation) {
|
if (content is TdApi.MessageLocation) {
|
||||||
osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatTitle}_${message.senderUserId}")
|
osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatId}_${message.senderUserId}")
|
||||||
} else if (content is MessageOsmAndBotLocation) {
|
} else if (content is MessageOsmAndBotLocation) {
|
||||||
osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatTitle}_${content.name}")
|
osmandAidlHelper.removeMapPoint(MAP_LAYER_ID, "${chatId}_${content.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ class TelegramHelper private constructor() {
|
||||||
private val secretChats = ConcurrentHashMap<Int, TdApi.SecretChat>()
|
private val secretChats = ConcurrentHashMap<Int, TdApi.SecretChat>()
|
||||||
|
|
||||||
private val chats = ConcurrentHashMap<Long, TdApi.Chat>()
|
private val chats = ConcurrentHashMap<Long, TdApi.Chat>()
|
||||||
private val chatTitles = ConcurrentHashMap<String, Long>()
|
|
||||||
private val chatList = TreeSet<OrderedChat>()
|
private val chatList = TreeSet<OrderedChat>()
|
||||||
private val chatLiveMessages = ConcurrentHashMap<Long, Long>()
|
private val chatLiveMessages = ConcurrentHashMap<Long, Long>()
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChatTitles() = chatTitles.keys().toList()
|
fun getChatIds() = chats.keys().toList()
|
||||||
|
|
||||||
fun getChat(id: Long) = chats[id]
|
fun getChat(id: Long) = chats[id]
|
||||||
|
|
||||||
|
@ -107,8 +106,8 @@ class TelegramHelper private constructor() {
|
||||||
fun getUserMessage(user: TdApi.User) =
|
fun getUserMessage(user: TdApi.User) =
|
||||||
usersLocationMessages.values.firstOrNull { it.senderUserId == user.id }
|
usersLocationMessages.values.firstOrNull { it.senderUserId == user.id }
|
||||||
|
|
||||||
fun getChatMessages(chatTitle: String) =
|
fun getChatMessages(chatId: Long) =
|
||||||
usersLocationMessages.values.filter { chats[it.chatId]?.title == chatTitle }
|
usersLocationMessages.values.filter { it.chatId == chatId }
|
||||||
|
|
||||||
fun getMessages() = usersLocationMessages.values.toList()
|
fun getMessages() = usersLocationMessages.values.toList()
|
||||||
|
|
||||||
|
@ -130,13 +129,6 @@ class TelegramHelper private constructor() {
|
||||||
|
|
||||||
fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id]
|
fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id]
|
||||||
|
|
||||||
private fun updateChatTitles() {
|
|
||||||
chatTitles.clear()
|
|
||||||
for (chatEntry in chats.entries) {
|
|
||||||
chatTitles[chatEntry.value.title] = chatEntry.key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isChannel(chat: TdApi.Chat): Boolean {
|
private fun isChannel(chat: TdApi.Chat): Boolean {
|
||||||
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
|
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
|
||||||
}
|
}
|
||||||
|
@ -172,7 +164,7 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TelegramIncomingMessagesListener {
|
interface TelegramIncomingMessagesListener {
|
||||||
fun onReceiveChatLocationMessages(chatTitle: String, vararg messages: TdApi.Message)
|
fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message)
|
||||||
fun updateLocationMessages()
|
fun updateLocationMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +338,6 @@ class TelegramHelper private constructor() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateChatTitles()
|
|
||||||
listener?.onTelegramChatsRead()
|
listener?.onTelegramChatsRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,11 +363,8 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
removeOldMessages(message.senderUserId, message.chatId)
|
removeOldMessages(message.senderUserId, message.chatId)
|
||||||
usersLocationMessages[message.id] = message
|
usersLocationMessages[message.id] = message
|
||||||
val chatTitle = chats[message.chatId]?.title
|
incomingMessagesListeners.forEach {
|
||||||
if (chatTitle != null) {
|
it.onReceiveChatLocationMessages(message.chatId, message)
|
||||||
incomingMessagesListeners.forEach {
|
|
||||||
it.onReceiveChatLocationMessages(chatTitle, message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,15 +385,15 @@ class TelegramHelper private constructor() {
|
||||||
* @latitude Latitude of the location
|
* @latitude Latitude of the location
|
||||||
* @longitude Longitude of the location
|
* @longitude Longitude of the location
|
||||||
*/
|
*/
|
||||||
fun sendLiveLocationMessage(chatTitles: List<String>, livePeriod: Int, latitude: Double, longitude: Double): Boolean {
|
fun sendLiveLocationMessage(chatIds: List<Long>, livePeriod: Int, latitude: Double, longitude: Double): Boolean {
|
||||||
if (!requestingActiveLiveLocationMessages && haveAuthorization) {
|
if (!requestingActiveLiveLocationMessages && haveAuthorization) {
|
||||||
if (needRefreshActiveLiveLocationMessages) {
|
if (needRefreshActiveLiveLocationMessages) {
|
||||||
getActiveLiveLocationMessages {
|
getActiveLiveLocationMessages {
|
||||||
sendLiveLocationImpl(chatTitles, livePeriod, latitude, longitude)
|
sendLiveLocationImpl(chatIds, livePeriod, latitude, longitude)
|
||||||
}
|
}
|
||||||
needRefreshActiveLiveLocationMessages = false
|
needRefreshActiveLiveLocationMessages = false
|
||||||
} else {
|
} else {
|
||||||
sendLiveLocationImpl(chatTitles, livePeriod, latitude, longitude)
|
sendLiveLocationImpl(chatIds, livePeriod, latitude, longitude)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -440,7 +428,7 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendLiveLocationImpl(chatTitles: List<String>, livePeriod: Int, latitude: Double, longitude: Double) {
|
private fun sendLiveLocationImpl(chatIds: List<Long>, livePeriod: Int, latitude: Double, longitude: Double) {
|
||||||
val lp = when {
|
val lp = when {
|
||||||
livePeriod < MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC
|
livePeriod < MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC
|
||||||
livePeriod > MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC
|
livePeriod > MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC
|
||||||
|
@ -449,18 +437,15 @@ class TelegramHelper private constructor() {
|
||||||
val location = TdApi.Location(latitude, longitude)
|
val location = TdApi.Location(latitude, longitude)
|
||||||
val content = TdApi.InputMessageLocation(location, lp)
|
val content = TdApi.InputMessageLocation(location, lp)
|
||||||
|
|
||||||
for (chatTitle in chatTitles) {
|
for (chatId in chatIds) {
|
||||||
val chatId = this.chatTitles[chatTitle]
|
val msgId = chatLiveMessages[chatId]
|
||||||
if (chatId != null) {
|
if (msgId != null) {
|
||||||
val msgId = chatLiveMessages[chatId]
|
if (msgId != 0L) {
|
||||||
if (msgId != null) {
|
client?.send(TdApi.EditMessageLiveLocation(chatId, msgId, null, location), liveLocationMessageUpdatesHandler)
|
||||||
if (msgId != 0L) {
|
|
||||||
client?.send(TdApi.EditMessageLiveLocation(chatId, msgId, null, location), liveLocationMessageUpdatesHandler)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
chatLiveMessages[chatId] = 0L
|
|
||||||
client?.send(TdApi.SendMessage(chatId, 0, false, true, null, content), liveLocationMessageUpdatesHandler)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
chatLiveMessages[chatId] = 0L
|
||||||
|
client?.send(TdApi.SendMessage(chatId, 0, false, true, null, content), liveLocationMessageUpdatesHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -761,7 +746,6 @@ class TelegramHelper private constructor() {
|
||||||
chat.order = 0
|
chat.order = 0
|
||||||
setChatOrder(chat, order)
|
setChatOrder(chat, order)
|
||||||
}
|
}
|
||||||
updateChatTitles()
|
|
||||||
listener?.onTelegramChatsChanged()
|
listener?.onTelegramChatsChanged()
|
||||||
}
|
}
|
||||||
TdApi.UpdateChatTitle.CONSTRUCTOR -> {
|
TdApi.UpdateChatTitle.CONSTRUCTOR -> {
|
||||||
|
@ -771,7 +755,6 @@ class TelegramHelper private constructor() {
|
||||||
synchronized(chat) {
|
synchronized(chat) {
|
||||||
chat.title = updateChat.title
|
chat.title = updateChat.title
|
||||||
}
|
}
|
||||||
updateChatTitles()
|
|
||||||
listener?.onTelegramChatChanged(chat)
|
listener?.onTelegramChatChanged(chat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,11 +839,8 @@ class TelegramHelper private constructor() {
|
||||||
synchronized(message) {
|
synchronized(message) {
|
||||||
message.editDate = updateMessageEdited.editDate
|
message.editDate = updateMessageEdited.editDate
|
||||||
}
|
}
|
||||||
val chatTitle = chats[message.chatId]?.title
|
incomingMessagesListeners.forEach {
|
||||||
if (chatTitle != null) {
|
it.onReceiveChatLocationMessages(message.chatId, message)
|
||||||
incomingMessagesListeners.forEach {
|
|
||||||
it.onReceiveChatLocationMessages(chatTitle, message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -880,11 +860,8 @@ class TelegramHelper private constructor() {
|
||||||
newContent
|
newContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val chatTitle = chats[message.chatId]?.title
|
incomingMessagesListeners.forEach {
|
||||||
if (chatTitle != null) {
|
it.onReceiveChatLocationMessages(message.chatId, message)
|
||||||
incomingMessagesListeners.forEach {
|
|
||||||
it.onReceiveChatLocationMessages(chatTitle, message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ object TelegramUiHelper {
|
||||||
messages: List<TdApi.Message>
|
messages: List<TdApi.Message>
|
||||||
): ChatItem {
|
): ChatItem {
|
||||||
val res = ChatItem().apply {
|
val res = ChatItem().apply {
|
||||||
|
chatId = chat.id
|
||||||
chatTitle = chat.title
|
chatTitle = chat.title
|
||||||
photoPath = chat.photo?.small?.local?.path
|
photoPath = chat.photo?.small?.local?.path
|
||||||
placeholderId = R.drawable.img_user_picture
|
placeholderId = R.drawable.img_user_picture
|
||||||
|
@ -95,6 +96,7 @@ object TelegramUiHelper {
|
||||||
): LocationItem? {
|
): LocationItem? {
|
||||||
return if (content.isValid()) {
|
return if (content.isValid()) {
|
||||||
LocationItem().apply {
|
LocationItem().apply {
|
||||||
|
chatId = chat.id
|
||||||
chatTitle = chat.title
|
chatTitle = chat.title
|
||||||
name = content.name
|
name = content.name
|
||||||
latLon = LatLon(content.lat, content.lon)
|
latLon = LatLon(content.lat, content.lon)
|
||||||
|
@ -113,6 +115,7 @@ object TelegramUiHelper {
|
||||||
val user = helper.getUser(message.senderUserId) ?: return null
|
val user = helper.getUser(message.senderUserId) ?: return null
|
||||||
val content = message.content as TdApi.MessageLocation
|
val content = message.content as TdApi.MessageLocation
|
||||||
return LocationItem().apply {
|
return LocationItem().apply {
|
||||||
|
chatId = chat.id
|
||||||
chatTitle = chat.title
|
chatTitle = chat.title
|
||||||
name = "${user.firstName} ${user.lastName}".trim()
|
name = "${user.firstName} ${user.lastName}".trim()
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
|
@ -130,6 +133,8 @@ object TelegramUiHelper {
|
||||||
|
|
||||||
abstract class ListItem {
|
abstract class ListItem {
|
||||||
|
|
||||||
|
var chatId: Long = 0
|
||||||
|
internal set
|
||||||
var chatTitle: String = ""
|
var chatTitle: String = ""
|
||||||
internal set
|
internal set
|
||||||
var latLon: LatLon? = null
|
var latLon: LatLon? = null
|
||||||
|
@ -161,7 +166,7 @@ object TelegramUiHelper {
|
||||||
|
|
||||||
override fun canBeOpenedOnMap() = latLon != null && !chatWithBot
|
override fun canBeOpenedOnMap() = latLon != null && !chatWithBot
|
||||||
|
|
||||||
override fun getMapPointId() = "${chatTitle}_$userId"
|
override fun getMapPointId() = "${chatId}_$userId"
|
||||||
|
|
||||||
override fun getVisibleName() = chatTitle
|
override fun getVisibleName() = chatTitle
|
||||||
}
|
}
|
||||||
|
@ -175,7 +180,7 @@ object TelegramUiHelper {
|
||||||
|
|
||||||
override fun getMapPointId(): String {
|
override fun getMapPointId(): String {
|
||||||
val id = if (userId != 0) userId.toString() else name
|
val id = if (userId != 0) userId.toString() else name
|
||||||
return "${chatTitle}_$id"
|
return "${chatId}_$id"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getVisibleName() = name
|
override fun getVisibleName() = name
|
||||||
|
|
|
@ -120,7 +120,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
override fun onSendLiveLocationError(code: Int, message: String) {}
|
override fun onSendLiveLocationError(code: Int, message: String) {}
|
||||||
|
|
||||||
override fun onReceiveChatLocationMessages(chatTitle: String, vararg messages: TdApi.Message) {
|
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
|
||||||
app.runInUIThread { updateList() }
|
app.runInUIThread { updateList() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,12 +274,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
if (item is ChatItem && holder is ChatViewHolder) {
|
if (item is ChatItem && holder is ChatViewHolder) {
|
||||||
val nextIsLocation = !lastItem && items[position + 1] is LocationItem
|
val nextIsLocation = !lastItem && items[position + 1] is LocationItem
|
||||||
val chatTitle = item.chatTitle
|
val chatId = item.chatId
|
||||||
val stateTextInd = if (settings.isShowingChatOnMap(chatTitle)) 1 else 0
|
val stateTextInd = if (settings.isShowingChatOnMap(chatId)) 1 else 0
|
||||||
|
|
||||||
holder.description?.text = getChatItemDescription(item)
|
holder.description?.text = getChatItemDescription(item)
|
||||||
holder.imageButton?.visibility = View.GONE
|
holder.imageButton?.visibility = View.GONE
|
||||||
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatTitle) }
|
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) }
|
||||||
holder.showOnMapState?.text = menuList[stateTextInd]
|
holder.showOnMapState?.text = menuList[stateTextInd]
|
||||||
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
|
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
|
||||||
} else if (item is LocationItem && holder is ContactViewHolder) {
|
} else if (item is LocationItem && holder is ContactViewHolder) {
|
||||||
|
@ -301,7 +301,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showPopupMenu(holder: ChatViewHolder, chatTitle: String) {
|
private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) {
|
||||||
val ctx = holder.itemView.context
|
val ctx = holder.itemView.context
|
||||||
|
|
||||||
val paint = Paint()
|
val paint = Paint()
|
||||||
|
@ -320,7 +320,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
setOnItemClickListener { _, _, position, _ ->
|
setOnItemClickListener { _, _, position, _ ->
|
||||||
val allSelected = position == 1
|
val allSelected = position == 1
|
||||||
|
|
||||||
settings.showChatOnMap(chatTitle, allSelected)
|
settings.showChatOnMap(chatId, allSelected)
|
||||||
if (settings.hasAnyChatToShowOnMap()) {
|
if (settings.hasAnyChatToShowOnMap()) {
|
||||||
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
||||||
if (allSelected) {
|
if (allSelected) {
|
||||||
|
@ -328,16 +328,16 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (allSelected) {
|
if (allSelected) {
|
||||||
app.showLocationHelper.showChatMessages(chatTitle)
|
app.showLocationHelper.showChatMessages(chatId)
|
||||||
} else {
|
} else {
|
||||||
app.showLocationHelper.hideChatMessages(chatTitle)
|
app.showLocationHelper.hideChatMessages(chatId)
|
||||||
}
|
}
|
||||||
app.showLocationHelper.startShowingLocation()
|
app.showLocationHelper.startShowingLocation()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.showLocationHelper.stopShowingLocation()
|
app.showLocationHelper.stopShowingLocation()
|
||||||
if (!allSelected) {
|
if (!allSelected) {
|
||||||
app.showLocationHelper.hideChatMessages(chatTitle)
|
app.showLocationHelper.hideChatMessages(chatId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeNonexistingChatsFromSettings() {
|
private fun removeNonexistingChatsFromSettings() {
|
||||||
val presentChatTitles = telegramHelper.getChatTitles()
|
val presentChatTitles = telegramHelper.getChatIds()
|
||||||
settings.removeNonexistingChats(presentChatTitles)
|
settings.removeNonexistingChats(presentChatTitles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,8 +451,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val chat = chats[position]
|
val chat = chats[position]
|
||||||
val chatTitle = chat.title
|
val chatId = chat.id
|
||||||
holder.groupName?.text = chatTitle
|
holder.groupName?.text = chat.title
|
||||||
|
|
||||||
var drawable: Drawable? = null
|
var drawable: Drawable? = null
|
||||||
var bitmap: Bitmap? = null
|
var bitmap: Bitmap? = null
|
||||||
|
@ -469,9 +469,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
holder.icon?.setImageDrawable(drawable)
|
holder.icon?.setImageDrawable(drawable)
|
||||||
}
|
}
|
||||||
holder.shareLocationSwitch?.setOnCheckedChangeListener(null)
|
holder.shareLocationSwitch?.setOnCheckedChangeListener(null)
|
||||||
holder.shareLocationSwitch?.isChecked = settings.isSharingLocationToChat(chatTitle)
|
holder.shareLocationSwitch?.isChecked = settings.isSharingLocationToChat(chatId)
|
||||||
holder.shareLocationSwitch?.setOnCheckedChangeListener { view, isChecked ->
|
holder.shareLocationSwitch?.setOnCheckedChangeListener { view, isChecked ->
|
||||||
settings.shareLocationToChat(chatTitle, isChecked)
|
settings.shareLocationToChat(chatId, isChecked)
|
||||||
if (settings.hasAnyChatToShareLocation()) {
|
if (settings.hasAnyChatToShareLocation()) {
|
||||||
if (!AndroidUtils.isLocationPermissionAvailable(view.context)) {
|
if (!AndroidUtils.isLocationPermissionAvailable(view.context)) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
@ -486,9 +486,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.showOnMapSwitch?.setOnCheckedChangeListener(null)
|
holder.showOnMapSwitch?.setOnCheckedChangeListener(null)
|
||||||
holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatTitle)
|
holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatId)
|
||||||
holder.showOnMapSwitch?.setOnCheckedChangeListener { _, isChecked ->
|
holder.showOnMapSwitch?.setOnCheckedChangeListener { _, isChecked ->
|
||||||
settings.showChatOnMap(chatTitle, isChecked)
|
settings.showChatOnMap(chatId, isChecked)
|
||||||
if (settings.hasAnyChatToShowOnMap()) {
|
if (settings.hasAnyChatToShowOnMap()) {
|
||||||
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
@ -496,16 +496,16 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
app.showLocationHelper.showChatMessages(chatTitle)
|
app.showLocationHelper.showChatMessages(chatId)
|
||||||
} else {
|
} else {
|
||||||
app.showLocationHelper.hideChatMessages(chatTitle)
|
app.showLocationHelper.hideChatMessages(chatId)
|
||||||
}
|
}
|
||||||
app.showLocationHelper.startShowingLocation()
|
app.showLocationHelper.startShowingLocation()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.showLocationHelper.stopShowingLocation()
|
app.showLocationHelper.stopShowingLocation()
|
||||||
if (!isChecked) {
|
if (!isChecked) {
|
||||||
app.showLocationHelper.hideChatMessages(chatTitle)
|
app.showLocationHelper.hideChatMessages(chatId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue