From 607a4389ca4821403abb7222d89d0d8e3f393606 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 17 Oct 2018 17:08:05 +0300 Subject: [PATCH] Fix expireTime and add check for lastSuccessfulSendTimeMs --- .../res/layout/item_with_three_text_lines.xml | 4 +- OsmAnd-telegram/res/values/strings.xml | 2 + .../net/osmand/telegram/TelegramSettings.kt | 3 +- .../telegram/ui/MyLocationTabFragment.kt | 13 +++++-- .../telegram/ui/SharingStatusBottomSheet.kt | 39 ++++++++++++------- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml b/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml index a56ed8f867..a720dfcffb 100644 --- a/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml +++ b/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml @@ -79,8 +79,8 @@ android:id="@+id/last_location_line_time" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="@dimen/content_padding_half" - android:paddingRight="@dimen/content_padding_half" + android:paddingLeft="@dimen/content_padding_small" + android:paddingRight="@dimen/content_padding_small" android:textColor="?android:attr/textColorSecondary" android:textSize="@dimen/list_item_description_text_size" app:firstBaselineToTopHeight="22dp" diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index e773d6bb22..910a6482ab 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,4 +1,6 @@ + Not sent yet + Not found yet Re-send location Last sent location Last available location diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index f5fa25a359..a1d2c9bef3 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -191,7 +191,6 @@ class TelegramSettings(private val app: TelegramApplication) { val shareChatInfo = shareChatsInfo[message.chatId] val content = message.content if (shareChatInfo != null && content is TdApi.MessageLocation) { - shareChatInfo.start = message.date.toLong() shareChatInfo.currentMessageId = message.id shareChatInfo.lastSuccessfulLocation = LatLon(content.location.latitude, content.location.longitude) shareChatInfo.lastSuccessfulSendTimeMs = Math.max(message.editDate, message.date) * 1000L @@ -210,7 +209,7 @@ class TelegramSettings(private val app: TelegramApplication) { } else { var sendChatsErrors = false shareChatsInfo.forEach { _, shareInfo -> - if (shareInfo.hasSharingError) { + if (shareInfo.hasSharingError || shareInfo.lastSuccessfulSendTimeMs == -1L) { sendChatsErrors = true locationTime = shareInfo.lastSuccessfulSendTimeMs val title = app.telegramHelper.getChat(shareInfo.chatId)?.title diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 3ddf3c5b67..be16f42caf 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -60,6 +60,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { private lateinit var searchBox: FrameLayout private lateinit var stopSharingSwitcher: Switch private lateinit var sharingStatusDescription: TextView + private lateinit var sharingStatusIcon: ImageView private lateinit var startSharingBtn: View private lateinit var searchBoxBg: GradientDrawable @@ -143,7 +144,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { text = spannable } - mainView.findViewById(R.id.sharing_status_icon).setImageDrawable(app.uiUtils.getActiveIcon(R.drawable.ic_action_live_now)) + sharingStatusIcon = mainView.findViewById(R.id.sharing_status_icon) textContainer = mainView.findViewById(R.id.text_container).apply { if (Build.VERSION.SDK_INT >= 16) { @@ -195,6 +196,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } mainView.findViewById(R.id.sharing_status_container).setOnClickListener { + settings.updateSharingStatusHistory() fragmentManager?.also { fm -> SharingStatusBottomSheet.showInstance(fm, this) } @@ -433,8 +435,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } private fun updateSharingStatus() { - if (sharingMode && settings.sharingStatusChanges.isNotEmpty()) { - sharingStatusDescription.text = settings.sharingStatusChanges.last().getDescription(app) + if (sharingMode) { + settings.updateSharingStatusHistory() + val sharingStatus = settings.sharingStatusChanges.last() + sharingStatusDescription.text = sharingStatus.getDescription(app) + sharingStatusIcon.setImageDrawable(app.uiUtils.getIcon(sharingStatus.statusType.iconId, sharingStatus.statusType.iconColorRes)) } } @@ -589,7 +594,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { holder.stopSharingFirstPart?.apply { visibility = getStopSharingVisibility(expiresIn) - text = OsmandFormatter.getFormattedTime(expiresIn) + text = OsmandFormatter.getFormattedTime(expiresIn * 1000) } holder.stopSharingSecondPart?.apply { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt index 5610edef0c..77edb348db 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt @@ -5,14 +5,15 @@ import android.support.design.widget.BottomSheetBehavior import android.support.v4.app.DialogFragment import android.support.v4.app.Fragment import android.support.v4.app.FragmentManager +import android.support.v4.content.ContextCompat import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView -import android.widget.LinearLayout import android.widget.TextView import net.osmand.telegram.R import net.osmand.telegram.TelegramApplication +import net.osmand.telegram.TelegramSettings import net.osmand.telegram.ui.views.BottomSheetDialog import net.osmand.telegram.utils.OsmandFormatter @@ -42,7 +43,9 @@ class SharingStatusBottomSheet : DialogFragment() { }) val itemsCont = mainView.findViewById(R.id.items_container) - settings.sharingStatusChanges.reversed().forEach { sharingStatus -> + val items = settings.sharingStatusChanges.toArray().reversed() + for (i in items.indices) { + val sharingStatus = items[i] as TelegramSettings.SharingStatus inflater.inflate(R.layout.item_with_three_text_lines, itemsCont, false).apply { val sharingStatusType = sharingStatus.statusType val time = sharingStatus.locationTime @@ -52,20 +55,30 @@ class SharingStatusBottomSheet : DialogFragment() { findViewById(R.id.status_change_time).text = OsmandFormatter.getFormattedTime(sharingStatus.statusChangeTime, false) findViewById(R.id.last_location_line).text = getString(sharingStatusType.descriptionId) - if (time > 0) { - findViewById(R.id.last_location_line_time).text = OsmandFormatter.getFormattedTime(time, false) - } else { - findViewById(R.id.description_container).visibility = View.INVISIBLE + val descriptionTime = when { + time > 0 -> OsmandFormatter.getFormattedTime(time, false) + sharingStatusType == TelegramSettings.SharingStatusType.NO_GPS -> getString(R.string.not_found_yet) + else -> getString(R.string.not_sent_yet) } - if (sharingStatusType.canResendLocation) { - findViewById(R.id.re_send_location).apply { - setOnClickListener { - app.forceUpdateMyLocation() - dismiss() + + findViewById(R.id.last_location_line_time).text = descriptionTime + + findViewById(R.id.re_send_location).apply { + if (sharingStatusType.canResendLocation) { + if (i == 0) { + setOnClickListener { + app.forceUpdateMyLocation() + dismiss() + } + } else { + setTextColor(ContextCompat.getColor(context!!, R.color.secondary_text_light)) } + } else { + visibility = View.GONE } - } else { - findViewById(R.id.re_send_location).visibility = View.GONE + } + if (i == items.size - 1) { + findViewById(R.id.bottom_divider).visibility = View.GONE } itemsCont.addView(this) }