diff --git a/OsmAnd-telegram/res/layout/my_location_sharing_chat.xml b/OsmAnd-telegram/res/layout/my_location_sharing_chat.xml index 0c3d10b782..872b7b2afb 100644 --- a/OsmAnd-telegram/res/layout/my_location_sharing_chat.xml +++ b/OsmAnd-telegram/res/layout/my_location_sharing_chat.xml @@ -129,7 +129,7 @@ android:layout_gravity="center_vertical" android:layout_marginEnd="@dimen/content_padding_standard" android:layout_marginRight="@dimen/content_padding_standard" - android:text="@string/stop_sharing_chat" + android:text="@string/turn_off_location_sharing" android:textColor="?attr/ctrl_active_color" android:textSize="@dimen/hint_text_size" app:typeface="@string/font_roboto_medium" /> @@ -147,7 +147,7 @@ android:textColor="?android:attr/textColorSecondary" android:textSize="@dimen/hint_text_size" app:typeface="@string/font_roboto_regular" - tools:text="@string/stop_at" /> + tools:text="@string/expire_in" /> Send my location GPS & location Sharing time - Stop at + Expire in Sharing is enabled (disable) - Stop chat sharing + Turn off location sharing Open OsmAnd Live Bot diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index 6804f10f5a..35063c8a82 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -162,6 +162,11 @@ class TelegramSettings(private val app: TelegramApplication) { fun getShowOnMapChatsCount() = showOnMapChats.size + fun clear() { + stopSharingLocationToChats() + app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE).edit().clear().apply() + } + fun save() { val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE) val edit = prefs.edit() diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/MessagesDbHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/MessagesDbHelper.kt index 6e505bc9aa..dcd4d67c46 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/MessagesDbHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/MessagesDbHelper.kt @@ -35,11 +35,15 @@ class MessagesDbHelper(val app: TelegramApplication) { } fun saveMessages() { - sqliteHelper.clearMessages() + clearMessages() synchronized(messages) { sqliteHelper.addMessages(messages) } } + + fun clearMessages() { + sqliteHelper.clearMessages() + } private fun addMessage(chatId: Long, messageId: Long) { synchronized(messages) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 73489acfdf..ba8a59ace9 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -575,7 +575,7 @@ class TelegramHelper private constructor() { } fun stopSendingLiveLocationMessages() { - chatLiveMessages.forEach { chatId, _ -> + chatLiveMessages.forEach { (chatId, _ )-> stopSendingLiveLocationToChat(chatId) } } @@ -610,7 +610,7 @@ class TelegramHelper private constructor() { private fun sendLiveLocationImpl(chatLivePeriods: Map, latitude: Double, longitude: Double) { val location = TdApi.Location(latitude, longitude) - chatLivePeriods.forEach { chatId, livePeriod -> + chatLivePeriods.forEach { (chatId, livePeriod) -> val content = TdApi.InputMessageLocation(location, livePeriod.toInt()) val msgId = chatLiveMessages[chatId]?.id if (msgId != null) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt index 4ae7441621..dcf24d5f3b 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt @@ -214,7 +214,7 @@ class LoginDialogFragment : BaseDialogFragment() { var focusRequested = false for (t in LoginDialogType.values()) { val layout: View? = view?.findViewById(t.viewId) - val contains = t == loginDialogActiveType && !showProgress + val contains = t == loginDialogActiveType when { contains -> { if (layout != null) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index bea87d42a2..1d1402abcf 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -155,8 +155,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene if (AndroidUtils.isLocationPermissionAvailable(this)) { app.locationProvider.resumeAllUpdates() - } else { - AndroidUtils.requestLocationPermission(this) } if (settings.hasAnyChatToShowOnMap() && !isOsmAndInstalled()) { showOsmandMissingDialog() @@ -196,7 +194,14 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene telegramHelper.init() telegramHelper.requestAuthorizationState() } - TelegramAuthorizationState.READY -> LoginDialogFragment.dismiss(fm) + TelegramAuthorizationState.READY -> { + LoginDialogFragment.dismiss(fm) + if (AndroidUtils.isLocationPermissionAvailable(this)) { + app.locationProvider.resumeAllUpdates() + } else { + AndroidUtils.requestLocationPermission(this) + } + } else -> Unit } @@ -273,6 +278,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene fun logoutTelegram(silent: Boolean = false) { if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) { if (app.isInternetConnectionAvailable) { + app.messagesDbHelper.clearMessages() + settings.clear() telegramHelper.logout() } else { Toast.makeText(this, R.string.logout_no_internet_msg, Toast.LENGTH_SHORT).show() diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 3d9af9f7aa..f8d233369a 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -578,7 +578,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { holder.stopSharingDescr?.apply { visibility = getStopSharingVisibility(expiresIn) - text = "${getText(R.string.stop_at)}:" + text = "${getText(R.string.expire_in)}:" } holder.stopSharingFirstPart?.apply { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt index 2e866ae624..c7d49771fe 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt @@ -87,7 +87,7 @@ class SetTimeDialogFragment : BaseDialogFragment(), TelegramLocationListener, Te if (!AndroidUtils.isLocationPermissionAvailable(view.context)) { AndroidUtils.requestLocationPermission(activity!!) } else { - chatLivePeriods.forEach { chatId, livePeriod -> + chatLivePeriods.forEach { (chatId, livePeriod) -> settings.shareLocationToChat(chatId, true, livePeriod) } app.shareLocationHelper.startSharingLocation() diff --git a/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt b/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt index 4d50cb347b..371d91b657 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/utils/OsmandFormatter.kt @@ -79,11 +79,10 @@ object OsmandFormatter { fun getListItemLiveTimeDescr(ctx: TelegramApplication, lastUpdated: Int, prefix: String = ""): String { return if (lastUpdated > 0) { val duration = System.currentTimeMillis() / 1000 - lastUpdated - if (duration > MIN_DURATION_FOR_DATE_FORMAT) { - prefix + getFormattedDate(lastUpdated.toLong()) - } else { - prefix + getFormattedDuration(ctx, duration) + " " + - ctx.getString(R.string.time_ago) + when { + duration > MIN_DURATION_FOR_DATE_FORMAT -> prefix + getFormattedDate(lastUpdated.toLong()) + duration > 0 -> prefix + getFormattedDuration(ctx, duration) + " " + ctx.getString(R.string.time_ago) + else -> "" } } else { ""