Add increasing values for adding sharing time
This commit is contained in:
parent
182edcc87f
commit
ad33ae1023
2 changed files with 36 additions and 7 deletions
|
@ -26,6 +26,7 @@ private val LOC_HISTORY_VALUES_SEC = listOf(
|
|||
12 * 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 STALE_LOC_DEFAULT_INDEX = 4
|
||||
|
@ -55,6 +56,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
private var chatLivePeriods = mutableMapOf<Long, Long>()
|
||||
private var chatShareLocStartSec = mutableMapOf<Long, Long>()
|
||||
|
||||
private var chatShareAddActiveTime = mutableMapOf<Long, Long>()
|
||||
|
||||
private var shareLocationChats: Set<Long> = emptySet()
|
||||
private var hiddenOnMapChats: Set<Long> = emptySet()
|
||||
|
@ -99,6 +102,10 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
presentChatIds.contains(key)
|
||||
}.toMutableMap()
|
||||
|
||||
chatShareAddActiveTime = chatShareAddActiveTime.filter { (key, _) ->
|
||||
presentChatIds.contains(key)
|
||||
}.toMutableMap()
|
||||
|
||||
chatShareLocStartSec = chatShareLocStartSec.filter { (key, _) ->
|
||||
presentChatIds.contains(key)
|
||||
}.toMutableMap()
|
||||
|
@ -107,7 +114,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
fun shareLocationToChat(
|
||||
chatId: Long,
|
||||
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()
|
||||
if (share) {
|
||||
|
@ -118,17 +126,34 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
chatLivePeriods[chatId] = lp
|
||||
chatShareLocStartSec[chatId] = (System.currentTimeMillis() / 1000)
|
||||
chatShareAddActiveTime[chatId] = addActiveTime
|
||||
shareLocationChats.add(chatId)
|
||||
} else {
|
||||
shareLocationChats.remove(chatId)
|
||||
chatLivePeriods.remove(chatId)
|
||||
chatShareLocStartSec.remove(chatId)
|
||||
chatShareAddActiveTime.remove(chatId)
|
||||
}
|
||||
this.shareLocationChats = shareLocationChats.toHashSet()
|
||||
}
|
||||
|
||||
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> {
|
||||
return chatLivePeriods.filter {
|
||||
getChatLiveMessageExpireTime(it.key) > 0
|
||||
|
@ -151,10 +176,15 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
chatShareLocStartSec[chatId] = startTime
|
||||
}
|
||||
|
||||
fun updateChatAddActiveTime(chatId: Long, newTime: Long) {
|
||||
chatShareAddActiveTime[chatId] = newTime
|
||||
}
|
||||
|
||||
fun stopSharingLocationToChats() {
|
||||
this.shareLocationChats = emptySet()
|
||||
this.chatLivePeriods.clear()
|
||||
this.chatShareLocStartSec.clear()
|
||||
this.chatShareAddActiveTime.clear()
|
||||
}
|
||||
|
||||
fun showChatOnMap(chatId: Long, show: Boolean) {
|
||||
|
|
|
@ -30,8 +30,6 @@ private const val DEFAULT_CHAT = 0
|
|||
|
||||
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 {
|
||||
|
||||
private var textMarginSmall: Int = 0
|
||||
|
@ -578,13 +576,14 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
|
||||
holder.textInArea?.apply {
|
||||
visibility = View.VISIBLE
|
||||
text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration(context!!,
|
||||
MESSAGE_ADD_ACTIVE_TIME_SEC)}"
|
||||
text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration(
|
||||
context!!, settings.getChatAddActiveTime(chat.id))}"
|
||||
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)
|
||||
telegramHelper.stopSendingLiveLocationToChat(chat.id)
|
||||
settings.shareLocationToChat(chat.id, true, newLivePeriod)
|
||||
settings.shareLocationToChat(chat.id, true, newLivePeriod, chatNextAddTime)
|
||||
app.forceUpdateMyLocation()
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue