move getListItemLiveTimeDescr to OsmandFormatter
This commit is contained in:
parent
f14b96fb88
commit
54c446f278
3 changed files with 26 additions and 33 deletions
|
@ -343,7 +343,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?.text = getListItemLiveTimeDescr(item)
|
||||
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
private fun getChatItemDescription(item: ChatItem): String {
|
||||
return when {
|
||||
item.chatWithBot -> getString(R.string.shared_string_bot)
|
||||
item.privateChat -> { getListItemLiveTimeDescr(item) }
|
||||
item.privateChat -> { OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, true) }
|
||||
else -> {
|
||||
val live = getString(R.string.shared_string_live)
|
||||
val all = getString(R.string.shared_string_all)
|
||||
|
@ -362,22 +362,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
}
|
||||
}
|
||||
|
||||
private fun getListItemLiveTimeDescr(item: ListItem): String {
|
||||
var description = ""
|
||||
if (item.lastUpdated > 0) {
|
||||
val duration = System.currentTimeMillis() / 1000 - item.lastUpdated
|
||||
description = if (duration > OsmandFormatter.MIN_DURATION_FOR_DATE_FORMAT) {
|
||||
val formattedTime = OsmandFormatter.getFormattedDate(item.lastUpdated.toLong())
|
||||
getString(R.string.last_response) + ": $formattedTime"
|
||||
} else {
|
||||
val formattedTime = OsmandFormatter.getFormattedDuration(app, duration)
|
||||
getString(R.string.last_response) + ": $formattedTime " +
|
||||
getString(R.string.time_ago)
|
||||
}
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) {
|
||||
val ctx = holder.itemView.context
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr
|
|||
if (message != null && content is TdApi.MessageLocation && (location != null && content.location != null)) {
|
||||
val lastUpdated = telegramHelper.getLastUpdatedTime(message)
|
||||
holder.description?.visibility = View.VISIBLE
|
||||
holder.description?.text = getListItemLiveTimeDescr(lastUpdated)
|
||||
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, lastUpdated)
|
||||
|
||||
holder.locationViewContainer?.visibility = if (lastUpdated > 0) View.VISIBLE else View.INVISIBLE
|
||||
locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 -
|
||||
|
@ -324,20 +324,6 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr
|
|||
|
||||
override fun getItemCount() = chats.size
|
||||
|
||||
private fun getListItemLiveTimeDescr(lastUpdated: Int): String {
|
||||
var description = ""
|
||||
if (lastUpdated > 0) {
|
||||
val duration = System.currentTimeMillis() / 1000 - lastUpdated
|
||||
description = if (duration > OsmandFormatter.MIN_DURATION_FOR_DATE_FORMAT) {
|
||||
OsmandFormatter.getFormattedDate(duration)
|
||||
} else {
|
||||
val formattedTime = OsmandFormatter.getFormattedDuration(app, duration)
|
||||
"$formattedTime " + getString(R.string.time_ago)
|
||||
}
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
inner class ChatViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
val icon: ImageView? = view.findViewById(R.id.icon)
|
||||
val title: TextView? = view.findViewById(R.id.title)
|
||||
|
|
|
@ -76,6 +76,29 @@ object OsmandFormatter {
|
|||
fun getFormattedDate(seconds: Long): String =
|
||||
SimpleDateFormat(SIMPLE_DATE_FORMAT, Locale.getDefault()).format(seconds * 1000L)
|
||||
|
||||
fun getListItemLiveTimeDescr(ctx: TelegramApplication, lastUpdated: Int, lastResponse: Boolean = false): String {
|
||||
var description = ""
|
||||
if (lastUpdated > 0) {
|
||||
val duration = System.currentTimeMillis() / 1000 - lastUpdated
|
||||
description = if (duration > MIN_DURATION_FOR_DATE_FORMAT) {
|
||||
val formattedTime = getFormattedDate(lastUpdated.toLong())
|
||||
if (lastResponse) {
|
||||
ctx.getString(R.string.last_response) + ": $formattedTime"
|
||||
} else {
|
||||
formattedTime
|
||||
}
|
||||
} else {
|
||||
val formattedTime = getFormattedDuration(ctx, duration)
|
||||
if (lastResponse) {
|
||||
ctx.getString(R.string.last_response) + ": $formattedTime " +
|
||||
ctx.getString(R.string.time_ago)
|
||||
} else {
|
||||
"$formattedTime " + ctx.getString(R.string.time_ago)
|
||||
}
|
||||
}
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
fun calculateRoundedDist(distInMeters: Double, ctx: TelegramApplication): Double {
|
||||
val mc = ctx.settings.metricsConstants
|
||||
|
|
Loading…
Reference in a new issue