Skip to content

Commit a8b3c54

Browse files
imbissbudenaesthetikSn0wfreezeDev
authored andcommitted
add Last Seen Overview to per Device Page (expert mode only)
1 parent 1d9fcaa commit a8b3c54

File tree

5 files changed

+322
-264
lines changed

5 files changed

+322
-264
lines changed

app/src/main/java/de/seemoo/at_tracking_detection/ui/tracking/TrackingViewModel.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import de.seemoo.at_tracking_detection.database.models.device.DeviceType
1212
import de.seemoo.at_tracking_detection.database.repository.BeaconRepository
1313
import de.seemoo.at_tracking_detection.database.repository.DeviceRepository
1414
import de.seemoo.at_tracking_detection.database.repository.NotificationRepository
15+
import de.seemoo.at_tracking_detection.util.SharedPrefs
1516
import kotlinx.coroutines.launch
1617
import timber.log.Timber
1718
import java.time.LocalDateTime
19+
import java.time.format.DateTimeFormatter
20+
import java.time.format.FormatStyle
1821
import javax.inject.Inject
1922

2023
class TrackingViewModel @Inject constructor(
@@ -59,6 +62,13 @@ class TrackingViewModel @Inject constructor(
5962
it.size.toString()
6063
}
6164

65+
val lastSeenTimes: MutableLiveData<List<String>> = MutableLiveData(emptyList())
66+
val lastSeenTimesString: LiveData<String> = lastSeenTimes.map {
67+
it.joinToString(separator = "\n")
68+
}
69+
70+
val expertMode = MutableLiveData(false)
71+
6272
fun loadDevice(address: String, deviceTypeOverride: DeviceType) =
6373
deviceRepository.getDevice(address).also { device ->
6474
this.device.postValue(device)
@@ -77,6 +87,12 @@ class TrackingViewModel @Inject constructor(
7787
canBeIgnored.postValue(deviceType.value!!.canBeIgnored(ConnectionState.OVERMATURE_OFFLINE))
7888
val notification = notificationRepository.notificationForDevice(device).firstOrNull()
7989
notification?.let { notificationId.postValue(it.notificationId) }
90+
91+
// Load last seen times
92+
viewModelScope.launch {
93+
loadLastSeenTimes(device)
94+
expertMode.postValue(SharedPrefs.advancedMode)
95+
}
8096
} else {
8197
noLocationsYet.postValue(true)
8298
}
@@ -89,6 +105,14 @@ class TrackingViewModel @Inject constructor(
89105
}
90106
}
91107

108+
private fun loadLastSeenTimes(baseDevice: BaseDevice) {
109+
val beacons = beaconRepository.getDeviceBeacons(baseDevice.address)
110+
val lastSeenList = beacons.sortedByDescending { it.receivedAt }.take(5).map { beacon ->
111+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).format(beacon.receivedAt)
112+
}
113+
lastSeenTimes.postValue(lastSeenList)
114+
}
115+
92116
fun toggleIgnoreDevice() {
93117
if (deviceAddress.value != null) {
94118
val newState = !deviceIgnored.value!!

app/src/main/res/layout/fragment_risk_detail.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
/>
5151

5252
</androidx.constraintlayout.widget.ConstraintLayout>
53+
5354
<com.google.android.material.card.MaterialCardView
5455
android:id="@+id/dates_detected"
5556
style="?attr/materialCardViewElevatedStyle"

0 commit comments

Comments
 (0)