diff --git a/OsmAnd-telegram/res/layout/bottom_sheet_sharing_status.xml b/OsmAnd-telegram/res/layout/bottom_sheet_sharing_status.xml index c8504c9e9e..ff45754d6b 100644 --- a/OsmAnd-telegram/res/layout/bottom_sheet_sharing_status.xml +++ b/OsmAnd-telegram/res/layout/bottom_sheet_sharing_status.xml @@ -36,13 +36,13 @@ android:textColor="?android:textColorPrimary" android:textSize="@dimen/list_item_title_text_size" app:firstBaselineToTopHeight="28sp" - app:typeface="@string/font_roboto_medium"/> + app:typeface="@string/font_roboto_medium" /> + android:orientation="vertical" /> @@ -60,7 +60,7 @@ layout="@layout/secondary_btn" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="@dimen/content_padding_half"/> + android:layout_margin="@dimen/content_padding_half" /> diff --git a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml index 260bddf8a3..a8c954e11b 100644 --- a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml +++ b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml @@ -1,5 +1,6 @@ - + android:paddingRight="@dimen/my_location_text_sides_margin"> + tools:text="@string/sharing_enabled" /> + tools:visibility="visible" /> @@ -192,7 +191,7 @@ android:layout_height="1dp" android:layout_marginLeft="@dimen/content_padding_standard" android:layout_marginStart="@dimen/content_padding_standard" - android:background="?attr/card_divider_color"/> + android:background="?attr/card_divider_color" /> + app:typeface="@string/font_roboto_medium" /> + android:focusable="false" /> @@ -241,7 +240,7 @@ android:id="@+id/appbar_divider2" android:layout_width="1dp" android:layout_height="match_parent" - android:background="?attr/card_divider_color"/> + android:background="?attr/card_divider_color" /> + android:tint="@color/ctrl_active_light" /> + app:typeface="@string/font_roboto_regular" /> + tools:text="@string/no_gps_connection" /> @@ -302,8 +301,7 @@ + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + tools:visibility="visible" /> - + diff --git a/OsmAnd-telegram/res/layout/item_with_four_text_lines.xml b/OsmAnd-telegram/res/layout/item_with_four_text_lines.xml deleted file mode 100644 index 9c42bb2a35..0000000000 --- a/OsmAnd-telegram/res/layout/item_with_four_text_lines.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml b/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml new file mode 100644 index 0000000000..17238d40af --- /dev/null +++ b/OsmAnd-telegram/res/layout/item_with_three_text_lines.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index b74cf7bc41..4b90dd5a93 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -180,7 +180,6 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis updateShareInfoHandler?.postDelayed({ if (isUsedByMyLocation(usedBy)) { app().shareLocationHelper.updateSendLiveMessages() - app().settings.updateSharingStatusHistory() startShareInfoUpdates() } }, UPDATE_LIVE_MESSAGES_INTERVAL_MS) @@ -233,26 +232,24 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis } override fun onLocationChanged(l: Location?) { - if (l != null) { - val location = convertLocation(l) - if (!isContinuous()) { - // unregister listener and wait next time - val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager - try { - locationManager.removeUpdates(this) - } catch (e: Throwable) { - Log.d(PlatformUtil.TAG, "Location service permission not granted") //$NON-NLS-1$ - } - - val lock = getLock(this) - if (lock.isHeld) { - lock.release() - } - app().shareLocationHelper.updateLocation(location) - } else if (System.currentTimeMillis() - lastLocationSentTime > sendLocationInterval * 1000) { - lastLocationSentTime = System.currentTimeMillis() - app().shareLocationHelper.updateLocation(location) + val location = convertLocation(l) + if (!isContinuous()) { + // unregister listener and wait next time + val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager + try { + locationManager.removeUpdates(this) + } catch (e: Throwable) { + Log.d(PlatformUtil.TAG, "Location service permission not granted") //$NON-NLS-1$ } + + val lock = getLock(this) + if (lock.isHeld) { + lock.release() + } + app().shareLocationHelper.updateLocation(location) + } else if (System.currentTimeMillis() - lastLocationSentTime > sendLocationInterval * 1000) { + lastLocationSentTime = System.currentTimeMillis() + app().shareLocationHelper.updateLocation(location) } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index 175fbc734d..99bb983320 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -205,8 +205,7 @@ class TelegramSettings(private val app: TelegramApplication) { if (shareChatInfo != null && content is TdApi.MessageLocation) { shareChatInfo.currentMessageId = message.id shareChatInfo.lastSuccessfulLocation = LatLon(content.location.latitude, content.location.longitude) - shareChatInfo.lastSuccessfulSendTimeMs = Math.max(message.editDate, message.date) * - 1000L + shareChatInfo.lastSuccessfulSendTimeMs = Math.max(message.editDate, message.date) * 1000L } } @@ -214,14 +213,16 @@ class TelegramSettings(private val app: TelegramApplication) { val newSharingStatus = SharingStatus().apply { statusChangeTime = System.currentTimeMillis() statusType = if (!app.isInternetConnectionAvailable) { + locationTime = getLastSuccessfulSendTime() SharingStatusType.NO_INTERNET - } else if (app.locationProvider.lastKnownLocation == null || !app.locationProvider.gpsInfo.fixed) { + } else if (app.shareLocationHelper.lastLocation == null) { + locationTime = app.shareLocationHelper.lastLocationMessageSentTime SharingStatusType.NO_GPS } else { - var sendChatErrors = false + var sendChatsErrors = false shareChatsInfo.forEach { _, shareInfo -> - if ((statusChangeTime - shareInfo.lastSuccessfulSendTimeMs) > (sendMyLocInterval * 2) * 1000) { - sendChatErrors = true + if (shareInfo.hasSharingError) { + sendChatsErrors = true locationTime = shareInfo.lastSuccessfulSendTimeMs val title = app.telegramHelper.getChat(shareInfo.chatId)?.title if (title != null) { @@ -229,17 +230,13 @@ class TelegramSettings(private val app: TelegramApplication) { } } } - if (sendChatErrors) { + if (sendChatsErrors) { SharingStatusType.NOT_POSSIBLE_TO_SENT_TO_CHATS } else { + locationTime = getLastSuccessfulSendTime() SharingStatusType.SUCCESSFULLY_SENT } } - if (statusType == SharingStatusType.NO_INTERNET || statusType == SharingStatusType.SUCCESSFULLY_SENT) { - locationTime = getLastSuccessfulSendTime() - } else if (statusType == SharingStatusType.NO_GPS) { - locationTime = app.locationProvider.lastKnownLocationTime ?: -1 - } } if (sharingStatusChanges.isNotEmpty()) { @@ -575,12 +572,7 @@ class TelegramSettings(private val app: TelegramApplication) { val start = spannableString.length val newSpannable = if (iterator.hasNext()) " @$chatTitle," else " @$chatTitle." spannableString.append(newSpannable) - spannableString.setSpan( - ForegroundColorSpan(app.uiUtils.getActiveColor()), - start, - spannableString.length - 1, - 0 - ) + spannableString.setSpan(ForegroundColorSpan(app.uiUtils.getActiveColor()), start, spannableString.length - 1, 0) } spannableString } @@ -600,7 +592,8 @@ class TelegramSettings(private val app: TelegramApplication) { var lastSuccessfulSendTimeMs = -1L var shouldDeletePreviousMessage = false var additionalActiveTime = ADDITIONAL_ACTIVE_TIME_VALUES_SEC[0] - + var hasSharingError = false + fun getNextAdditionalActiveTime(): Long { var index = ADDITIONAL_ACTIVE_TIME_VALUES_SEC.indexOf(additionalActiveTime) return if (ADDITIONAL_ACTIVE_TIME_VALUES_SEC.lastIndex > index) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt index f0e043e8ed..9076646735 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt @@ -23,9 +23,7 @@ class ShareLocationHelper(private val app: TelegramApplication) { var lastLocationMessageSentTime: Long = 0 - private var lastTimeInMillis: Long = 0L - - private var lastLocation: Location? = null + var lastLocation: Location? = null set(value) { if (lastTimeInMillis == 0L) { lastTimeInMillis = System.currentTimeMillis() @@ -40,6 +38,8 @@ class ShareLocationHelper(private val app: TelegramApplication) { field = value } + private var lastTimeInMillis: Long = 0L + fun updateLocation(location: Location?) { lastLocation = location @@ -54,9 +54,10 @@ class ShareLocationHelper(private val app: TelegramApplication) { val url = "https://live.osmand.net/device/$sharingMode/send?lat=${location.latitude}&lon=${location.longitude}" AndroidNetworkUtils.sendRequestAsync(url, null) } - lastLocationMessageSentTime = System.currentTimeMillis() } + lastLocationMessageSentTime = System.currentTimeMillis() } + app.settings.updateSharingStatusHistory() refreshNotification() } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index ba67e21cdd..a99e852500 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -28,6 +28,7 @@ class TelegramHelper private constructor() { private val log = PlatformUtil.getLog(TelegramHelper::class.java) private const val CHATS_LIMIT = 100 private const val IGNORED_ERROR_CODE = 406 + private const val MESSAGE_CANNOT_BE_EDITED_ERROR_CODE = 5 private const val DEVICE_PREFIX = "Device: " private const val LOCATION_PREFIX = "Location: " @@ -97,7 +98,6 @@ class TelegramHelper private constructor() { private var haveAuthorization = false private val defaultHandler = DefaultHandler() - private val liveLocationMessageUpdatesHandler = LiveLocationMessageUpdatesHandler() private var updateLiveMessagesExecutor: ScheduledExecutorService? = null @@ -595,19 +595,19 @@ class TelegramHelper private constructor() { return false } - fun stopSendingLiveLocationToChat(chatId: Long, msgId: Long) { - if (msgId != -1L) { + fun stopSendingLiveLocationToChat(shareInfo: TelegramSettings.ShareChatInfo) { + if (shareInfo.currentMessageId != -1L && shareInfo.chatId != -1L) { client?.send( - TdApi.EditMessageLiveLocation(chatId, msgId, null, null), - liveLocationMessageUpdatesHandler - ) + TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMessageId, null, null)) { obj -> + handleLiveLocationMessageUpdate(obj, shareInfo) + } } needRefreshActiveLiveLocationMessages = true } fun stopSendingLiveLocationMessages(chatsShareInfo: Map) { - chatsShareInfo.forEach { (chatId, chatInfo) -> - stopSendingLiveLocationToChat(chatId, chatInfo.currentMessageId) + chatsShareInfo.forEach { (_, chatInfo) -> + stopSendingLiveLocationToChat(chatInfo) } } @@ -641,16 +641,14 @@ class TelegramHelper private constructor() { } } - private fun recreateLiveLocationMessage(chatId: Long, msgId: Long, content: TdApi.InputMessageLocation) { - if (msgId != -1L) { - log.info("recreateLiveLocationMessage - $msgId") + private fun recreateLiveLocationMessage(shareInfo: TelegramSettings.ShareChatInfo, content: TdApi.InputMessageLocation) { + if (shareInfo.currentMessageId != -1L && shareInfo.chatId != -1L) { + log.info("recreateLiveLocationMessage - $shareInfo.currentMessageId") val array = LongArray(1) - array[0] = msgId - client?.send(TdApi.DeleteMessages(chatId, array, true)) { obj -> + array[0] = shareInfo.currentMessageId + client?.send(TdApi.DeleteMessages(shareInfo.chatId, array, true)) { obj -> when (obj.constructor) { - TdApi.Ok.CONSTRUCTOR -> { - sendNewLiveLocationMessage(chatId, content) - } + TdApi.Ok.CONSTRUCTOR -> sendNewLiveLocationMessage(shareInfo, content) TdApi.Error.CONSTRUCTOR -> { val error = obj as TdApi.Error if (error.code != IGNORED_ERROR_CODE) { @@ -666,13 +664,13 @@ class TelegramHelper private constructor() { needRefreshActiveLiveLocationMessages = true } - private fun sendNewLiveLocationMessage(chatId: Long, content: TdApi.InputMessageLocation) { + private fun sendNewLiveLocationMessage(shareInfo: TelegramSettings.ShareChatInfo, content: TdApi.InputMessageLocation) { needRefreshActiveLiveLocationMessages = true log.info("sendNewLiveLocationMessage") client?.send( - TdApi.SendMessage(chatId, 0, false, true, null, content), - liveLocationMessageUpdatesHandler - ) + TdApi.SendMessage(shareInfo.chatId, 0, false, true, null, content)) { obj -> + handleLiveLocationMessageUpdate(obj, shareInfo) + } } private fun sendLiveLocationImpl(chatsShareInfo: Map, latitude: Double, longitude: Double) { @@ -688,18 +686,51 @@ class TelegramHelper private constructor() { val msgId = shareInfo.currentMessageId if (msgId != -1L) { if (shareInfo.shouldDeletePreviousMessage) { - recreateLiveLocationMessage(chatId, msgId, content) + recreateLiveLocationMessage(shareInfo, content) shareInfo.shouldDeletePreviousMessage = false shareInfo.currentMessageId = -1 } else { log.info("EditMessageLiveLocation - $msgId") client?.send( - TdApi.EditMessageLiveLocation(chatId, msgId, null, location), - liveLocationMessageUpdatesHandler - ) + TdApi.EditMessageLiveLocation(chatId, msgId, null, location)) { obj -> + handleLiveLocationMessageUpdate(obj, shareInfo) + } } } else { - sendNewLiveLocationMessage(chatId, content) + sendNewLiveLocationMessage(shareInfo, content) + } + } + } + + private fun handleLiveLocationMessageUpdate(obj: TdApi.Object, shareInfo: TelegramSettings.ShareChatInfo) { + when (obj.constructor) { + TdApi.Error.CONSTRUCTOR -> { + val error = obj as TdApi.Error + needRefreshActiveLiveLocationMessages = true + if (error.code == MESSAGE_CANNOT_BE_EDITED_ERROR_CODE) { + shareInfo.shouldDeletePreviousMessage = true + } else if (error.code != IGNORED_ERROR_CODE) { + shareInfo.hasSharingError = true + outgoingMessagesListeners.forEach { + it.onSendLiveLocationError(error.code, error.message) + } + } + } + TdApi.Message.CONSTRUCTOR -> { + if (obj is TdApi.Message) { + if (obj.sendingState?.constructor == TdApi.MessageSendingStateFailed.CONSTRUCTOR) { + shareInfo.hasSharingError = true + needRefreshActiveLiveLocationMessages = true + outgoingMessagesListeners.forEach { + it.onSendLiveLocationError(-1, "Live location message ${obj.id} failed to send") + } + } else { + shareInfo.hasSharingError = false + outgoingMessagesListeners.forEach { + it.onUpdateMessages(listOf(obj)) + } + } + } } } } @@ -757,36 +788,6 @@ class TelegramHelper private constructor() { } } - private inner class LiveLocationMessageUpdatesHandler : ResultHandler { - override fun onResult(obj: TdApi.Object) { - when (obj.constructor) { - TdApi.Error.CONSTRUCTOR -> { - val error = obj as TdApi.Error - if (error.code != IGNORED_ERROR_CODE) { - needRefreshActiveLiveLocationMessages = true - outgoingMessagesListeners.forEach { - it.onSendLiveLocationError(error.code, error.message) - } - } - } - TdApi.Message.CONSTRUCTOR -> { - if (obj is TdApi.Message) { - if (obj.sendingState?.constructor == TdApi.MessageSendingStateFailed.CONSTRUCTOR) { - needRefreshActiveLiveLocationMessages = true - outgoingMessagesListeners.forEach { - it.onSendLiveLocationError(-1, "Live location message ${obj.id} failed to send") - } - } else { - outgoingMessagesListeners.forEach { - it.onUpdateMessages(listOf(obj)) - } - } - } - } - } - } - } - private fun onAuthorizationStateUpdated(authorizationState: AuthorizationState?, info: Boolean = false) { val prevAuthState = getTelegramAuthorizationState() if (authorizationState != null) { @@ -809,7 +810,10 @@ class TelegramHelper private constructor() { parameters.applicationVersion = "1.0" parameters.enableStorageOptimizer = true - client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler()) + client!!.send( + TdApi.SetTdlibParameters(parameters), + AuthorizationRequestHandler() + ) } } TdApi.AuthorizationStateWaitEncryptionKey.CONSTRUCTOR -> { @@ -819,15 +823,21 @@ class TelegramHelper private constructor() { } TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR -> { log.info("Request phone number") - telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter(PHONE_NUMBER) + telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter( + PHONE_NUMBER + ) } TdApi.AuthorizationStateWaitCode.CONSTRUCTOR -> { log.info("Request code") - telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter(CODE) + telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter( + CODE + ) } TdApi.AuthorizationStateWaitPassword.CONSTRUCTOR -> { log.info("Request password") - telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter(PASSWORD) + telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter( + PASSWORD + ) } TdApi.AuthorizationStateReady.CONSTRUCTOR -> { log.info("Ready") @@ -844,7 +854,8 @@ class TelegramHelper private constructor() { else -> log.error("Unsupported authorization state: " + this.authorizationState!!) } val wasAuthorized = haveAuthorization - haveAuthorization = this.authorizationState?.constructor == TdApi.AuthorizationStateReady.CONSTRUCTOR + haveAuthorization = this.authorizationState?.constructor == + TdApi.AuthorizationStateReady.CONSTRUCTOR if (wasAuthorized != haveAuthorization) { needRefreshActiveLiveLocationMessages = true if (haveAuthorization) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index c15f4bbcc2..2520247877 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -74,7 +74,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { private var actionButtonsListener: ActionButtonsListener? = null private var sharingMode = false - + private var updateEnable: Boolean = false override fun onCreateView( @@ -93,7 +93,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { searchBoxSidesMargin = resources.getDimensionPixelSize(R.dimen.content_padding_half) sharingMode = settings.hasAnyChatToShareLocation() - + savedInstanceState?.apply { selectedChats.addAll(getLongArray(SELECTED_CHATS_KEY).toSet()) if (selectedChats.isNotEmpty()) { @@ -193,7 +193,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } mainView.findViewById(R.id.sharing_status_container).setOnClickListener { - settings.updateSharingStatusHistory() fragmentManager?.also { fm -> SharingStatusBottomSheet.showInstance(fm, this) } @@ -211,7 +210,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { updateContent() } } - + return mainView } @@ -228,7 +227,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { super.onPause() updateEnable = false } - + override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putLongArray(SELECTED_CHATS_KEY, selectedChats.toLongArray()) @@ -247,6 +246,9 @@ class MyLocationTabFragment : Fragment(), TelegramListener { app.stopSharingLocation() updateContent() } + SharingStatusBottomSheet.SHARING_STATUS_REQUEST_CODE -> { + updateSharingStatus() + } } } @@ -323,7 +325,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } }, ADAPTER_UPDATE_INTERVAL_MIL) } - + private fun animateStartSharingBtn(show: Boolean) { if (startSharingBtn.visibility == View.VISIBLE) { val scale = if (show) 1f else 0f @@ -335,7 +337,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { .start() } } - + private fun clearSelection() { selectedChats.clear() adapter.notifyDataSetChanged() @@ -429,17 +431,16 @@ class MyLocationTabFragment : Fragment(), TelegramListener { private fun updateSharingStatus() { if (sharingMode) { - if (settings.sharingStatusChanges.isEmpty()) { - settings.updateSharingStatusHistory() + if (settings.sharingStatusChanges.isNotEmpty()) { + sharingStatusDescription.text = settings.sharingStatusChanges.last().getDescription(app) } - sharingStatusDescription.text = settings.sharingStatusChanges.last().getDescription(app) } } private fun updateList() { val chats: MutableList = mutableListOf() val currentUser = telegramHelper.getCurrentUser() - val chatList = if (sharingMode && settings.hasAnyChatToShareLocation()) { + val chatList = if (sharingMode) { settings.getShareLocationChats() } else { telegramHelper.getChatListIds() @@ -468,7 +469,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { list.sortWith(Comparator { o1, o2 -> o1.title.compareTo(o2.title) }) return list } - + inner class MyLocationListAdapter : RecyclerView.Adapter() { var chats = mutableListOf() set(value) { @@ -547,10 +548,9 @@ class MyLocationTabFragment : Fragment(), TelegramListener { isChecked = live setOnCheckedChangeListener { _, isChecked -> if (!isChecked) { - val currentMessageId = shareInfo?.currentMessageId settings.shareLocationToChat(chat.id, false) - if (currentMessageId != null) { - telegramHelper.stopSendingLiveLocationToChat(chat.id, currentMessageId) + if (shareInfo != null) { + telegramHelper.stopSendingLiveLocationToChat(shareInfo) } removeItem(chat) } @@ -567,7 +567,7 @@ 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 diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt index 955d10b033..825e9a4f72 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SharingStatusBottomSheet.kt @@ -12,7 +12,6 @@ import android.widget.ImageView 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 @@ -24,17 +23,16 @@ class SharingStatusBottomSheet : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!) - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val mainView = inflater.inflate(R.layout.bottom_sheet_sharing_status, container, false) mainView.findViewById(R.id.scroll_view_container).setOnClickListener { dismiss() } BottomSheetBehavior.from(mainView.findViewById(R.id.scroll_view)) .setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(bottomSheet: View, newState: Int) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { + targetFragment?.also { target -> + target.onActivityResult(targetRequestCode, SHARING_STATUS_REQUEST_CODE, null) + } dismiss() } } @@ -44,7 +42,7 @@ class SharingStatusBottomSheet : DialogFragment() { val itemsCont = mainView.findViewById(R.id.items_container) settings.sharingStatusChanges.reversed().forEach { sharingStatus -> - inflater.inflate(R.layout.item_with_four_text_lines, itemsCont, false).apply { + inflater.inflate(R.layout.item_with_three_text_lines, itemsCont, false).apply { val sharingStatusType = sharingStatus.statusType findViewById(R.id.icon).setImageDrawable(uiUtils.getIcon(sharingStatusType.iconId, sharingStatusType.iconColorRes)) findViewById(R.id.title).text = sharingStatus.getDescription(app) @@ -71,10 +69,14 @@ class SharingStatusBottomSheet : DialogFragment() { itemsCont.addView(this) } } - mainView.findViewById(R.id.secondary_btn).apply { setText(R.string.shared_string_close) - setOnClickListener { dismiss() } + setOnClickListener { + targetFragment?.also { target -> + target.onActivityResult(targetRequestCode, SHARING_STATUS_REQUEST_CODE, null) + } + dismiss() + } } return mainView } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt b/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt index 803fd2f4be..7e8e4d9b32 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt @@ -19,9 +19,9 @@ object OsmandFormatter { val FEET_IN_ONE_METER = YARDS_IN_ONE_METER * 3f private val fixed2 = DecimalFormat("0.00") private val fixed1 = DecimalFormat("0.0") - + private const val SHORT_TIME_FORMAT = "%02d:%02d" - private const val SIMPLE_TIME_OF_DAY_FORMAT = "HH:mm:ss" + private const val SIMPLE_TIME_OF_DAY_FORMAT = "HH:mm" private const val SIMPLE_DATE_FORMAT = "dd MMM HH:mm:ss" private const val MIN_DURATION_FOR_DATE_FORMAT = 48 * 60 * 60