Last active
July 15, 2020 18:16
-
-
Save yashovardhan99/b14fe26d535049cbd2ca76f17655ffc4 to your computer and use it in GitHub Desktop.
Firebase MVVM User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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