From 64e5fed7ac5294a351dd2cb96bac25abf6fdc384 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 11 Jun 2019 13:57:35 +0200 Subject: [PATCH] Fix issue: lastSeenTs can be null --- .../internal/crypto/model/rest/DeviceInfo.kt | 4 ++-- .../VectorSettingsPreferencesFragment.kt | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/DeviceInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/DeviceInfo.kt index c43e1287c2..1bd5f671cc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/DeviceInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/DeviceInfo.kt @@ -48,7 +48,7 @@ data class DeviceInfo( * The last time this device has been seen. */ @Json(name = "last_seen_ts") - var lastSeenTs: Long = 0, + var lastSeenTs: Long? = null, /** * The last ip address @@ -58,6 +58,6 @@ data class DeviceInfo( ) : DatedObject { override val date: Long - get() = lastSeenTs + get() = lastSeenTs ?: 0 } diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt index 822c91c8c7..06455f35a6 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt @@ -2379,19 +2379,21 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // last seen info textView = layout.findViewById(R.id.device_last_seen) - if (!TextUtils.isEmpty(aDeviceInfo.lastSeenIp)) { - val lastSeenIp = aDeviceInfo.lastSeenIp + + val lastSeenIp = aDeviceInfo.lastSeenIp?.takeIf { ip -> ip.isNotBlank() } ?: "-" + + val lastSeenTime = aDeviceInfo.lastSeenTs?.let { ts -> val dateFormatTime = SimpleDateFormat("HH:mm:ss") - val time = dateFormatTime.format(Date(aDeviceInfo.lastSeenTs)) + val date = Date(ts) + + val time = dateFormatTime.format(date) val dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()) - val lastSeenTime = dateFormat.format(Date(aDeviceInfo.lastSeenTs)) + ", " + time - val lastSeenInfo = getString(R.string.devices_details_last_seen_format, lastSeenIp, lastSeenTime) - textView.text = lastSeenInfo - } else { - // hide last time seen section - layout.findViewById(R.id.device_last_seen_title).visibility = View.GONE - textView.visibility = View.GONE - } + + dateFormat.format(date) + ", " + time + } ?: "-" + + val lastSeenInfo = getString(R.string.devices_details_last_seen_format, lastSeenIp, lastSeenTime) + textView.text = lastSeenInfo // title & icon builder.setTitle(R.string.devices_details_dialog_title)