Merge pull request #5885 from osmandapp/UiImprovements

Ui time improvements
This commit is contained in:
Alexander Sytnyk 2018-08-17 15:40:21 +03:00 committed by GitHub
commit ae20adac9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 30 deletions

View file

@ -29,8 +29,6 @@ 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
import java.text.SimpleDateFormat
import java.util.*
private const val CHAT_VIEW_TYPE = 0
private const val LOCATION_ITEM_VIEW_TYPE = 1
@ -276,6 +274,8 @@ 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))
@ -326,7 +326,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
openOnMapView?.setOnClickListener(null)
}
if (location != null && item.latLon != null) {
holder.locationViewContainer?.visibility = View.VISIBLE
holder.locationViewContainer?.visibility = if (item.lastUpdated > 0) View.VISIBLE else View.GONE
locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 - item.lastUpdated > settings.staleLocTime
app.uiUtils.updateLocationView(
holder.directionIcon,
@ -350,7 +350,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, lastResponseStr)
}
}
@ -359,7 +359,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, lastResponseStr) }
else -> {
val live = getString(R.string.shared_string_live)
val all = getString(R.string.shared_string_all)
@ -369,19 +369,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
}
}
private fun getListItemLiveTimeDescr(item: ListItem): String {
val duration = System.currentTimeMillis() / 1000 - item.lastUpdated
var formattedTime = OsmandFormatter.getFormattedDuration(app, duration)
return if (duration > 48 * 60 * 60) {
// TODO make constant
val day = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())
formattedTime = day.format(Date(item.lastUpdated * 1000.toLong()))
getString(R.string.last_response) + ": $formattedTime"
} else {
getString(R.string.last_response) + ": $formattedTime " + getString(R.string.time_ago)
}
}
private fun showPopupMenu(holder: ChatViewHolder, chatId: Long) {
val ctx = holder.itemView.context

View file

@ -294,9 +294,9 @@ 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 = View.VISIBLE
holder.locationViewContainer?.visibility = if (lastUpdated > 0) View.VISIBLE else View.GONE
locationViewCache.outdatedLocation = System.currentTimeMillis() / 1000 -
lastUpdated > settings.staleLocTime
@ -324,16 +324,6 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr
override fun getItemCount() = chats.size
private fun getListItemLiveTimeDescr(lastUpdated: Int): String {
val duration = System.currentTimeMillis() / 1000 - lastUpdated
var formattedTime = OsmandFormatter.getFormattedDuration(app, duration)
if (duration > 48 * 60 * 60) {
// TODO make constant
formattedTime = Date(lastUpdated * 1000.toLong()).toString();
}
return "$formattedTime " + getString(R.string.time_ago)
}
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)

View file

@ -22,6 +22,9 @@ object OsmandFormatter {
private const val SHORT_TIME_FORMAT = "%02d:%02d"
private const val SIMPLE_TIME_OF_DAY_FORMAT = "HH:mm"
private const val SIMPLE_DATE_FORMAT = "dd MMM HH:mm:ss"
private const val MIN_DURATION_FOR_DATE_FORMAT = 48 * 60 * 60
private val dateFormatSymbols = DateFormatSymbols.getInstance()
private val localDaysStr = getLettersStringArray(dateFormatSymbols.shortWeekdays, 2)
@ -70,6 +73,23 @@ object OsmandFormatter {
}
}
fun getFormattedDate(seconds: Long): String =
SimpleDateFormat(SIMPLE_DATE_FORMAT, Locale.getDefault()).format(seconds * 1000L)
fun getListItemLiveTimeDescr(ctx: TelegramApplication, lastUpdated: Int, prefix: String = ""): String {
return if (lastUpdated > 0) {
val duration = System.currentTimeMillis() / 1000 - lastUpdated
if (duration > MIN_DURATION_FOR_DATE_FORMAT) {
prefix + getFormattedDate(lastUpdated.toLong())
} else {
prefix + getFormattedDuration(ctx, duration) + " " +
ctx.getString(R.string.time_ago)
}
} else {
""
}
}
fun calculateRoundedDist(distInMeters: Double, ctx: TelegramApplication): Double {
val mc = ctx.settings.metricsConstants
var mainUnitInMeter = 1.0