mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
Fix last seen indicator not live updating.
This commit is contained in:
@@ -31,6 +31,7 @@ import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.isActive
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -95,7 +96,7 @@ class OverviewFragmentVM @Inject constructor(
|
||||
requiredPermissions,
|
||||
pods,
|
||||
debugSettings.isDebugModeEnabled.flow,
|
||||
) { _, permissions, pods, isDebugMode ->
|
||||
) { tick, permissions, pods, isDebugMode ->
|
||||
val items = mutableListOf<OverviewAdapter.Item>()
|
||||
|
||||
permissions
|
||||
@@ -107,13 +108,29 @@ class OverviewFragmentVM @Inject constructor(
|
||||
}
|
||||
.forEach { items.add(it) }
|
||||
|
||||
val now = Instant.now()
|
||||
pods
|
||||
.map {
|
||||
when (it) {
|
||||
is DualApplePods -> DualApplePodsCardVH.Item(it, showDebug = isDebugMode)
|
||||
is SingleApplePods -> SingleApplePodsCardVH.Item(it, showDebug = isDebugMode)
|
||||
is BasicSingleApplePods -> BasicSingleApplePodsCardVH.Item(it, showDebug = isDebugMode)
|
||||
else -> UnknownPodDeviceCardVH.Item(it)
|
||||
is DualApplePods -> DualApplePodsCardVH.Item(
|
||||
now = now,
|
||||
device = it,
|
||||
showDebug = isDebugMode
|
||||
)
|
||||
is SingleApplePods -> SingleApplePodsCardVH.Item(
|
||||
now = now,
|
||||
device = it,
|
||||
showDebug = isDebugMode
|
||||
)
|
||||
is BasicSingleApplePods -> BasicSingleApplePodsCardVH.Item(
|
||||
now = now,
|
||||
device = it,
|
||||
showDebug = isDebugMode
|
||||
)
|
||||
else -> UnknownPodDeviceCardVH.Item(
|
||||
now = now,
|
||||
device = it
|
||||
)
|
||||
}
|
||||
}
|
||||
.run { items.addAll(this) }
|
||||
|
||||
+2
-1
@@ -27,7 +27,7 @@ class BasicSingleApplePodsCardVH(parent: ViewGroup) :
|
||||
name.text = device.getLabel(context)
|
||||
deviceIcon.setImageResource(device.iconRes)
|
||||
|
||||
val duration = Duration.between(device.lastSeenAt, Instant.now())
|
||||
val duration = Duration.between(device.lastSeenAt, item.now)
|
||||
lastSeen.text = lastSeenFormatter.format(
|
||||
duration.seconds.toDouble(),
|
||||
RelativeDateTimeFormatter.Direction.LAST,
|
||||
@@ -54,6 +54,7 @@ class BasicSingleApplePodsCardVH(parent: ViewGroup) :
|
||||
}
|
||||
|
||||
data class Item(
|
||||
override val now: Instant,
|
||||
override val device: BasicSingleApplePods,
|
||||
override val showDebug: Boolean,
|
||||
) : PodDeviceVH.Item
|
||||
|
||||
+2
-2
@@ -27,7 +27,6 @@ class DualApplePodsCardVH(parent: ViewGroup) :
|
||||
|
||||
override val onBindData = binding(payload = true) { item: Item ->
|
||||
val device = item.device
|
||||
|
||||
name.apply {
|
||||
val sb = StringBuilder(device.getLabel(context))
|
||||
if (device.deviceColor != DeviceColor.UNKNOWN) {
|
||||
@@ -37,7 +36,7 @@ class DualApplePodsCardVH(parent: ViewGroup) :
|
||||
}
|
||||
deviceIcon.setImageResource(device.iconRes)
|
||||
|
||||
val duration = Duration.between(device.lastSeenAt, Instant.now())
|
||||
val duration = Duration.between(device.lastSeenAt, item.now)
|
||||
lastSeen.text = lastSeenFormatter.format(
|
||||
duration.seconds.toDouble(),
|
||||
RelativeDateTimeFormatter.Direction.LAST,
|
||||
@@ -98,6 +97,7 @@ class DualApplePodsCardVH(parent: ViewGroup) :
|
||||
}
|
||||
|
||||
data class Item(
|
||||
override val now: Instant,
|
||||
override val device: DualApplePods,
|
||||
override val showDebug: Boolean,
|
||||
) : PodDeviceVH.Item
|
||||
|
||||
@@ -8,6 +8,7 @@ import eu.darken.capod.common.lists.differ.DifferItem
|
||||
import eu.darken.capod.common.lists.modular.ModularAdapter
|
||||
import eu.darken.capod.main.ui.overview.OverviewAdapter
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import java.time.Instant
|
||||
|
||||
abstract class PodDeviceVH<D : PodDeviceVH.Item, B : ViewBinding>(
|
||||
@LayoutRes layoutId: Int,
|
||||
@@ -16,6 +17,8 @@ abstract class PodDeviceVH<D : PodDeviceVH.Item, B : ViewBinding>(
|
||||
|
||||
interface Item : OverviewAdapter.Item {
|
||||
|
||||
val now: Instant
|
||||
|
||||
val device: PodDevice
|
||||
|
||||
val showDebug: Boolean
|
||||
|
||||
+2
-1
@@ -27,7 +27,7 @@ class SingleApplePodsCardVH(parent: ViewGroup) :
|
||||
name.text = device.getLabel(context)
|
||||
deviceIcon.setImageResource(device.iconRes)
|
||||
|
||||
val duration = Duration.between(device.lastSeenAt, Instant.now())
|
||||
val duration = Duration.between(device.lastSeenAt, item.now)
|
||||
lastSeen.text = lastSeenFormatter.format(
|
||||
duration.seconds.toDouble(),
|
||||
RelativeDateTimeFormatter.Direction.LAST,
|
||||
@@ -59,6 +59,7 @@ class SingleApplePodsCardVH(parent: ViewGroup) :
|
||||
}
|
||||
|
||||
data class Item(
|
||||
override val now: Instant,
|
||||
override val device: SingleApplePods,
|
||||
override val showDebug: Boolean,
|
||||
) : PodDeviceVH.Item
|
||||
|
||||
+2
-1
@@ -25,7 +25,7 @@ class UnknownPodDeviceCardVH(parent: ViewGroup) :
|
||||
val device = item.device
|
||||
name.text = device.getLabel(context)
|
||||
|
||||
val duration = Duration.between(device.lastSeenAt, Instant.now())
|
||||
val duration = Duration.between(device.lastSeenAt, item.now)
|
||||
lastSeen.text = lastSeenFormatter.format(
|
||||
duration.seconds.toDouble(),
|
||||
RelativeDateTimeFormatter.Direction.LAST,
|
||||
@@ -36,6 +36,7 @@ class UnknownPodDeviceCardVH(parent: ViewGroup) :
|
||||
}
|
||||
|
||||
data class Item(
|
||||
override val now: Instant,
|
||||
override val device: PodDevice,
|
||||
override val showDebug: Boolean = false
|
||||
) : PodDeviceVH.Item
|
||||
|
||||
Reference in New Issue
Block a user