FirebaseJetpack
Represents a Jetpack item stored in Firebase Firestore with sync metadata.
This model demonstrates the offline-first sync pattern used in this template. It includes metadata fields (lastUpdated, lastSynced, deleted) that enable bidirectional synchronization between local Room database and remote Firestore.
Sync Pattern
Pull: Query Firestore for items where
lastUpdated > lastSyncTimestampPush: Upload local items to Firestore based on their SyncAction
Soft Delete: Use deleted flag instead of hard deletion for sync safety
Field Initialization
All properties must have default values to work with Firestore's automatic serialization. This is a Firestore requirement for data classes used as document models.
Usage Example
// Create new item
val jetpack = FirebaseJetpack(
name = "Lightning Bolt",
price = 99.99,
userId = currentUser.id,
lastUpdated = System.currentTimeMillis()
)
// Mark for deletion (soft delete)
val deletedJetpack = jetpack.copy(
deleted = true,
lastUpdated = System.currentTimeMillis()
)Conversion to/from Room Entity
// Extension in repository layer
fun FirebaseJetpack.toEntity() = JetpackEntity(
id = id,
name = name,
price = price,
userId = userId,
lastUpdated = lastUpdated,
lastSynced = lastSynced,
deleted = deleted,
syncAction = SyncAction.SYNCED
)
fun JetpackEntity.toFirebase() = FirebaseJetpack(
id = id,
name = name,
price = price,
userId = userId,
lastUpdated = lastUpdated,
lastSynced = lastSynced,
deleted = deleted
)See also
Constructors
Properties
Timestamp in milliseconds (epoch time) of the last successful sync with Firestore. Updated after successful push/pull operations.
Timestamp in milliseconds (epoch time) of the last modification to this item. Updated whenever the item is created, modified, or soft-deleted. Used for incremental sync to pull only changed items.