Merge pull request #6135 from osmandapp/TelegramFixes

Fix max sharing time and add check for internet connection
This commit is contained in:
Vitaliy 2018-10-04 21:17:48 +03:00 committed by GitHub
commit ba2e8d94c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View file

@ -126,7 +126,6 @@ class TelegramSettings(private val app: TelegramApplication) {
if (share) {
val lp: Long = when {
livePeriod < TelegramHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
livePeriod > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
else -> livePeriod
}
chatLivePeriods[chatId] = lp

View file

@ -40,11 +40,25 @@ class ShareLocationHelper(private val app: TelegramApplication) {
if (location != null && app.isInternetConnectionAvailable) {
val chatLivePeriods = app.settings.getChatLivePeriods()
val updatedLivePeriods = mutableMapOf<Long, Long>()
if (chatLivePeriods.isNotEmpty()) {
chatLivePeriods.forEach { (chatId, livePeriod) ->
if (livePeriod > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC) {
val startTime = app.settings.getChatShareLocStartSec(chatId)
val currTime = (System.currentTimeMillis() / 1000)
if (startTime != null && startTime + TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC < currTime) {
app.settings.shareLocationToChat(chatId, true, livePeriod - TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC)
} else if (startTime != null) {
updatedLivePeriods[chatId] = TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
}
} else {
updatedLivePeriods[chatId] = livePeriod
}
}
val user = app.telegramHelper.getCurrentUser()
val sharingMode = app.settings.currentSharingMode
if (user != null && sharingMode == user.id.toString()) {
app.telegramHelper.sendLiveLocationMessage(chatLivePeriods, location.latitude, location.longitude)
app.telegramHelper.sendLiveLocationMessage(updatedLivePeriods, location.latitude, location.longitude)
} else if (sharingMode.isNotEmpty()) {
val url = "https://live.osmand.net/device/$sharingMode/send?lat=${location.latitude}&lon=${location.longitude}"
AndroidNetworkUtils.sendRequestAsync(url, null)

View file

@ -440,7 +440,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (sharingMode) {
val message = telegramHelper.getChatLiveMessages()[chat.id]
if (message != null) {
settings.updateChatShareLocStartSec(chatId, message.date.toLong())
// settings.updateChatShareLocStartSec(chatId, message.date.toLong())
}
} else {
continue
@ -465,7 +465,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (settings.isSharingLocationToChat(it.chatId)
&& (settings.getChatShareLocStartSec(it.chatId) == null || settings.getChatLivePeriod(it.chatId) == null)) {
settings.shareLocationToChat(it.chatId, true, (it.content as TdApi.MessageLocation).livePeriod.toLong())
settings.updateChatShareLocStartSec(it.chatId, it.date.toLong())
// settings.updateChatShareLocStartSec(it.chatId, it.date.toLong())
}
}
sharingMode = settings.hasAnyChatToShareLocation()
@ -582,9 +582,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
val chatNextAddTime = settings.getChatNextAddActiveTime(chat.id)
val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + settings.getChatAddActiveTime(chat.id)
settings.shareLocationToChat(chat.id, true, newLivePeriod, chatNextAddTime)
telegramHelper.pauseSendingLiveLocationToChat(chat.id)
telegramHelper.deleteLiveLocationMessage(chat.id)
telegramHelper.resumeSendingLiveLocationToChat(chat.id)
if (app.isInternetConnectionAvailable) {
telegramHelper.pauseSendingLiveLocationToChat(chat.id)
telegramHelper.deleteLiveLocationMessage(chat.id)
telegramHelper.resumeSendingLiveLocationToChat(chat.id)
}
notifyItemChanged(position)
}
}