diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt index 424a02fe..9e99e546 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt @@ -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() 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) } diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/BasicSingleApplePodsCardVH.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/BasicSingleApplePodsCardVH.kt index 3eda1b5c..10667491 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/BasicSingleApplePodsCardVH.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/BasicSingleApplePodsCardVH.kt @@ -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 diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/DualApplePodsCardVH.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/DualApplePodsCardVH.kt index 2402f3ea..99b22808 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/DualApplePodsCardVH.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/DualApplePodsCardVH.kt @@ -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 diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/PodDeviceVH.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/PodDeviceVH.kt index 98e67316..c7a9ca5f 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/PodDeviceVH.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/PodDeviceVH.kt @@ -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( @LayoutRes layoutId: Int, @@ -16,6 +17,8 @@ abstract class PodDeviceVH( interface Item : OverviewAdapter.Item { + val now: Instant + val device: PodDevice val showDebug: Boolean diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/SingleApplePodsCardVH.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/SingleApplePodsCardVH.kt index ee122ca7..345a8efa 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/SingleApplePodsCardVH.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/SingleApplePodsCardVH.kt @@ -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 diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/UnknownPodDeviceCardVH.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/UnknownPodDeviceCardVH.kt index 532e66a7..d70e3862 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/UnknownPodDeviceCardVH.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/pods/UnknownPodDeviceCardVH.kt @@ -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