Fix #8015
This commit is contained in:
parent
6014085fb1
commit
967c5ad4c8
6 changed files with 54 additions and 20 deletions
|
@ -1,5 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<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="back_to_osmand">Back to OsmAnd</string>
|
||||||
<string name="shared_string_suggested">Suggested</string>
|
<string name="shared_string_suggested">Suggested</string>
|
||||||
<string name="status_widget_title">OsmAnd Tracker status</string>
|
<string name="status_widget_title">OsmAnd Tracker status</string>
|
||||||
|
|
|
@ -187,7 +187,10 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
bearing = content.bearing.toFloat()
|
bearing = content.bearing.toFloat()
|
||||||
}
|
}
|
||||||
val params = generatePointParams(photoPath, stale, speed, bearing)
|
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) {
|
if (update) {
|
||||||
osmandAidlHelper.updateMapPoint(MAP_LAYER_ID, pointId, name, name, typeName, Color.WHITE, aLatLon, details, params)
|
osmandAidlHelper.updateMapPoint(MAP_LAYER_ID, pointId, name, name, typeName, Color.WHITE, aLatLon, details, params)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -60,8 +60,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
private var heading: Float? = null
|
private var heading: Float? = null
|
||||||
private var locationUiUpdateAllowed: Boolean = true
|
private var locationUiUpdateAllowed: Boolean = true
|
||||||
|
|
||||||
private var lastTelegramUpdateStr = ""
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
@ -71,7 +69,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
|
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
|
||||||
|
|
||||||
lastTelegramUpdateTime = mainView.findViewById<TextView>(R.id.last_telegram_update_time)
|
lastTelegramUpdateTime = mainView.findViewById<TextView>(R.id.last_telegram_update_time)
|
||||||
lastTelegramUpdateStr = getString(R.string.last_update_from_telegram) + ": "
|
|
||||||
|
|
||||||
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
|
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
|
||||||
adapter = LiveNowListAdapter()
|
adapter = LiveNowListAdapter()
|
||||||
|
@ -302,7 +299,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
if (res.isEmpty()) {
|
if (res.isEmpty()) {
|
||||||
lastTelegramUpdateTime.visibility = View.VISIBLE
|
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 {
|
} else {
|
||||||
lastTelegramUpdateTime.visibility = View.GONE
|
lastTelegramUpdateTime.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
@ -398,8 +400,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
inner class LiveNowListAdapter : RecyclerView.Adapter<BaseViewHolder>() {
|
inner class LiveNowListAdapter : RecyclerView.Adapter<BaseViewHolder>() {
|
||||||
|
|
||||||
private var lastResponseStr = getString(R.string.last_response) + ": "
|
|
||||||
|
|
||||||
private val menuList =
|
private val menuList =
|
||||||
listOf(getString(R.string.shared_string_off), getString(R.string.shared_string_all))
|
listOf(getString(R.string.shared_string_off), getString(R.string.shared_string_all))
|
||||||
|
|
||||||
|
@ -478,7 +478,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
if (lastItem) {
|
if (lastItem) {
|
||||||
holder.lastTelegramUpdateTime?.visibility = View.VISIBLE
|
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 {
|
} else {
|
||||||
holder.lastTelegramUpdateTime?.visibility = View.GONE
|
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.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
|
||||||
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, R.string.last_response_date,
|
||||||
|
R.string.last_response_duration
|
||||||
|
)
|
||||||
holder.topShadowDivider?.visibility = View.GONE
|
holder.topShadowDivider?.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -517,15 +525,17 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
override fun getItemCount() = items.size
|
override fun getItemCount() = items.size
|
||||||
|
|
||||||
private fun getChatItemDescription(item: ChatItem): String {
|
private fun getChatItemDescription(item: ChatItem): String {
|
||||||
|
val dateRes = R.string.last_response_date
|
||||||
|
val durationRes = R.string.last_response_duration
|
||||||
return when {
|
return when {
|
||||||
item.chatWithBot -> {
|
item.chatWithBot -> {
|
||||||
if (settings.liveNowSortType.isSortByGroup()) {
|
if (settings.liveNowSortType.isSortByGroup()) {
|
||||||
getString(R.string.shared_string_bot)
|
getString(R.string.shared_string_bot)
|
||||||
} else {
|
} 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 -> {
|
else -> {
|
||||||
if (settings.liveNowSortType.isSortByGroup()) {
|
if (settings.liveNowSortType.isSortByGroup()) {
|
||||||
val live = getString(R.string.shared_string_live)
|
val live = getString(R.string.shared_string_live)
|
||||||
|
@ -533,7 +543,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
val liveStr = "$live ${item.liveMembersCount}"
|
val liveStr = "$live ${item.liveMembersCount}"
|
||||||
if (item.membersCount > 0) "$liveStr • $all ${item.membersCount}" else liveStr
|
if (item.membersCount > 0) "$liveStr • $all ${item.membersCount}" else liveStr
|
||||||
} else {
|
} else {
|
||||||
OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
|
OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, dateRes, durationRes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,7 +502,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
|
||||||
|
|
||||||
private fun getItemDescription(item: TdApi.Object, lastUpdateTime: Int?): String? {
|
private fun getItemDescription(item: TdApi.Object, lastUpdateTime: Int?): String? {
|
||||||
if (lastUpdateTime != null) {
|
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)) {
|
if (item is TdApi.Chat && telegramHelper.isGroup(item)) {
|
||||||
return getString(R.string.shared_string_group)
|
return getString(R.string.shared_string_group)
|
||||||
|
|
|
@ -349,7 +349,7 @@ class SetTimeDialogFragment : BaseDialogFragment(), TelegramLocationListener, Te
|
||||||
if (message != null && content is TdApi.MessageLocation && (location != null && content.location != null)) {
|
if (message != null && content is TdApi.MessageLocation && (location != null && content.location != null)) {
|
||||||
val lastUpdated = OsmandLocationUtils.getLastUpdatedTime(message)
|
val lastUpdated = OsmandLocationUtils.getLastUpdatedTime(message)
|
||||||
holder.description?.visibility = View.VISIBLE
|
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
|
holder.locationViewContainer?.visibility = if (lastUpdated > 0) View.VISIBLE else View.GONE
|
||||||
locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 -
|
locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 -
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.telegram.utils
|
package net.osmand.telegram.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import net.osmand.telegram.R
|
import net.osmand.telegram.R
|
||||||
import net.osmand.telegram.TelegramApplication
|
import net.osmand.telegram.TelegramApplication
|
||||||
import java.text.DateFormatSymbols
|
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) {
|
return if (lastUpdated > 0) {
|
||||||
val duration = System.currentTimeMillis() / 1000 - lastUpdated
|
val duration = System.currentTimeMillis() / 1000 - lastUpdated
|
||||||
when {
|
when {
|
||||||
duration > MIN_DURATION_FOR_DATE_FORMAT -> prefix + getFormattedDate(lastUpdated.toLong())
|
duration > MIN_DURATION_FOR_DATE_FORMAT -> ctx.getString(dateRes, getFormattedDate(lastUpdated.toLong()))
|
||||||
duration > 0 -> prefix + getFormattedDuration(ctx, duration) + " " + ctx.getString(R.string.time_ago)
|
duration > 0 -> ctx.getString(durationRes, getFormattedDuration(ctx, duration))
|
||||||
else -> ""
|
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 {
|
fun calculateRoundedDist(distInMeters: Double, ctx: TelegramApplication): Double {
|
||||||
|
|
Loading…
Reference in a new issue