kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
display timeAgo properly and show coords in users screen
rodzic
b4d562d15f
commit
c8107441de
|
@ -17,6 +17,7 @@ import com.geeksville.mesh.R
|
|||
import com.geeksville.mesh.databinding.AdapterNodeLayoutBinding
|
||||
import com.geeksville.mesh.databinding.NodelistFragmentBinding
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.util.formatAgo
|
||||
import java.text.ParseException
|
||||
import java.util.*
|
||||
|
||||
|
@ -24,6 +25,7 @@ import java.util.*
|
|||
class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
|
||||
private var _binding: NodelistFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
|
@ -34,6 +36,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
class ViewHolder(itemView: AdapterNodeLayoutBinding) : RecyclerView.ViewHolder(itemView.root) {
|
||||
val nodeNameView = itemView.nodeNameView
|
||||
val distanceView = itemView.distanceView
|
||||
val coordsview = itemView.coordsView
|
||||
val batteryPctView = itemView.batteryPercentageView
|
||||
val lastTime = itemView.lastConnectionView
|
||||
val powerIcon = itemView.batteryIcon
|
||||
|
@ -108,6 +111,13 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
holder.nodeNameView.text = n.user?.longName ?: n.user?.id ?: "Unknown node"
|
||||
|
||||
val ourNodeInfo = model.nodeDB.ourNodeInfo
|
||||
val pos = ourNodeInfo?.position;
|
||||
if (pos != null) {
|
||||
holder.coordsview.text = pos.latitude.toString() + " " + pos.longitude
|
||||
holder.coordsview.visibility = View.VISIBLE
|
||||
} else {
|
||||
holder.coordsview.visibility = View.INVISIBLE
|
||||
}
|
||||
val distance = ourNodeInfo?.distanceStr(n)
|
||||
if (distance != null) {
|
||||
holder.distanceView.text = distance
|
||||
|
@ -118,7 +128,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
|
||||
renderBattery(n.batteryPctLevel, holder)
|
||||
|
||||
holder.lastTime.text = getLastTimeValue(n)
|
||||
holder.lastTime.text = formatAgo(n.lastSeen);
|
||||
}
|
||||
|
||||
private var nodes = arrayOf<NodeInfo>()
|
||||
|
@ -150,30 +160,6 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
})
|
||||
}
|
||||
|
||||
private fun getLastTimeValue(n: NodeInfo): String {
|
||||
var lastTimeText = "?"
|
||||
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?
|
||||
|
|
|
@ -51,6 +51,19 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/coords_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="76dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/sample_coords"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/batteryIcon"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -94,4 +94,5 @@
|
|||
<string name="okay">Okay</string>
|
||||
<string name="must_set_region">You must set a region!</string>
|
||||
<string name="region">Region</string>
|
||||
<string name="sample_coords">55.332244 34.442211</string>
|
||||
</resources>
|
||||
|
|
Ładowanie…
Reference in New Issue