forked from GitHub-Mirror/riotX-android
Fix issue: lastSeenTs can be null
This commit is contained in:
parent
f6c36670c3
commit
64e5fed7ac
@ -48,7 +48,7 @@ data class DeviceInfo(
|
|||||||
* The last time this device has been seen.
|
* The last time this device has been seen.
|
||||||
*/
|
*/
|
||||||
@Json(name = "last_seen_ts")
|
@Json(name = "last_seen_ts")
|
||||||
var lastSeenTs: Long = 0,
|
var lastSeenTs: Long? = null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last ip address
|
* The last ip address
|
||||||
@ -58,6 +58,6 @@ data class DeviceInfo(
|
|||||||
) : DatedObject {
|
) : DatedObject {
|
||||||
|
|
||||||
override val date: Long
|
override val date: Long
|
||||||
get() = lastSeenTs
|
get() = lastSeenTs ?: 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2379,19 +2379,21 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref
|
|||||||
|
|
||||||
// last seen info
|
// last seen info
|
||||||
textView = layout.findViewById(R.id.device_last_seen)
|
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 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 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)
|
val lastSeenInfo = getString(R.string.devices_details_last_seen_format, lastSeenIp, lastSeenTime)
|
||||||
textView.text = lastSeenInfo
|
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
|
// title & icon
|
||||||
builder.setTitle(R.string.devices_details_dialog_title)
|
builder.setTitle(R.string.devices_details_dialog_title)
|
||||||
|
Loading…
Reference in New Issue
Block a user