Merge pull request #6186 from osmandapp/TelegramImprovements

Telegram status improvements
This commit is contained in:
Alexander Sytnyk 2018-10-17 18:58:25 +03:00 committed by GitHub
commit bc764165b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 21 deletions

View file

@ -79,8 +79,8 @@
android:id="@+id/last_location_line_time" android:id="@+id/last_location_line_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="@dimen/content_padding_half" android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_half" android:paddingRight="@dimen/content_padding_small"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size" android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="22dp" app:firstBaselineToTopHeight="22dp"

View file

@ -1,4 +1,6 @@
<resources> <resources>
<string name="not_sent_yet">Not sent yet</string>
<string name="not_found_yet">Not found yet</string>
<string name="re_send_location">Re-send location</string> <string name="re_send_location">Re-send location</string>
<string name="last_sent_location">Last sent location</string> <string name="last_sent_location">Last sent location</string>
<string name="last_available_location">Last available location</string> <string name="last_available_location">Last available location</string>

View file

@ -191,7 +191,6 @@ class TelegramSettings(private val app: TelegramApplication) {
val shareChatInfo = shareChatsInfo[message.chatId] val shareChatInfo = shareChatsInfo[message.chatId]
val content = message.content val content = message.content
if (shareChatInfo != null && content is TdApi.MessageLocation) { if (shareChatInfo != null && content is TdApi.MessageLocation) {
shareChatInfo.start = message.date.toLong()
shareChatInfo.currentMessageId = message.id shareChatInfo.currentMessageId = message.id
shareChatInfo.lastSuccessfulLocation = LatLon(content.location.latitude, content.location.longitude) 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
@ -210,7 +209,7 @@ class TelegramSettings(private val app: TelegramApplication) {
} else { } else {
var sendChatsErrors = false var sendChatsErrors = false
shareChatsInfo.forEach { _, shareInfo -> shareChatsInfo.forEach { _, shareInfo ->
if (shareInfo.hasSharingError) { if (shareInfo.hasSharingError || shareInfo.lastSuccessfulSendTimeMs == -1L) {
sendChatsErrors = true sendChatsErrors = true
locationTime = shareInfo.lastSuccessfulSendTimeMs locationTime = shareInfo.lastSuccessfulSendTimeMs
val title = app.telegramHelper.getChat(shareInfo.chatId)?.title val title = app.telegramHelper.getChat(shareInfo.chatId)?.title

View file

@ -60,6 +60,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private lateinit var searchBox: FrameLayout private lateinit var searchBox: FrameLayout
private lateinit var stopSharingSwitcher: Switch private lateinit var stopSharingSwitcher: Switch
private lateinit var sharingStatusDescription: TextView private lateinit var sharingStatusDescription: TextView
private lateinit var sharingStatusIcon: ImageView
private lateinit var startSharingBtn: View private lateinit var startSharingBtn: View
private lateinit var searchBoxBg: GradientDrawable private lateinit var searchBoxBg: GradientDrawable
@ -143,7 +144,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
text = spannable text = spannable
} }
mainView.findViewById<ImageView>(R.id.sharing_status_icon).setImageDrawable(app.uiUtils.getActiveIcon(R.drawable.ic_action_live_now)) sharingStatusIcon = mainView.findViewById<ImageView>(R.id.sharing_status_icon)
textContainer = mainView.findViewById<LinearLayout>(R.id.text_container).apply { textContainer = mainView.findViewById<LinearLayout>(R.id.text_container).apply {
if (Build.VERSION.SDK_INT >= 16) { if (Build.VERSION.SDK_INT >= 16) {
@ -195,6 +196,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
mainView.findViewById<View>(R.id.sharing_status_container).setOnClickListener { mainView.findViewById<View>(R.id.sharing_status_container).setOnClickListener {
settings.updateSharingStatusHistory()
updateSharingStatus()
fragmentManager?.also { fm -> fragmentManager?.also { fm ->
SharingStatusBottomSheet.showInstance(fm, this) SharingStatusBottomSheet.showInstance(fm, this)
} }
@ -433,8 +436,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
private fun updateSharingStatus() { private fun updateSharingStatus() {
if (sharingMode && settings.sharingStatusChanges.isNotEmpty()) { if (sharingMode) {
sharingStatusDescription.text = settings.sharingStatusChanges.last().getDescription(app) 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 +595,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
holder.stopSharingFirstPart?.apply { holder.stopSharingFirstPart?.apply {
visibility = getStopSharingVisibility(expiresIn) visibility = getStopSharingVisibility(expiresIn)
text = OsmandFormatter.getFormattedTime(expiresIn) text = OsmandFormatter.getFormattedTime(expiresIn * 1000)
} }
holder.stopSharingSecondPart?.apply { holder.stopSharingSecondPart?.apply {

View file

@ -5,14 +5,15 @@ import android.support.design.widget.BottomSheetBehavior
import android.support.v4.app.DialogFragment import android.support.v4.app.DialogFragment
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
import android.support.v4.content.ContextCompat
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import net.osmand.telegram.R import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.TelegramSettings
import net.osmand.telegram.ui.views.BottomSheetDialog import net.osmand.telegram.ui.views.BottomSheetDialog
import net.osmand.telegram.utils.OsmandFormatter import net.osmand.telegram.utils.OsmandFormatter
@ -42,7 +43,9 @@ class SharingStatusBottomSheet : DialogFragment() {
}) })
val itemsCont = mainView.findViewById<ViewGroup>(R.id.items_container) val itemsCont = mainView.findViewById<ViewGroup>(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 { inflater.inflate(R.layout.item_with_three_text_lines, itemsCont, false).apply {
val sharingStatusType = sharingStatus.statusType val sharingStatusType = sharingStatus.statusType
val time = sharingStatus.locationTime val time = sharingStatus.locationTime
@ -52,20 +55,30 @@ class SharingStatusBottomSheet : DialogFragment() {
findViewById<TextView>(R.id.status_change_time).text = OsmandFormatter.getFormattedTime(sharingStatus.statusChangeTime, false) findViewById<TextView>(R.id.status_change_time).text = OsmandFormatter.getFormattedTime(sharingStatus.statusChangeTime, false)
findViewById<TextView>(R.id.last_location_line).text = getString(sharingStatusType.descriptionId) findViewById<TextView>(R.id.last_location_line).text = getString(sharingStatusType.descriptionId)
if (time > 0) { val descriptionTime = when {
findViewById<TextView>(R.id.last_location_line_time).text = OsmandFormatter.getFormattedTime(time, false) time > 0 -> OsmandFormatter.getFormattedTime(time, false)
} else { sharingStatusType == TelegramSettings.SharingStatusType.NO_GPS -> getString(R.string.not_found_yet)
findViewById<LinearLayout>(R.id.description_container).visibility = View.INVISIBLE else -> getString(R.string.not_sent_yet)
} }
if (sharingStatusType.canResendLocation) {
findViewById<TextView>(R.id.re_send_location).apply { findViewById<TextView>(R.id.last_location_line_time).text = descriptionTime
setOnClickListener {
app.forceUpdateMyLocation() findViewById<TextView>(R.id.re_send_location).apply {
dismiss() 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<TextView>(R.id.re_send_location).visibility = View.GONE if (i == items.size - 1) {
findViewById<View>(R.id.bottom_divider).visibility = View.GONE
} }
itemsCont.addView(this) itemsCont.addView(this)
} }