Fix direction arrow and distance text on "Live now" screen

This commit is contained in:
Alex Sytnyk 2018-07-06 18:44:23 +03:00
parent fb0b299760
commit 50286c32e3
3 changed files with 16 additions and 32 deletions

View file

@ -3,6 +3,7 @@ package net.osmand.telegram.helpers
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.widget.ImageView
import net.osmand.data.LatLon
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.helpers.TelegramHelper.MessageOsmAndBotLocation
@ -48,8 +49,7 @@ object TelegramUiHelper {
if (chatType is TdApi.ChatTypePrivate && !helper.isBot(chatType.userId)) {
val content = messages.firstOrNull()?.content
if (content is TdApi.MessageLocation) {
res.lat = content.location.latitude
res.lon = content.location.longitude
res.latLon = LatLon(content.location.latitude, content.location.longitude)
}
}
return res
@ -68,8 +68,7 @@ object TelegramUiHelper {
return if (content.isValid()) {
LocationItem().apply {
name = content.name
lat = content.lat
lon = content.lon
latLon = LatLon(content.lat, content.lon)
placeholderId = R.drawable.ic_group
}
} else {
@ -91,8 +90,7 @@ object TelegramUiHelper {
if (name.isEmpty()) {
name = user.phoneNumber
}
lat = content.location.latitude
lon = content.location.longitude
latLon = LatLon(content.location.latitude, content.location.longitude)
photoPath = helper.getUserPhotoPath(user)
placeholderId = R.drawable.ic_group
}
@ -101,9 +99,7 @@ object TelegramUiHelper {
class ChatItem {
var title: String = ""
internal set
var lat: Double = 0.0
internal set
var lon: Double = 0.0
var latLon: LatLon? = null
internal set
var photoPath: String? = null
internal set
@ -114,9 +110,7 @@ object TelegramUiHelper {
class LocationItem {
var name: String = ""
internal set
var lat: Double = 0.0
internal set
var lon: Double = 0.0
var latLon: LatLon? = null
internal set
var photoPath: String? = null
internal set

View file

@ -240,8 +240,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
app.uiUtils.updateLocationView(
holder.directionIcon,
holder.distanceText,
location!!.latitude,
location!!.longitude,
item.latLon,
locationViewCache
)
} else {
@ -262,8 +261,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
app.uiUtils.updateLocationView(
holder.directionIcon,
holder.distanceText,
location!!.latitude,
location!!.longitude,
item.latLon,
locationViewCache
)
} else {

View file

@ -136,27 +136,19 @@ class UiUtils(private val app: TelegramApplication) {
fun updateLocationView(
arrow: ImageView?,
text: TextView?,
lat: Double,
lon: Double,
cache: UpdateLocationViewCache
) {
updateLocationView(arrow, text, LatLon(lat, lon), cache)
}
fun updateLocationView(
arrow: ImageView?,
text: TextView?,
toLoc: LatLon,
toLoc: LatLon?,
cache: UpdateLocationViewCache
) {
val fromLoc = app.locationProvider.lastKnownLocationLatLon
val heading = app.locationProvider.heading
val mes = FloatArray(2)
val locPassive = fromLoc == null || cache.outdatedLocation
val locPassive = fromLoc == null || toLoc == null || cache.outdatedLocation
val colorId = if (locPassive) R.color.icon_light else R.color.ctrl_active_light
fromLoc?.also { l ->
Location.distanceBetween(toLoc.latitude, toLoc.longitude, l.latitude, l.longitude, mes)
if (fromLoc != null && toLoc != null) {
Location.distanceBetween(
fromLoc.latitude, fromLoc.longitude, toLoc.latitude, toLoc.longitude, mes
)
}
if (arrow != null) {
@ -169,7 +161,7 @@ class UiUtils(private val app: TelegramApplication) {
DirectionDrawable(app)
}
dd.setImage(R.drawable.ic_direction_arrow, colorId)
if (fromLoc == null || heading == null) {
if (fromLoc == null || toLoc == null || heading == null) {
dd.setAngle(0f)
} else {
dd.setAngle(mes[1] - heading + 180 + cache.screenOrientation)
@ -182,7 +174,7 @@ class UiUtils(private val app: TelegramApplication) {
if (text != null) {
text.setTextColor(ContextCompat.getColor(app, colorId))
val meters = if (fromLoc == null) 0f else mes[1]
val meters = if (fromLoc == null || toLoc == null) 0f else mes[1]
text.text = OsmandFormatter.getFormattedDistance(meters, app)
}
}