From 07e3660d546b131a3334edbb0a4eb0750ec0fe37 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 12 Oct 2018 12:38:46 +0300 Subject: [PATCH] Move getNextAdditionalActiveTime to shareInfo --- .../net/osmand/telegram/TelegramSettings.kt | 31 +++++++------------ .../telegram/ui/MyLocationTabFragment.kt | 14 ++++++--- 2 files changed, 22 insertions(+), 23 deletions(-) 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) } }