This commit is contained in:
Vitaliy 2020-01-23 17:00:05 +02:00
parent 6014085fb1
commit 967c5ad4c8
6 changed files with 54 additions and 20 deletions

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="last_update_from_telegram_date">Last update from Telegram: %1$s</string>
<string name="last_response_date">Last response: %1$s</string>
<string name="last_update_from_telegram_duration">Last update from Telegram: %1$s ago</string>
<string name="last_response_duration">Last response: %1$s ago</string>
<string name="duration_ago">%1$s ago</string>
<string name="back_to_osmand">Back to OsmAnd</string>
<string name="shared_string_suggested">Suggested</string>
<string name="status_widget_title">OsmAnd Tracker status</string>

View file

@ -187,7 +187,10 @@ class ShowLocationHelper(private val app: TelegramApplication) {
bearing = content.bearing.toFloat()
}
val params = generatePointParams(photoPath, stale, speed, bearing)
val typeName = if (isGroup) chatTitle else OsmandFormatter.getListItemLiveTimeDescr(app, date, app.getString(R.string.last_response) + ": ")
val typeName = if (isGroup) chatTitle else OsmandFormatter.getListItemLiveTimeDescr(
app, date, R.string.last_response_date,
R.string.last_response_duration
)
if (update) {
osmandAidlHelper.updateMapPoint(MAP_LAYER_ID, pointId, name, name, typeName, Color.WHITE, aLatLon, details, params)
} else {

View file

@ -60,8 +60,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
private var heading: Float? = null
private var locationUiUpdateAllowed: Boolean = true
private var lastTelegramUpdateStr = ""
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -71,7 +69,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
lastTelegramUpdateTime = mainView.findViewById<TextView>(R.id.last_telegram_update_time)
lastTelegramUpdateStr = getString(R.string.last_update_from_telegram) + ": "
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
adapter = LiveNowListAdapter()
@ -302,7 +299,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
if (res.isEmpty()) {
lastTelegramUpdateTime.visibility = View.VISIBLE
lastTelegramUpdateTime.text = OsmandFormatter.getListItemLiveTimeDescr(app, telegramHelper.lastTelegramUpdateTime, lastTelegramUpdateStr)
lastTelegramUpdateTime.text = OsmandFormatter.getListItemLiveTimeDescr(
app,
telegramHelper.lastTelegramUpdateTime,
R.string.last_update_from_telegram_date,
R.string.last_update_from_telegram_duration
)
} else {
lastTelegramUpdateTime.visibility = View.GONE
}
@ -398,8 +400,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
inner class LiveNowListAdapter : RecyclerView.Adapter<BaseViewHolder>() {
private var lastResponseStr = getString(R.string.last_response) + ": "
private val menuList =
listOf(getString(R.string.shared_string_off), getString(R.string.shared_string_all))
@ -478,7 +478,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
if (lastItem) {
holder.lastTelegramUpdateTime?.visibility = View.VISIBLE
holder.lastTelegramUpdateTime?.text = OsmandFormatter.getListItemLiveTimeDescr(app, telegramHelper.lastTelegramUpdateTime, lastTelegramUpdateStr)
holder.lastTelegramUpdateTime?.text = OsmandFormatter.getListItemLiveTimeDescr(
app,
telegramHelper.lastTelegramUpdateTime,
R.string.last_update_from_telegram_date,
R.string.last_update_from_telegram_duration
)
} else {
holder.lastTelegramUpdateTime?.visibility = View.GONE
}
@ -509,7 +514,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
holder.topDivider?.visibility = if (!sortByGroup && position != 0) View.GONE else View.VISIBLE
} 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, R.string.last_response_date,
R.string.last_response_duration
)
holder.topShadowDivider?.visibility = View.GONE
}
}
@ -517,15 +525,17 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
override fun getItemCount() = items.size
private fun getChatItemDescription(item: ChatItem): String {
val dateRes = R.string.last_response_date
val durationRes = R.string.last_response_duration
return when {
item.chatWithBot -> {
if (settings.liveNowSortType.isSortByGroup()) {
getString(R.string.shared_string_bot)
} else {
OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, dateRes, durationRes)
}
}
item.privateChat -> OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
item.privateChat -> OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, dateRes, durationRes)
else -> {
if (settings.liveNowSortType.isSortByGroup()) {
val live = getString(R.string.shared_string_live)
@ -533,7 +543,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
val liveStr = "$live ${item.liveMembersCount}"
if (item.membersCount > 0) "$liveStr$all ${item.membersCount}" else liveStr
} else {
OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, dateRes, durationRes)
}
}
}

View file

@ -502,7 +502,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
private fun getItemDescription(item: TdApi.Object, lastUpdateTime: Int?): String? {
if (lastUpdateTime != null) {
return OsmandFormatter.getListItemLiveTimeDescr(app, lastUpdateTime)
return OsmandFormatter.getListItemShortLiveTimeDescr(app, lastUpdateTime, R.string.duration_ago)
}
if (item is TdApi.Chat && telegramHelper.isGroup(item)) {
return getString(R.string.shared_string_group)

View file

@ -349,7 +349,7 @@ class SetTimeDialogFragment : BaseDialogFragment(), TelegramLocationListener, Te
if (message != null && content is TdApi.MessageLocation && (location != null && content.location != null)) {
val lastUpdated = OsmandLocationUtils.getLastUpdatedTime(message)
holder.description?.visibility = View.VISIBLE
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, lastUpdated)
holder.description?.text = OsmandFormatter.getListItemShortLiveTimeDescr(app, lastUpdated,R.string.duration_ago)
holder.locationViewContainer?.visibility = if (lastUpdated > 0) View.VISIBLE else View.GONE
locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 -

View file

@ -1,6 +1,7 @@
package net.osmand.telegram.utils
import android.content.Context
import androidx.annotation.StringRes
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
import java.text.DateFormatSymbols
@ -106,17 +107,32 @@ object OsmandFormatter {
}
}
fun getListItemLiveTimeDescr(ctx: TelegramApplication, lastUpdated: Int, prefix: String = ""): String {
fun getListItemLiveTimeDescr(
ctx: TelegramApplication,
lastUpdated: Int, @StringRes dateRes: Int, @StringRes durationRes: Int
): String {
return if (lastUpdated > 0) {
val duration = System.currentTimeMillis() / 1000 - lastUpdated
when {
duration > MIN_DURATION_FOR_DATE_FORMAT -> prefix + getFormattedDate(lastUpdated.toLong())
duration > 0 -> prefix + getFormattedDuration(ctx, duration) + " " + ctx.getString(R.string.time_ago)
duration > MIN_DURATION_FOR_DATE_FORMAT -> ctx.getString(dateRes, getFormattedDate(lastUpdated.toLong()))
duration > 0 -> ctx.getString(durationRes, getFormattedDuration(ctx, duration))
else -> ""
}
} else {
""
} else ""
}
fun getListItemShortLiveTimeDescr(
ctx: TelegramApplication,
lastUpdated: Int, @StringRes durationRes: Int
): String {
return if (lastUpdated > 0) {
val duration = System.currentTimeMillis() / 1000 - lastUpdated
when {
duration > MIN_DURATION_FOR_DATE_FORMAT -> getFormattedDate(lastUpdated.toLong())
duration > 0 -> ctx.getString(durationRes, getFormattedDuration(ctx, duration))
else -> ""
}
} else ""
}
fun calculateRoundedDist(distInMeters: Double, ctx: TelegramApplication): Double {