Display power plug icon when no battery #99

1.2-legacy
Ludovic Goix 2020-07-16 08:50:47 -04:00
rodzic 75be43b3c5
commit 4a6d88039b
2 zmienionych plików z 36 dodań i 12 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
@ -31,6 +32,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
val distance_view = itemView.distance_view
val batteryPctView = itemView.batteryPercentageView
val lastTime = itemView.lastConnectionView
val powerIcon = itemView.batteryIcon
}
private val nodesAdapter = object : RecyclerView.Adapter<ViewHolder>() {
@ -112,15 +114,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
holder.distance_view.visibility = View.INVISIBLE
}
val battery = n.batteryPctLevel
if (battery != null)
{
holder.batteryPctView.text = "$battery%"
}
else
{
holder.batteryPctView.text = "?"
}
renderBattery(n.batteryPctLevel, holder)
holder.lastTime.text = getLastTimeValue(n)
}
@ -134,14 +128,33 @@ class UsersFragment : ScreenFragment("Users"), Logging {
}
}
private fun getLastTimeValue(n: NodeInfo): String {
var lastTimeText: String = "?"
private fun renderBattery(
battery: Int?,
holder: ViewHolder
) {
val (image, text) = when (battery) {
null -> Pair(R.drawable.ic_battery_full_24, "?")
0 -> Pair(R.drawable.ic_power_plug_24, "")
else -> Pair(R.drawable.ic_battery_full_24, "$battery%")
}
holder.batteryPctView.text = text
holder.powerIcon.setImageDrawable(context?.let {
ContextCompat.getDrawable(
it,
image
)
})
}
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))
if (n.lastSeen < (currentTime - threeDaysLong))
return lastTimeText
try {

Wyświetl plik

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:fillAlpha=".5"
android:pathData="M16,7V3H14V7H10V3H8V7H8C7,7 6,8 6,9V14.5L9.5,18V21H14.5V18L18,14.5V9C18,8 17,7 16,7Z" />
</vector>