Prevent crash when destroying GroupedCallLogData if lastCallLogViewModel wasn't created yet

This commit is contained in:
Sylvain Berfini 2023-02-15 13:26:54 +01:00
parent 890d217ab7
commit 083c1afa11

View file

@ -27,10 +27,18 @@ class GroupedCallLogData(callLog: CallLog) {
val callLogs = arrayListOf(callLog)
val lastCallLogViewModel: CallLogViewModel
get() {
return CallLogViewModel(lastCallLog)
if (::_lastCallLogViewModel.isInitialized) {
return _lastCallLogViewModel
}
_lastCallLogViewModel = CallLogViewModel(lastCallLog)
return _lastCallLogViewModel
}
private lateinit var _lastCallLogViewModel: CallLogViewModel
fun destroy() {
lastCallLogViewModel.destroy()
if (::_lastCallLogViewModel.isInitialized) {
lastCallLogViewModel
}
}
}