mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
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.
|
||||
*/
|
||||
@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
|
||||
|
||||
}
|
||||
|
@ -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<View>(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)
|
||||
|
Loading…
Reference in New Issue
Block a user