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_gravity="center_vertical"
|
||||||
android:layout_marginEnd="@dimen/content_padding_standard"
|
android:layout_marginEnd="@dimen/content_padding_standard"
|
||||||
android:layout_marginRight="@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:textColor="?attr/ctrl_active_color"
|
||||||
android:textSize="@dimen/hint_text_size"
|
android:textSize="@dimen/hint_text_size"
|
||||||
app:typeface="@string/font_roboto_medium" />
|
app:typeface="@string/font_roboto_medium" />
|
||||||
|
@ -147,7 +147,7 @@
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:textSize="@dimen/hint_text_size"
|
android:textSize="@dimen/hint_text_size"
|
||||||
app:typeface="@string/font_roboto_regular"
|
app:typeface="@string/font_roboto_regular"
|
||||||
tools:text="@string/stop_at" />
|
tools:text="@string/expire_in" />
|
||||||
|
|
||||||
<net.osmand.telegram.ui.views.TextViewEx
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
android:id="@+id/ending_in_first_part"
|
android:id="@+id/ending_in_first_part"
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
<string name="send_my_location">Send my location</string>
|
<string name="send_my_location">Send my location</string>
|
||||||
<string name="gps_and_location">GPS & location</string>
|
<string name="gps_and_location">GPS & location</string>
|
||||||
<string name="sharing_time">Sharing time</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_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="open_osmand">Open OsmAnd</string>
|
||||||
<string name="shared_string_live">Live</string>
|
<string name="shared_string_live">Live</string>
|
||||||
<string name="shared_string_bot">Bot</string>
|
<string name="shared_string_bot">Bot</string>
|
||||||
|
|
|
@ -162,6 +162,11 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
fun getShowOnMapChatsCount() = showOnMapChats.size
|
fun getShowOnMapChatsCount() = showOnMapChats.size
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
stopSharingLocationToChats()
|
||||||
|
app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE).edit().clear().apply()
|
||||||
|
}
|
||||||
|
|
||||||
fun save() {
|
fun save() {
|
||||||
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
||||||
val edit = prefs.edit()
|
val edit = prefs.edit()
|
||||||
|
|
|
@ -35,12 +35,16 @@ class MessagesDbHelper(val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveMessages() {
|
fun saveMessages() {
|
||||||
sqliteHelper.clearMessages()
|
clearMessages()
|
||||||
synchronized(messages) {
|
synchronized(messages) {
|
||||||
sqliteHelper.addMessages(messages)
|
sqliteHelper.addMessages(messages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearMessages() {
|
||||||
|
sqliteHelper.clearMessages()
|
||||||
|
}
|
||||||
|
|
||||||
private fun addMessage(chatId: Long, messageId: Long) {
|
private fun addMessage(chatId: Long, messageId: Long) {
|
||||||
synchronized(messages) {
|
synchronized(messages) {
|
||||||
messages.add(Message(chatId, messageId))
|
messages.add(Message(chatId, messageId))
|
||||||
|
|
|
@ -575,7 +575,7 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopSendingLiveLocationMessages() {
|
fun stopSendingLiveLocationMessages() {
|
||||||
chatLiveMessages.forEach { chatId, _ ->
|
chatLiveMessages.forEach { (chatId, _ )->
|
||||||
stopSendingLiveLocationToChat(chatId)
|
stopSendingLiveLocationToChat(chatId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -610,7 +610,7 @@ class TelegramHelper private constructor() {
|
||||||
|
|
||||||
private fun sendLiveLocationImpl(chatLivePeriods: Map<Long, Long>, latitude: Double, longitude: Double) {
|
private fun sendLiveLocationImpl(chatLivePeriods: Map<Long, Long>, latitude: Double, longitude: Double) {
|
||||||
val location = TdApi.Location(latitude, longitude)
|
val location = TdApi.Location(latitude, longitude)
|
||||||
chatLivePeriods.forEach { chatId, livePeriod ->
|
chatLivePeriods.forEach { (chatId, livePeriod) ->
|
||||||
val content = TdApi.InputMessageLocation(location, livePeriod.toInt())
|
val content = TdApi.InputMessageLocation(location, livePeriod.toInt())
|
||||||
val msgId = chatLiveMessages[chatId]?.id
|
val msgId = chatLiveMessages[chatId]?.id
|
||||||
if (msgId != null) {
|
if (msgId != null) {
|
||||||
|
|
|
@ -214,7 +214,7 @@ class LoginDialogFragment : BaseDialogFragment() {
|
||||||
var focusRequested = false
|
var focusRequested = false
|
||||||
for (t in LoginDialogType.values()) {
|
for (t in LoginDialogType.values()) {
|
||||||
val layout: View? = view?.findViewById(t.viewId)
|
val layout: View? = view?.findViewById(t.viewId)
|
||||||
val contains = t == loginDialogActiveType && !showProgress
|
val contains = t == loginDialogActiveType
|
||||||
when {
|
when {
|
||||||
contains -> {
|
contains -> {
|
||||||
if (layout != null) {
|
if (layout != null) {
|
||||||
|
|
|
@ -155,8 +155,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
|
|
||||||
if (AndroidUtils.isLocationPermissionAvailable(this)) {
|
if (AndroidUtils.isLocationPermissionAvailable(this)) {
|
||||||
app.locationProvider.resumeAllUpdates()
|
app.locationProvider.resumeAllUpdates()
|
||||||
} else {
|
|
||||||
AndroidUtils.requestLocationPermission(this)
|
|
||||||
}
|
}
|
||||||
if (settings.hasAnyChatToShowOnMap() && !isOsmAndInstalled()) {
|
if (settings.hasAnyChatToShowOnMap() && !isOsmAndInstalled()) {
|
||||||
showOsmandMissingDialog()
|
showOsmandMissingDialog()
|
||||||
|
@ -196,7 +194,14 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
telegramHelper.init()
|
telegramHelper.init()
|
||||||
telegramHelper.requestAuthorizationState()
|
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
|
else -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,6 +278,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
fun logoutTelegram(silent: Boolean = false) {
|
fun logoutTelegram(silent: Boolean = false) {
|
||||||
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
|
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
|
||||||
if (app.isInternetConnectionAvailable) {
|
if (app.isInternetConnectionAvailable) {
|
||||||
|
app.messagesDbHelper.clearMessages()
|
||||||
|
settings.clear()
|
||||||
telegramHelper.logout()
|
telegramHelper.logout()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, R.string.logout_no_internet_msg, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.logout_no_internet_msg, Toast.LENGTH_SHORT).show()
|
||||||
|
|
|
@ -578,7 +578,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
|
|
||||||
holder.stopSharingDescr?.apply {
|
holder.stopSharingDescr?.apply {
|
||||||
visibility = getStopSharingVisibility(expiresIn)
|
visibility = getStopSharingVisibility(expiresIn)
|
||||||
text = "${getText(R.string.stop_at)}:"
|
text = "${getText(R.string.expire_in)}:"
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.stopSharingFirstPart?.apply {
|
holder.stopSharingFirstPart?.apply {
|
||||||
|
|
|
@ -87,7 +87,7 @@ class SetTimeDialogFragment : BaseDialogFragment(), TelegramLocationListener, Te
|
||||||
if (!AndroidUtils.isLocationPermissionAvailable(view.context)) {
|
if (!AndroidUtils.isLocationPermissionAvailable(view.context)) {
|
||||||
AndroidUtils.requestLocationPermission(activity!!)
|
AndroidUtils.requestLocationPermission(activity!!)
|
||||||
} else {
|
} else {
|
||||||
chatLivePeriods.forEach { chatId, livePeriod ->
|
chatLivePeriods.forEach { (chatId, livePeriod) ->
|
||||||
settings.shareLocationToChat(chatId, true, livePeriod)
|
settings.shareLocationToChat(chatId, true, livePeriod)
|
||||||
}
|
}
|
||||||
app.shareLocationHelper.startSharingLocation()
|
app.shareLocationHelper.startSharingLocation()
|
||||||
|
|
|
@ -79,11 +79,10 @@ object OsmandFormatter {
|
||||||
fun getListItemLiveTimeDescr(ctx: TelegramApplication, lastUpdated: Int, prefix: String = ""): String {
|
fun getListItemLiveTimeDescr(ctx: TelegramApplication, lastUpdated: Int, prefix: String = ""): String {
|
||||||
return if (lastUpdated > 0) {
|
return if (lastUpdated > 0) {
|
||||||
val duration = System.currentTimeMillis() / 1000 - lastUpdated
|
val duration = System.currentTimeMillis() / 1000 - lastUpdated
|
||||||
if (duration > MIN_DURATION_FOR_DATE_FORMAT) {
|
when {
|
||||||
prefix + getFormattedDate(lastUpdated.toLong())
|
duration > MIN_DURATION_FOR_DATE_FORMAT -> prefix + getFormattedDate(lastUpdated.toLong())
|
||||||
} else {
|
duration > 0 -> prefix + getFormattedDuration(ctx, duration) + " " + ctx.getString(R.string.time_ago)
|
||||||
prefix + getFormattedDuration(ctx, duration) + " " +
|
else -> ""
|
||||||
ctx.getString(R.string.time_ago)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
|
Loading…
Reference in a new issue