Merge pull request #6121 from osmandapp/TelegramUiImprovements

Add increasing values for adding sharing time
This commit is contained in:
Alexander Sytnyk 2018-10-02 15:19:26 +03:00 committed by GitHub
commit c9238a741b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 7 deletions

View file

@ -26,6 +26,7 @@ private val LOC_HISTORY_VALUES_SEC = listOf(
12 * 60 * 60L, 12 * 60 * 60L,
24 * 60 * 60L 24 * 60 * 60L
) )
private val MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC = listOf(15 * 60L, 30 * 60L, 60 * 60L, 180 * 60L)
private const val SEND_MY_LOC_DEFAULT_INDEX = 6 private const val SEND_MY_LOC_DEFAULT_INDEX = 6
private const val STALE_LOC_DEFAULT_INDEX = 4 private const val STALE_LOC_DEFAULT_INDEX = 4
@ -55,6 +56,8 @@ class TelegramSettings(private val app: TelegramApplication) {
private var chatLivePeriods = mutableMapOf<Long, Long>() private var chatLivePeriods = mutableMapOf<Long, Long>()
private var chatShareLocStartSec = mutableMapOf<Long, Long>() private var chatShareLocStartSec = mutableMapOf<Long, Long>()
private var chatShareAddActiveTime = mutableMapOf<Long, Long>()
private var shareLocationChats: Set<Long> = emptySet() private var shareLocationChats: Set<Long> = emptySet()
private var hiddenOnMapChats: Set<Long> = emptySet() private var hiddenOnMapChats: Set<Long> = emptySet()
@ -99,6 +102,10 @@ class TelegramSettings(private val app: TelegramApplication) {
presentChatIds.contains(key) presentChatIds.contains(key)
}.toMutableMap() }.toMutableMap()
chatShareAddActiveTime = chatShareAddActiveTime.filter { (key, _) ->
presentChatIds.contains(key)
}.toMutableMap()
chatShareLocStartSec = chatShareLocStartSec.filter { (key, _) -> chatShareLocStartSec = chatShareLocStartSec.filter { (key, _) ->
presentChatIds.contains(key) presentChatIds.contains(key)
}.toMutableMap() }.toMutableMap()
@ -107,7 +114,8 @@ class TelegramSettings(private val app: TelegramApplication) {
fun shareLocationToChat( fun shareLocationToChat(
chatId: Long, chatId: Long,
share: Boolean, share: Boolean,
livePeriod: Long = DEFAULT_VISIBLE_TIME_SECONDS livePeriod: Long = DEFAULT_VISIBLE_TIME_SECONDS,
addActiveTime: Long = MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC[0]
) { ) {
val shareLocationChats = shareLocationChats.toMutableList() val shareLocationChats = shareLocationChats.toMutableList()
if (share) { if (share) {
@ -118,17 +126,34 @@ class TelegramSettings(private val app: TelegramApplication) {
} }
chatLivePeriods[chatId] = lp chatLivePeriods[chatId] = lp
chatShareLocStartSec[chatId] = (System.currentTimeMillis() / 1000) chatShareLocStartSec[chatId] = (System.currentTimeMillis() / 1000)
chatShareAddActiveTime[chatId] = addActiveTime
shareLocationChats.add(chatId) shareLocationChats.add(chatId)
} else { } else {
shareLocationChats.remove(chatId) shareLocationChats.remove(chatId)
chatLivePeriods.remove(chatId) chatLivePeriods.remove(chatId)
chatShareLocStartSec.remove(chatId) chatShareLocStartSec.remove(chatId)
chatShareAddActiveTime.remove(chatId)
} }
this.shareLocationChats = shareLocationChats.toHashSet() this.shareLocationChats = shareLocationChats.toHashSet()
} }
fun getChatLivePeriod(chatId: Long) = chatLivePeriods[chatId] fun getChatLivePeriod(chatId: Long) = chatLivePeriods[chatId]
fun getChatAddActiveTime(chatId: Long) = chatShareAddActiveTime[chatId] ?: MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC[0]
fun getChatNextAddActiveTime(chatId: Long): Long {
return if (chatShareAddActiveTime.containsKey(chatId)) {
var index = MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC.indexOf(chatShareAddActiveTime[chatId])
if (MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC.lastIndex > index) {
MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC[++index]
} else {
MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC[index]
}
} else {
MESSAGE_ADD_ACTIVE_TIME_VALUES_SEC[0]
}
}
fun getChatLivePeriods(): Map<Long, Long> { fun getChatLivePeriods(): Map<Long, Long> {
return chatLivePeriods.filter { return chatLivePeriods.filter {
getChatLiveMessageExpireTime(it.key) > 0 getChatLiveMessageExpireTime(it.key) > 0
@ -151,10 +176,15 @@ class TelegramSettings(private val app: TelegramApplication) {
chatShareLocStartSec[chatId] = startTime chatShareLocStartSec[chatId] = startTime
} }
fun updateChatAddActiveTime(chatId: Long, newTime: Long) {
chatShareAddActiveTime[chatId] = newTime
}
fun stopSharingLocationToChats() { fun stopSharingLocationToChats() {
this.shareLocationChats = emptySet() this.shareLocationChats = emptySet()
this.chatLivePeriods.clear() this.chatLivePeriods.clear()
this.chatShareLocStartSec.clear() this.chatShareLocStartSec.clear()
this.chatShareAddActiveTime.clear()
} }
fun showChatOnMap(chatId: Long, show: Boolean) { fun showChatOnMap(chatId: Long, show: Boolean) {

View file

@ -30,8 +30,6 @@ private const val DEFAULT_CHAT = 0
private const val ADAPTER_UPDATE_INTERVAL_MIL = 5 * 1000L // 5 sec private const val ADAPTER_UPDATE_INTERVAL_MIL = 5 * 1000L // 5 sec
private const val MESSAGE_ADD_ACTIVE_TIME_SEC = 30 * 60L // 30 min
class MyLocationTabFragment : Fragment(), TelegramListener { class MyLocationTabFragment : Fragment(), TelegramListener {
private var textMarginSmall: Int = 0 private var textMarginSmall: Int = 0
@ -578,13 +576,14 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
holder.textInArea?.apply { holder.textInArea?.apply {
visibility = View.VISIBLE visibility = View.VISIBLE
text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration(context!!, text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration(
MESSAGE_ADD_ACTIVE_TIME_SEC)}" context!!, settings.getChatAddActiveTime(chat.id))}"
setOnClickListener { setOnClickListener {
val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + MESSAGE_ADD_ACTIVE_TIME_SEC val chatNextAddTime = settings.getChatNextAddActiveTime(chat.id)
val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + settings.getChatAddActiveTime(chat.id)
settings.shareLocationToChat(chat.id, false) settings.shareLocationToChat(chat.id, false)
telegramHelper.stopSendingLiveLocationToChat(chat.id) telegramHelper.stopSendingLiveLocationToChat(chat.id)
settings.shareLocationToChat(chat.id, true, newLivePeriod) settings.shareLocationToChat(chat.id, true, newLivePeriod, chatNextAddTime)
app.forceUpdateMyLocation() app.forceUpdateMyLocation()
notifyItemChanged(position) notifyItemChanged(position)
} }