Fix points size on live now screen

This commit is contained in:
Chumva 2019-02-12 11:27:50 +02:00
parent ea8524d08e
commit cbec3f0153
2 changed files with 15 additions and 65 deletions

View file

@ -123,7 +123,7 @@ object TelegramUiHelper {
): ChatItem? { ): ChatItem? {
val content = OsmandLocationUtils.parseMessageContent(message, helper) val content = OsmandLocationUtils.parseMessageContent(message, helper)
return when (content) { return when (content) {
is MessageOsmAndBotLocation -> botMessageToChatItem(helper, chat, content) is MessageOsmAndBotLocation -> botMessageToChatItem(helper, chat, content, message)
is TdApi.MessageLocation -> locationMessageToChatItem(helper, chat, message) is TdApi.MessageLocation -> locationMessageToChatItem(helper, chat, message)
is MessageUserLocation -> locationMessageToChatItem(helper, chat, message) is MessageUserLocation -> locationMessageToChatItem(helper, chat, message)
else -> null else -> null
@ -175,10 +175,11 @@ object TelegramUiHelper {
private fun botMessageToChatItem( private fun botMessageToChatItem(
helper: TelegramHelper, helper: TelegramHelper,
chat: TdApi.Chat, chat: TdApi.Chat,
content: MessageOsmAndBotLocation content: MessageOsmAndBotLocation,
): ChatItem? { message: TdApi.Message): ChatItem? {
return if (content.isValid()) { return if (content.isValid()) {
ChatItem().apply { ChatItem().apply {
userId = OsmandLocationUtils.getSenderMessageId(message)
chatId = chat.id chatId = chat.id
chatTitle = chat.title chatTitle = chat.title
name = content.deviceName name = content.deviceName

View file

@ -483,12 +483,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.lastTelegramUpdateTime?.visibility = View.GONE holder.lastTelegramUpdateTime?.visibility = View.GONE
} }
if (settings.showGpsPoints) { val points = getChatItemGpxPointsSize(item)
holder.receivedGpxPointsContainer?.visibility = View.VISIBLE holder.receivedGpxPointsContainer?.visibility = if (settings.showGpsPoints && points > 0) View.VISIBLE else View.GONE
holder.receivedGpxPointsDescr?.text = getChatItemGpxPointsDescription(item) holder.receivedGpxPointsDescr?.text = getString(R.string.received_gps_points, points)
} else {
holder.receivedGpxPointsContainer?.visibility = View.GONE
}
if (item is ChatItem && holder is ChatViewHolder) { if (item is ChatItem && holder is ChatViewHolder) {
val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !sortByGroup) val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !sortByGroup)
@ -505,13 +502,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.groupDescrContainer?.visibility = View.GONE holder.groupDescrContainer?.visibility = View.GONE
} }
if (settings.showGpsPoints) {
holder.receivedGpxPointsContainer?.visibility = View.VISIBLE
holder.receivedGpxPointsDescr?.text = getChatItemGpxPointsDescription(item)
} else {
holder.receivedGpxPointsContainer?.visibility = View.GONE
}
holder.description?.text = getChatItemDescription(item) holder.description?.text = getChatItemDescription(item)
holder.imageButton?.visibility = View.GONE holder.imageButton?.visibility = View.GONE
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) } holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) }
@ -520,12 +510,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.topDivider?.visibility = if (!sortByGroup && position != 0) View.GONE else View.VISIBLE holder.topDivider?.visibility = if (!sortByGroup && position != 0) View.GONE else View.VISIBLE
} else if (item is LocationItem && holder is ContactViewHolder) { } else if (item is LocationItem && holder is ContactViewHolder) {
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr) holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
if (settings.showGpsPoints) {
holder.receivedGpxPointsContainer?.visibility = View.VISIBLE
holder.receivedGpxPointsDescr?.text = getChatItemGpxPointsDescription(item)
} else {
holder.receivedGpxPointsContainer?.visibility = View.GONE
}
} }
} }
@ -554,49 +538,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
} }
} }
private fun getChatItemGpxPointsDescription(item: ListItem): String { private fun getChatItemGpxPointsSize(item: ListItem): Int {
return when { val deviceName = if (item is ChatItem && item.chatWithBot) item.name else ""
item is ChatItem && item.chatWithBot -> { val start = System.currentTimeMillis() - settings.locHistoryTime * 1000
if (settings.liveNowSortType.isSortByGroup()) { val end = System.currentTimeMillis()
getString(R.string.shared_string_bot) val userLocations = app.locationMessages.getIngoingUserLocationsInChat(item.userId, item.chatId, deviceName, start, end)
} else { var points = 0
val deviceName = if(item.chatWithBot) item.name else "" userLocations?.getUniqueSegments()?.forEach { points += it.points.size }
val start = System.currentTimeMillis() - settings.locHistoryTime * 1000 return points
val end = System.currentTimeMillis()
val userLocations = app.locationMessages.getIngoingUserLocationsInChat(item.userId, item.chatId,deviceName,start, end)
var points = 0
userLocations?.getUniqueSegments()?.forEach { points += it.points.size }
getString(R.string.received_gps_points, points)
}
}
item is ChatItem && item.privateChat -> {
val deviceName = if(item.chatWithBot) item.name else ""
val start = System.currentTimeMillis() - settings.locHistoryTime * 1000
val end = System.currentTimeMillis()
val userLocations = app.locationMessages.getIngoingUserLocationsInChat(item.userId, item.chatId,deviceName,start, end)
var points = 0
userLocations?.getUniqueSegments()?.forEach { points += it.points.size }
getString(R.string.received_gps_points, points)
}
else -> {
if (!settings.liveNowSortType.isSortByGroup()&&item is ChatItem) {
val deviceName = if(item.chatWithBot) item.name else ""
val start = System.currentTimeMillis() - settings.locHistoryTime * 1000
val end = System.currentTimeMillis()
val userLocations = app.locationMessages.getIngoingUserLocationsInChat(item.userId, item.chatId,deviceName,start, end)
var points = 0
userLocations?.getUniqueSegments()?.forEach { points += it.points.size }
getString(R.string.received_gps_points, points)
} else {
val start = System.currentTimeMillis() - settings.locHistoryTime * 1000
val end = System.currentTimeMillis()
val userLocations = app.locationMessages.getIngoingUserLocationsInChat(item.userId, item.chatId,"",start, end)
var points = 0
userLocations?.getUniqueSegments()?.forEach { points += it.points.size }
getString(R.string.received_gps_points, points)
}
}
}
} }
private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) { private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) {