Merge pull request #5907 from osmandapp/TelegramImprovements
Telegram improvements
This commit is contained in:
commit
68d538bdc6
10 changed files with 33 additions and 18 deletions
|
@ -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" />
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:id="@+id/ending_in_first_part"
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
<string name="send_my_location">Send my location</string>
|
||||
<string name="gps_and_location">GPS & location</string>
|
||||
<string name="sharing_time">Sharing time</string>
|
||||
<string name="stop_at">Stop at</string>
|
||||
<string name="expire_in">Expire in</string>
|
||||
<string name="stop_sharing_all">Sharing is enabled (disable)</string>
|
||||
<string name="stop_sharing_chat">Stop chat sharing</string>
|
||||
<string name="turn_off_location_sharing">Turn off location sharing</string>
|
||||
<string name="open_osmand">Open OsmAnd</string>
|
||||
<string name="shared_string_live">Live</string>
|
||||
<string name="shared_string_bot">Bot</string>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<Long, Long>, 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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
""
|
||||
|
|
Loading…
Reference in a new issue