Skip to content

Instantly share code, notes, and snippets.

@yashovardhan99
Last active July 15, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashovardhan99/b14fe26d535049cbd2ca76f17655ffc4 to your computer and use it in GitHub Desktop.
Save yashovardhan99/b14fe26d535049cbd2ca76f17655ffc4 to your computer and use it in GitHub Desktop.
Firebase MVVM User
@Parcelize
data class User(val userId: String, //Document ID is actually the user id
val name: String,
val bio: String,
val imageUrl: String) : Parcelable {
companion object {
fun DocumentSnapshot.toUser(): User? {
try {
val name = getString("name")!!
val imageUrl = getString("profile_image")!!
val bio = getString("user_bio")!!
return User(id, name, bio, imageUrl)
} catch (e: Exception) {
Log.e(TAG, "Error converting user profile", e)
FirebaseCrashlytics.getInstance().log("Error converting user profile")
FirebaseCrashlytics.getInstance().setCustomKey("userId", id)
FirebaseCrashlytics.getInstance().recordException(e)
return null
}
}
private const val TAG = "User"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment