Merge branch 'master' of ssh://github.com/osmandapp/Osmand into LoginDialogsUiImprovements
This commit is contained in:
commit
057d53dee1
3 changed files with 23 additions and 39 deletions
|
@ -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
|
||||
|
|
|
@ -187,11 +187,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
}
|
||||
|
||||
private fun convertToLocationItems(messages: List<TdApi.Message>): List<LocationItem> {
|
||||
return mutableListOf<LocationItem>().apply {
|
||||
messages.forEach { message ->
|
||||
TelegramUiHelper.messageToLocationItem(telegramHelper, message)?.also { add(it) }
|
||||
}
|
||||
val res = mutableListOf<LocationItem>()
|
||||
messages.forEach { message ->
|
||||
TelegramUiHelper.messageToLocationItem(telegramHelper, message)?.also { res.add(it) }
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
inner class LiveNowListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
@ -207,7 +207,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (items[position]) {
|
||||
is TdApi.Chat -> CHAT_VIEW_TYPE
|
||||
is ChatItem -> CHAT_VIEW_TYPE
|
||||
else -> LOCATION_ITEM_VIEW_TYPE
|
||||
}
|
||||
}
|
||||
|
@ -234,14 +234,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, item.placeholderId)
|
||||
holder.title?.text = chatTitle
|
||||
if (location != null) {
|
||||
if (location != null && item.latLon != null) {
|
||||
holder.locationViewContainer?.visibility = View.VISIBLE
|
||||
// TODO: locationViewCache.outdatedLocation
|
||||
app.uiUtils.updateLocationView(
|
||||
holder.directionIcon,
|
||||
holder.distanceText,
|
||||
location!!.latitude,
|
||||
location!!.longitude,
|
||||
item.latLon,
|
||||
locationViewCache
|
||||
)
|
||||
} else {
|
||||
|
@ -256,14 +255,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
} else if (item is LocationItem && holder is ContactViewHolder) {
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, item.placeholderId)
|
||||
holder.title?.text = item.name
|
||||
if (location != null) {
|
||||
if (location != null && item.latLon != null) {
|
||||
holder.locationViewContainer?.visibility = View.VISIBLE
|
||||
// TODO: locationViewCache.outdatedLocation
|
||||
app.uiUtils.updateLocationView(
|
||||
holder.directionIcon,
|
||||
holder.distanceText,
|
||||
location!!.latitude,
|
||||
location!!.longitude,
|
||||
item.latLon,
|
||||
locationViewCache
|
||||
)
|
||||
} else {
|
||||
|
|
|
@ -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(
|
||||
toLoc.latitude, toLoc.longitude, fromLoc.latitude, fromLoc.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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue