Display last time we receive a transmission from a node #65

1.2-legacy
Ludovic Goix 2020-07-13 23:49:07 -04:00
rodzic 2d706f5a4c
commit 8f253bdca1
3 zmienionych plików z 34 dodań i 3 usunięć

Wyświetl plik

@ -57,7 +57,7 @@ data class Position(
fun bearing(o: Position) = bearing(latitude, longitude, o.latitude, o.longitude)
override fun toString(): String {
return "Position(lat=${latitude.anonymize}, lon=${longitude.anonymize}, alt=${altitude.anonymize}, time=${time})"
return "Position(lat=${latitude.anonymize}, lon=${longitude.anonymize}, alt=${altitude.anonymize}, time=${time}, batteryPctLevel=${batteryPctLevel})"
}
}

Wyświetl plik

@ -2,6 +2,7 @@ package com.geeksville.mesh.ui
import android.os.Bundle
import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -15,6 +16,8 @@ import com.geeksville.mesh.R
import com.geeksville.mesh.model.UIViewModel
import kotlinx.android.synthetic.main.adapter_node_layout.view.*
import kotlinx.android.synthetic.main.nodelist_fragment.*
import java.text.ParseException
import java.util.*
class UsersFragment : ScreenFragment("Users"), Logging {
@ -27,6 +30,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
val nodeNameView = itemView.nodeNameView
val distance_view = itemView.distance_view
val batteryPctView = itemView.batteryPercentageView
val lastTime = itemView.lastConnectionView
}
private val nodesAdapter = object : RecyclerView.Adapter<ViewHolder>() {
@ -117,6 +121,8 @@ class UsersFragment : ScreenFragment("Users"), Logging {
{
holder.batteryPctView.text = "?"
}
holder.lastTime.text = getLastTimeValue(n)
}
private var nodes = arrayOf<NodeInfo>()
@ -128,6 +134,31 @@ class UsersFragment : ScreenFragment("Users"), Logging {
}
}
private fun getLastTimeValue(n: NodeInfo): String {
var lastTimeText: String = "?"
val currentTime = (System.currentTimeMillis()/1000).toInt()
val threeDaysLong = 3 * 60*60*24
//if the lastSeen is too old
if((n.lastSeen<currentTime-threeDaysLong))
return lastTimeText
try {
val toLong: Long = n.lastSeen.toLong()
val long1000 = toLong * 1000L
val date = Date(long1000)
val timeFormat = DateFormat.getTimeFormat(context)
lastTimeText = timeFormat.format(date)
} catch (e: ParseException) {
//
}
return lastTimeText
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?

Wyświetl plik

@ -77,7 +77,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:visibility="invisible"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/lastConnectionView"
app:srcCompat="@drawable/ic_antenna_24" />
@ -88,7 +88,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="06/14 15h01 (13 min ago)"
android:visibility="invisible"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/lastCommIcon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/lastCommIcon" />