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.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import net.osmand.data.LatLon
|
||||||
import net.osmand.telegram.R
|
import net.osmand.telegram.R
|
||||||
import net.osmand.telegram.TelegramApplication
|
import net.osmand.telegram.TelegramApplication
|
||||||
import net.osmand.telegram.helpers.TelegramHelper.MessageOsmAndBotLocation
|
import net.osmand.telegram.helpers.TelegramHelper.MessageOsmAndBotLocation
|
||||||
|
@ -48,8 +49,7 @@ object TelegramUiHelper {
|
||||||
if (chatType is TdApi.ChatTypePrivate && !helper.isBot(chatType.userId)) {
|
if (chatType is TdApi.ChatTypePrivate && !helper.isBot(chatType.userId)) {
|
||||||
val content = messages.firstOrNull()?.content
|
val content = messages.firstOrNull()?.content
|
||||||
if (content is TdApi.MessageLocation) {
|
if (content is TdApi.MessageLocation) {
|
||||||
res.lat = content.location.latitude
|
res.latLon = LatLon(content.location.latitude, content.location.longitude)
|
||||||
res.lon = content.location.longitude
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
@ -68,8 +68,7 @@ object TelegramUiHelper {
|
||||||
return if (content.isValid()) {
|
return if (content.isValid()) {
|
||||||
LocationItem().apply {
|
LocationItem().apply {
|
||||||
name = content.name
|
name = content.name
|
||||||
lat = content.lat
|
latLon = LatLon(content.lat, content.lon)
|
||||||
lon = content.lon
|
|
||||||
placeholderId = R.drawable.ic_group
|
placeholderId = R.drawable.ic_group
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,8 +90,7 @@ object TelegramUiHelper {
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
name = user.phoneNumber
|
name = user.phoneNumber
|
||||||
}
|
}
|
||||||
lat = content.location.latitude
|
latLon = LatLon(content.location.latitude, content.location.longitude)
|
||||||
lon = content.location.longitude
|
|
||||||
photoPath = helper.getUserPhotoPath(user)
|
photoPath = helper.getUserPhotoPath(user)
|
||||||
placeholderId = R.drawable.ic_group
|
placeholderId = R.drawable.ic_group
|
||||||
}
|
}
|
||||||
|
@ -101,9 +99,7 @@ object TelegramUiHelper {
|
||||||
class ChatItem {
|
class ChatItem {
|
||||||
var title: String = ""
|
var title: String = ""
|
||||||
internal set
|
internal set
|
||||||
var lat: Double = 0.0
|
var latLon: LatLon? = null
|
||||||
internal set
|
|
||||||
var lon: Double = 0.0
|
|
||||||
internal set
|
internal set
|
||||||
var photoPath: String? = null
|
var photoPath: String? = null
|
||||||
internal set
|
internal set
|
||||||
|
@ -114,9 +110,7 @@ object TelegramUiHelper {
|
||||||
class LocationItem {
|
class LocationItem {
|
||||||
var name: String = ""
|
var name: String = ""
|
||||||
internal set
|
internal set
|
||||||
var lat: Double = 0.0
|
var latLon: LatLon? = null
|
||||||
internal set
|
|
||||||
var lon: Double = 0.0
|
|
||||||
internal set
|
internal set
|
||||||
var photoPath: String? = null
|
var photoPath: String? = null
|
||||||
internal set
|
internal set
|
||||||
|
|
|
@ -187,11 +187,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertToLocationItems(messages: List<TdApi.Message>): List<LocationItem> {
|
private fun convertToLocationItems(messages: List<TdApi.Message>): List<LocationItem> {
|
||||||
return mutableListOf<LocationItem>().apply {
|
val res = mutableListOf<LocationItem>()
|
||||||
messages.forEach { message ->
|
messages.forEach { message ->
|
||||||
TelegramUiHelper.messageToLocationItem(telegramHelper, message)?.also { add(it) }
|
TelegramUiHelper.messageToLocationItem(telegramHelper, message)?.also { res.add(it) }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class LiveNowListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
inner class LiveNowListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
|
@ -207,7 +207,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return when (items[position]) {
|
return when (items[position]) {
|
||||||
is TdApi.Chat -> CHAT_VIEW_TYPE
|
is ChatItem -> CHAT_VIEW_TYPE
|
||||||
else -> LOCATION_ITEM_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)
|
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, item.placeholderId)
|
||||||
holder.title?.text = chatTitle
|
holder.title?.text = chatTitle
|
||||||
if (location != null) {
|
if (location != null && item.latLon != null) {
|
||||||
holder.locationViewContainer?.visibility = View.VISIBLE
|
holder.locationViewContainer?.visibility = View.VISIBLE
|
||||||
// TODO: locationViewCache.outdatedLocation
|
// TODO: locationViewCache.outdatedLocation
|
||||||
app.uiUtils.updateLocationView(
|
app.uiUtils.updateLocationView(
|
||||||
holder.directionIcon,
|
holder.directionIcon,
|
||||||
holder.distanceText,
|
holder.distanceText,
|
||||||
location!!.latitude,
|
item.latLon,
|
||||||
location!!.longitude,
|
|
||||||
locationViewCache
|
locationViewCache
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -256,14 +255,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
} else if (item is LocationItem && holder is ContactViewHolder) {
|
} else if (item is LocationItem && holder is ContactViewHolder) {
|
||||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, item.placeholderId)
|
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, item.placeholderId)
|
||||||
holder.title?.text = item.name
|
holder.title?.text = item.name
|
||||||
if (location != null) {
|
if (location != null && item.latLon != null) {
|
||||||
holder.locationViewContainer?.visibility = View.VISIBLE
|
holder.locationViewContainer?.visibility = View.VISIBLE
|
||||||
// TODO: locationViewCache.outdatedLocation
|
// TODO: locationViewCache.outdatedLocation
|
||||||
app.uiUtils.updateLocationView(
|
app.uiUtils.updateLocationView(
|
||||||
holder.directionIcon,
|
holder.directionIcon,
|
||||||
holder.distanceText,
|
holder.distanceText,
|
||||||
location!!.latitude,
|
item.latLon,
|
||||||
location!!.longitude,
|
|
||||||
locationViewCache
|
locationViewCache
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -136,27 +136,19 @@ class UiUtils(private val app: TelegramApplication) {
|
||||||
fun updateLocationView(
|
fun updateLocationView(
|
||||||
arrow: ImageView?,
|
arrow: ImageView?,
|
||||||
text: TextView?,
|
text: TextView?,
|
||||||
lat: Double,
|
toLoc: LatLon?,
|
||||||
lon: Double,
|
|
||||||
cache: UpdateLocationViewCache
|
|
||||||
) {
|
|
||||||
updateLocationView(arrow, text, LatLon(lat, lon), cache)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateLocationView(
|
|
||||||
arrow: ImageView?,
|
|
||||||
text: TextView?,
|
|
||||||
toLoc: LatLon,
|
|
||||||
cache: UpdateLocationViewCache
|
cache: UpdateLocationViewCache
|
||||||
) {
|
) {
|
||||||
val fromLoc = app.locationProvider.lastKnownLocationLatLon
|
val fromLoc = app.locationProvider.lastKnownLocationLatLon
|
||||||
val heading = app.locationProvider.heading
|
val heading = app.locationProvider.heading
|
||||||
val mes = FloatArray(2)
|
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
|
val colorId = if (locPassive) R.color.icon_light else R.color.ctrl_active_light
|
||||||
|
|
||||||
fromLoc?.also { l ->
|
if (fromLoc != null && toLoc != null) {
|
||||||
Location.distanceBetween(toLoc.latitude, toLoc.longitude, l.latitude, l.longitude, mes)
|
Location.distanceBetween(
|
||||||
|
toLoc.latitude, toLoc.longitude, fromLoc.latitude, fromLoc.longitude, mes
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arrow != null) {
|
if (arrow != null) {
|
||||||
|
@ -169,7 +161,7 @@ class UiUtils(private val app: TelegramApplication) {
|
||||||
DirectionDrawable(app)
|
DirectionDrawable(app)
|
||||||
}
|
}
|
||||||
dd.setImage(R.drawable.ic_direction_arrow, colorId)
|
dd.setImage(R.drawable.ic_direction_arrow, colorId)
|
||||||
if (fromLoc == null || heading == null) {
|
if (fromLoc == null || toLoc == null || heading == null) {
|
||||||
dd.setAngle(0f)
|
dd.setAngle(0f)
|
||||||
} else {
|
} else {
|
||||||
dd.setAngle(mes[1] - heading + 180 + cache.screenOrientation)
|
dd.setAngle(mes[1] - heading + 180 + cache.screenOrientation)
|
||||||
|
@ -182,7 +174,7 @@ class UiUtils(private val app: TelegramApplication) {
|
||||||
|
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
text.setTextColor(ContextCompat.getColor(app, colorId))
|
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)
|
text.text = OsmandFormatter.getFormattedDistance(meters, app)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue