diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index d58bd675cb..4c87c3d684 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -15,6 +15,8 @@ import org.json.JSONArray import org.json.JSONException import org.json.JSONObject +val ADDITIONAL_ACTIVE_TIME_VALUES_SEC = listOf(15 * 60L, 30 * 60L, 60 * 60L, 180 * 60L) + private val SEND_MY_LOC_VALUES_SEC = listOf(1L, 2L, 3L, 5L, 10L, 15L, 30L, 60L, 90L, 2 * 60L, 3 * 60L, 5 * 60L) private val STALE_LOC_VALUES_SEC = @@ -31,7 +33,6 @@ private val LOC_HISTORY_VALUES_SEC = listOf( 12 * 60 * 60L, 24 * 60 * 60L ) -private val ADDITIONAL_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 @@ -148,23 +149,6 @@ class TelegramSettings(private val app: TelegramApplication) { fun getChatsShareInfo() = shareChatsInfo - fun getAdditionalActiveTime(chatId: Long) = - shareChatsInfo[chatId]?.additionalActiveTime ?: ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0] - - fun getNextAdditionalActiveTime(chatId: Long): Long { - return if (shareChatsInfo.containsKey(chatId)) { - var index = - ADDITIONAL_ACTIVE_TIME_VALUES_SEC.indexOf(shareChatsInfo[chatId]?.additionalActiveTime) - if (ADDITIONAL_ACTIVE_TIME_VALUES_SEC.lastIndex > index) { - ADDITIONAL_ACTIVE_TIME_VALUES_SEC[++index] - } else { - ADDITIONAL_ACTIVE_TIME_VALUES_SEC[index] - } - } else { - ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0] - } - } - fun getChatLiveMessageExpireTime(chatId: Long): Long { val shareInfo = shareChatsInfo[chatId] return if (shareInfo != null) { @@ -491,7 +475,16 @@ class TelegramSettings(private val app: TelegramApplication) { var lastSuccessfulSendTime = -1L var shouldDeletePreviousMessage = false var additionalActiveTime = ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0] - + + fun getNextAdditionalActiveTime(): Long { + var index = ADDITIONAL_ACTIVE_TIME_VALUES_SEC.indexOf(additionalActiveTime) + return if (ADDITIONAL_ACTIVE_TIME_VALUES_SEC.lastIndex > index) { + ADDITIONAL_ACTIVE_TIME_VALUES_SEC[++index] + } else { + ADDITIONAL_ACTIVE_TIME_VALUES_SEC[index] + } + } + companion object { internal const val CHAT_ID_KEY = "chatId" diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 0531a67cb5..54c5fe9e8f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -15,6 +15,7 @@ import android.support.v7.widget.RecyclerView import android.view.* import android.view.animation.LinearInterpolator import android.widget.* +import net.osmand.telegram.ADDITIONAL_ACTIVE_TIME_VALUES_SEC import net.osmand.telegram.R import net.osmand.telegram.TelegramApplication import net.osmand.telegram.helpers.TelegramHelper @@ -541,12 +542,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener { val expiresIn = settings.getChatLiveMessageExpireTime(chat.id) holder.textInArea?.apply { + val time = shareInfo?.additionalActiveTime ?: ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0] visibility = View.VISIBLE - text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration( - context!!, settings.getAdditionalActiveTime(chat.id))}" + text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration(context!!, time)}" setOnClickListener { - val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + settings.getAdditionalActiveTime(chat.id) - settings.shareLocationToChat(chat.id, true, newLivePeriod, settings.getNextAdditionalActiveTime(chat.id)) + if (shareInfo != null) { + val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + shareInfo.additionalActiveTime + settings.shareLocationToChat(chat.id, true, newLivePeriod, shareInfo.getNextAdditionalActiveTime()) + } else { + val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0] + settings.shareLocationToChat(chat.id, true, newLivePeriod, ADDITIONAL_ACTIVE_TIME_VALUES_SEC[1]) + } notifyItemChanged(position) } }