Fix issue: lastSeenTs can be null

This commit is contained in:
Benoit Marty 2019-06-11 13:57:35 +02:00
parent f6c36670c3
commit 64e5fed7ac
2 changed files with 15 additions and 13 deletions

View File

@ -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

}

View File

@ -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

dateFormat.format(date) + ", " + time
} ?: "-"

val lastSeenInfo = getString(R.string.devices_details_last_seen_format, lastSeenIp, lastSeenTime)
textView.text = lastSeenInfo
} else {
// hide last time seen section
layout.findViewById<View>(R.id.device_last_seen_title).visibility = View.GONE
textView.visibility = View.GONE
}

// title & icon
builder.setTitle(R.string.devices_details_dialog_title)