add time in ui for live now messages

This commit is contained in:
Chumva 2018-08-15 17:00:58 +03:00
parent ff53e260d9
commit 4e102bb1e8
5 changed files with 24 additions and 5 deletions

View file

@ -90,7 +90,7 @@
android:text="•"
android:textColor="?attr/android:textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
android:visibility="invisible" />
android:visibility="visible" />
</LinearLayout>

View file

@ -88,7 +88,7 @@
android:text="•"
android:textColor="?attr/android:textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
android:visibility="invisible" />
android:visibility="visible" />
</LinearLayout>

View file

@ -483,7 +483,9 @@ class TelegramHelper private constructor() {
if (message.isAppropriate()) {
val oldContent = message.content
if (oldContent is TdApi.MessageText) {
message.content = parseOsmAndBotLocation(oldContent.text.text)
val messageOsmAndBotLocation = parseOsmAndBotLocation(oldContent.text.text)
messageOsmAndBotLocation.created = message.date
message.content = messageOsmAndBotLocation
} else if (oldContent is TdApi.MessageLocation &&
(isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) {
message.content = parseOsmAndBotLocation(message)
@ -758,6 +760,7 @@ class TelegramHelper private constructor() {
name = getOsmAndBotDeviceName(message)
lat = messageLocation.location.latitude
lon = messageLocation.location.longitude
created = message.date
val date = message.editDate
lastUpdated = if (date != 0) {
date
@ -773,6 +776,7 @@ class TelegramHelper private constructor() {
name = oldContent.name
lat = messageLocation.location.latitude
lon = messageLocation.location.longitude
created = oldContent.created
lastUpdated = (System.currentTimeMillis() / 1000).toInt()
}
}
@ -850,6 +854,8 @@ class TelegramHelper private constructor() {
internal set
var lastUpdated: Int = 0
internal set
var created: Int = 0
internal set
override fun getConstructor() = -1

View file

@ -55,6 +55,7 @@ object TelegramUiHelper {
val message = messages.firstOrNull()
if (message != null) {
res.lastUpdated = message.editDate
res.created = message.date
}
if (type is TdApi.ChatTypePrivate || type is TdApi.ChatTypeSecret) {
val userId = getUserIdFromChatType(type)
@ -124,6 +125,7 @@ object TelegramUiHelper {
latLon = LatLon(content.lat, content.lon)
placeholderId = R.drawable.img_user_picture
lastUpdated = content.lastUpdated
created = content.created
}
} else {
null
@ -146,6 +148,7 @@ object TelegramUiHelper {
placeholderId = R.drawable.img_user_picture
userId = message.senderUserId
lastUpdated = message.editDate
created = message.date
}
}
@ -165,6 +168,8 @@ object TelegramUiHelper {
internal set
var lastUpdated: Int = 0
internal set
var created: Int = 0
internal set
abstract fun canBeOpenedOnMap(): Boolean

View file

@ -25,6 +25,7 @@ import net.osmand.telegram.helpers.TelegramUiHelper.ListItem
import net.osmand.telegram.helpers.TelegramUiHelper.LocationItem
import net.osmand.telegram.ui.LiveNowTabFragment.LiveNowListAdapter.BaseViewHolder
import net.osmand.telegram.utils.AndroidUtils
import net.osmand.telegram.utils.OsmandFormatter
import net.osmand.telegram.utils.UiUtils.UpdateLocationViewCache
import net.osmand.util.MapUtils
import org.drinkless.td.libcore.telegram.TdApi
@ -341,7 +342,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.showOnMapState?.text = menuList[stateTextInd]
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
} else if (item is LocationItem && holder is ContactViewHolder) {
holder.description?.visibility = View.GONE
holder.description?.text = getListItemLiveTimeDescr(item)
}
}
@ -350,7 +351,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
private fun getChatItemDescription(item: ChatItem): String {
return when {
item.chatWithBot -> getString(R.string.shared_string_bot)
item.privateChat -> "" // FIXME
item.privateChat -> { getListItemLiveTimeDescr(item) }
else -> {
val live = getString(R.string.shared_string_live)
val all = getString(R.string.shared_string_all)
@ -360,6 +361,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
}
}
private fun getListItemLiveTimeDescr(item: ListItem):String {
return getString(R.string.shared_string_live) +
": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(item))}"
}
private fun getListItemLiveTime(item: ListItem): Long = (System.currentTimeMillis() / 1000) - item.created
private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) {
val ctx = holder.itemView.context