KV
07/28/2021, 8:40 AM/** Returns the signed in users ID as a `String` or `null` if no ID in shared preferences found (or `0`). */
fun SharedPreferencesManager.userId(): String? {
val userIdLong: Long = this.loadCurrentAdminPsid()
return if (userIdLong == 0L) null else userIdLong.toString()
}
ephemient
07/28/2021, 8:57 AMfun SharedPreferencesManager.userId() =
loadCurrentAdminPsid().takeIf { it != 0L }?.toString()
KV
07/28/2021, 9:03 AMEugen Martynov
07/28/2021, 9:56 AMKV
07/28/2021, 10:12 AMMichael Böiers
08/02/2021, 7:10 AMfun SharedPreferencesManager.userId() = loadCurrentAdminPsid().let {
if (it == 0L) null : it.toString()
}
Of course it would be helpful if you could refactor loadCurrentAdminPsid()
to return null if the id is invalid. And ideally you would use a value type for the id.