From e668e12143e5c4c9c914afd204fd0e3910c91cf0 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 16 Aug 2018 12:43:47 +0300 Subject: [PATCH] change live to last response --- OsmAnd-telegram/res/values/strings.xml | 1 + .../osmand/telegram/ui/LiveNowTabFragment.kt | 4 +- .../telegram/ui/SetTimeDialogFragment.kt | 46 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index d029a09d44..ec6f5d166c 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,4 +1,5 @@ + Last response Group To properly log out from your Telegram account, the Internet is needed. Close diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index af2037eb4b..62d64d5001 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -362,11 +362,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage } private fun getListItemLiveTimeDescr(item: ListItem):String { - return getString(R.string.shared_string_live) + + return getString(R.string.last_response) + ": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(item))}" } - private fun getListItemLiveTime(item: ListItem): Long = (System.currentTimeMillis() / 1000) - item.created + private fun getListItemLiveTime(item: ListItem): Long = (System.currentTimeMillis() / 1000) - item.lastUpdated private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) { val ctx = holder.itemView.context diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt index cec8d44d66..495657f70a 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt @@ -283,26 +283,26 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr holder.description?.text = getString(R.string.shared_string_group) } else { val message = telegramHelper.getChatMessages(chat.id).firstOrNull() - if (message != null) { - val content = message.content - if (content is TdApi.MessageLocation && (location != null && content.location != null)) { - holder.description?.visibility = View.VISIBLE - holder.description?.text = getListItemLiveTimeDescr(message) - - holder.locationViewContainer?.visibility = View.VISIBLE - locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 - - message.editDate > settings.staleLocTime - - app.uiUtils.updateLocationView( - holder.directionIcon, - holder.distanceText, - LatLon(content.location.latitude, content.location.longitude), - locationViewCache - ) + val content = message?.content + if (message != null && content is TdApi.MessageLocation && (location != null && content.location != null)) { + val lastUpdated = if (message.editDate != 0) { + message.editDate } else { - holder.locationViewContainer?.visibility = View.GONE - holder.description?.visibility = View.INVISIBLE + message.date } + holder.description?.visibility = View.VISIBLE + holder.description?.text = getListItemLiveTimeDescr(lastUpdated) + + holder.locationViewContainer?.visibility = View.VISIBLE + locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 - + lastUpdated > settings.staleLocTime + + app.uiUtils.updateLocationView( + holder.directionIcon, + holder.distanceText, + LatLon(content.location.latitude, content.location.longitude), + locationViewCache + ) } else { holder.locationViewContainer?.visibility = View.GONE holder.description?.visibility = View.INVISIBLE @@ -321,12 +321,14 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr override fun getItemCount() = chats.size - private fun getListItemLiveTimeDescr(message: TdApi.Message): String { - return getString(R.string.shared_string_live) + - ": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(message))}" + private fun getListItemLiveTimeDescr(lastUpdated: Int): String { + return getString(R.string.last_response) + + ": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(lastUpdated))}" } - private fun getListItemLiveTime(message: TdApi.Message): Long = (System.currentTimeMillis() / 1000) - message.date + private fun getListItemLiveTime(lastUpdated: Int): Long { + return (System.currentTimeMillis() / 1000) - lastUpdated + } inner class ChatViewHolder(val view: View) : RecyclerView.ViewHolder(view) { val icon: ImageView? = view.findViewById(R.id.icon)