style: replace Pair() usage with explicit values

This commit is contained in:
andrekir 2023-07-31 23:07:27 -03:00
parent 377c6a18e0
commit cdc76155d9
4 changed files with 12 additions and 27 deletions

View file

@ -160,10 +160,7 @@ class MainActivity : AppCompatActivity(), Logging {
private val tabsAdapter = object : FragmentStateAdapter(supportFragmentManager, lifecycle) {
override fun getItemCount(): Int = tabInfos.size
override fun createFragment(position: Int): Fragment {
return tabInfos[position].content
}
override fun createFragment(position: Int): Fragment = tabInfos[position].content
}
private val isInTestLab: Boolean by lazy {
@ -217,20 +214,12 @@ class MainActivity : AppCompatActivity(), Logging {
}
private fun updateConnectionStatusImage(connected: MeshService.ConnectionState) {
if (model.actionBarMenu == null)
return
if (model.actionBarMenu == null) return
val (image, tooltip) = when (connected) {
MeshService.ConnectionState.CONNECTED -> Pair(R.drawable.cloud_on, R.string.connected)
MeshService.ConnectionState.DEVICE_SLEEP -> Pair(
R.drawable.ic_twotone_cloud_upload_24,
R.string.device_sleeping
)
MeshService.ConnectionState.DISCONNECTED -> Pair(
R.drawable.cloud_off,
R.string.disconnected
)
MeshService.ConnectionState.CONNECTED -> R.drawable.cloud_on to R.string.connected
MeshService.ConnectionState.DEVICE_SLEEP -> R.drawable.ic_twotone_cloud_upload_24 to R.string.device_sleeping
MeshService.ConnectionState.DISCONNECTED -> R.drawable.cloud_off to R.string.disconnected
}
val item = model.actionBarMenu?.findItem(R.id.connectStatusImage)

View file

@ -164,7 +164,7 @@ data class NodeInfo(
val g = (num and 0x00FF00) shr 8
val b = num and 0x0000FF
val brightness = ((r * 0.299) + (g * 0.587) + (b * 0.114)) / 255
return Pair(if (brightness > 0.5) Color.BLACK else Color.WHITE, Color.rgb(r, g, b))
return (if (brightness > 0.5) Color.BLACK else Color.WHITE) to Color.rgb(r, g, b)
}
val batteryLevel get() = deviceMetrics?.batteryLevel

View file

@ -330,11 +330,10 @@ class MeshService : Service(), Logging {
myNodeInfo = ni
// put our node array into our two different map representations
nodeDBbyNodeNum.putAll(nodes.map { Pair(it.num, it) })
nodeDBbyNodeNum.putAll(nodes.map { it.num to it })
nodeDBbyID.putAll(nodes.mapNotNull {
it.user?.let { user -> // ignore records that don't have a valid user
Pair(user.id, it)
}
// ignore records that don't have a valid user
it.user?.let { user -> user.id to it }
})
}

View file

@ -254,12 +254,9 @@ class UsersFragment : ScreenFragment("Users"), Logging {
) {
val (image, text) = when (battery) {
in 0..100 -> Pair(
R.drawable.ic_battery_full_24,
"%d%% %.2fV".format(battery, voltage ?: 0)
)
101 -> Pair(R.drawable.ic_power_plug_24, "")
else -> Pair(R.drawable.ic_battery_full_24, "?")
in 0..100 -> R.drawable.ic_battery_full_24 to "%d%% %.2fV".format(battery, voltage)
101 -> R.drawable.ic_power_plug_24 to ""
else -> R.drawable.ic_battery_full_24 to "?"
}
holder.batteryPctView.text = text