diff --git a/app/src/main/java/illyan/jay/data/disk/model/RoomPreferences.kt b/app/src/main/java/illyan/jay/data/disk/model/RoomPreferences.kt index 2c85d6fc..ec845839 100644 --- a/app/src/main/java/illyan/jay/data/disk/model/RoomPreferences.kt +++ b/app/src/main/java/illyan/jay/data/disk/model/RoomPreferences.kt @@ -20,6 +20,7 @@ package illyan.jay.data.disk.model import androidx.room.Entity import androidx.room.PrimaryKey +import illyan.jay.domain.model.DomainPreferences import java.time.ZonedDateTime import java.util.UUID @@ -29,8 +30,8 @@ import java.util.UUID data class RoomPreferences( @PrimaryKey val userUUID: String = UUID.randomUUID().toString(), - val freeDriveAutoStart: Boolean = false, - val analyticsEnabled: Boolean = false, + val freeDriveAutoStart: Boolean = DomainPreferences.default.freeDriveAutoStart, + val analyticsEnabled: Boolean = DomainPreferences.default.analyticsEnabled, val lastUpdate: Long = ZonedDateTime.now().toInstant().toEpochMilli(), - val shouldSync: Boolean = false + val shouldSync: Boolean = DomainPreferences.default.shouldSync ) diff --git a/app/src/main/java/illyan/jay/data/network/datasource/PreferencesNetworkDataSource.kt b/app/src/main/java/illyan/jay/data/network/datasource/PreferencesNetworkDataSource.kt index 0c0cd7f6..43b09cb8 100644 --- a/app/src/main/java/illyan/jay/data/network/datasource/PreferencesNetworkDataSource.kt +++ b/app/src/main/java/illyan/jay/data/network/datasource/PreferencesNetworkDataSource.kt @@ -86,7 +86,7 @@ class PreferencesNetworkDataSource @Inject constructor( val userRef = firestore .collection(FirestoreUser.CollectionName) .document(authInteractor.userUUID!!) - val fieldMapToSet = mapOf(FirestoreUser.FieldSettings to preferences.toFirestoreModel()) + val fieldMapToSet = mapOf(FirestoreUser.FieldPreferences to preferences.toFirestoreModel()) batch.set( userRef, fieldMapToSet, diff --git a/app/src/main/java/illyan/jay/data/network/model/FirestorePath.kt b/app/src/main/java/illyan/jay/data/network/model/FirestorePath.kt index e051bfe8..3606d301 100644 --- a/app/src/main/java/illyan/jay/data/network/model/FirestorePath.kt +++ b/app/src/main/java/illyan/jay/data/network/model/FirestorePath.kt @@ -22,6 +22,7 @@ import android.os.Parcelable import com.google.firebase.Timestamp import com.google.firebase.firestore.DocumentId import com.google.firebase.firestore.GeoPoint +import com.google.firebase.firestore.PropertyName import kotlinx.parcelize.Parcelize import kotlinx.parcelize.TypeParceler @@ -31,21 +32,21 @@ import kotlinx.parcelize.TypeParceler data class FirestorePath( @DocumentId val uuid: String = "", - val sessionUUID: String = "", // reference of the session this path is part of - val ownerUUID: String = "", - val accuracyChangeTimestamps: List = emptyList(), - val accuracyChanges: List = emptyList(), - val altitudes: List = emptyList(), - val bearingAccuracyChangeTimestamps: List = emptyList(), - val bearingAccuracyChanges: List = emptyList(), - val bearings: List = emptyList(), - val coords: List = emptyList(), - val speeds: List = emptyList(), - val speedAccuracyChangeTimestamps: List = emptyList(), - val speedAccuracyChanges: List = emptyList(), - val timestamps: List = emptyList(), - val verticalAccuracyChangeTimestamps: List = emptyList(), - val verticalAccuracyChanges: List = emptyList() + @PropertyName(FieldSessionUUID) val sessionUUID: String = "", // reference of the session this path is part of + @PropertyName(FieldOwnerUUID) val ownerUUID: String = "", + @PropertyName(FieldAccuracyChangeTimestamps) val accuracyChangeTimestamps: List = emptyList(), + @PropertyName(FieldAccuracyChanges) val accuracyChanges: List = emptyList(), + @PropertyName(FieldAltitudes) val altitudes: List = emptyList(), + @PropertyName(FieldBearingAccuracyChangeTimestamps) val bearingAccuracyChangeTimestamps: List = emptyList(), + @PropertyName(FieldBearingAccuracyChanges) val bearingAccuracyChanges: List = emptyList(), + @PropertyName(FieldBearings) val bearings: List = emptyList(), + @PropertyName(FieldCoords) val coords: List = emptyList(), + @PropertyName(FieldSpeeds) val speeds: List = emptyList(), + @PropertyName(FieldSpeedAccuracyChangeTimestamps) val speedAccuracyChangeTimestamps: List = emptyList(), + @PropertyName(FieldSpeedAccuracyChanges) val speedAccuracyChanges: List = emptyList(), + @PropertyName(FieldTimestamps) val timestamps: List = emptyList(), + @PropertyName(FieldVerticalAccuracyChangeTimestamps) val verticalAccuracyChangeTimestamps: List = emptyList(), + @PropertyName(FieldVerticalAccuracyChanges) val verticalAccuracyChanges: List = emptyList() ) : Parcelable { companion object { const val CollectionName = "paths" diff --git a/app/src/main/java/illyan/jay/data/network/model/FirestoreSession.kt b/app/src/main/java/illyan/jay/data/network/model/FirestoreSession.kt index 6b1cbbb7..287b8ac2 100644 --- a/app/src/main/java/illyan/jay/data/network/model/FirestoreSession.kt +++ b/app/src/main/java/illyan/jay/data/network/model/FirestoreSession.kt @@ -20,19 +20,20 @@ package illyan.jay.data.network.model import com.google.firebase.Timestamp import com.google.firebase.firestore.GeoPoint +import com.google.firebase.firestore.PropertyName import illyan.jay.util.toTimestamp import java.time.Instant data class FirestoreSession( - val uuid: String = "", - val startDateTime: Timestamp = Instant.EPOCH.toTimestamp(), - val endDateTime: Timestamp? = null, - val startLocation: GeoPoint? = null, - val endLocation: GeoPoint? = null, - val startLocationName: String? = null, - val endLocationName: String? = null, - val distance: Float? = null, - val clientUUID: String? = null + @PropertyName(FieldUUID) val uuid: String = "", + @PropertyName(FieldStartDateTime) val startDateTime: Timestamp = Instant.EPOCH.toTimestamp(), + @PropertyName(FieldEndDateTime) val endDateTime: Timestamp? = null, + @PropertyName(FieldStartLocation) val startLocation: GeoPoint? = null, + @PropertyName(FieldEndLocation) val endLocation: GeoPoint? = null, + @PropertyName(FieldStartLocationName) val startLocationName: String? = null, + @PropertyName(FieldEndLocationName) val endLocationName: String? = null, + @PropertyName(FieldDistance) val distance: Float? = null, + @PropertyName(FieldClientUUID) val clientUUID: String? = null ) { companion object { const val FieldUUID = "uuid" diff --git a/app/src/main/java/illyan/jay/data/network/model/FirestoreUser.kt b/app/src/main/java/illyan/jay/data/network/model/FirestoreUser.kt index 77f6afc7..fb954398 100644 --- a/app/src/main/java/illyan/jay/data/network/model/FirestoreUser.kt +++ b/app/src/main/java/illyan/jay/data/network/model/FirestoreUser.kt @@ -19,16 +19,17 @@ package illyan.jay.data.network.model import com.google.firebase.firestore.DocumentId +import com.google.firebase.firestore.PropertyName data class FirestoreUser( @DocumentId val uuid: String = "", - val sessions: List = emptyList(), - val preferences: FirestoreUserPreferences? = null + @PropertyName(FieldSessions) val sessions: List = emptyList(), + @PropertyName(FieldPreferences) val preferences: FirestoreUserPreferences? = null ) { companion object { const val CollectionName = "users" const val FieldSessions = "sessions" - const val FieldSettings = "preferences" + const val FieldPreferences = "preferences" } } \ No newline at end of file diff --git a/app/src/main/java/illyan/jay/data/network/model/FirestoreUserPreferences.kt b/app/src/main/java/illyan/jay/data/network/model/FirestoreUserPreferences.kt index e5301715..8ad14784 100644 --- a/app/src/main/java/illyan/jay/data/network/model/FirestoreUserPreferences.kt +++ b/app/src/main/java/illyan/jay/data/network/model/FirestoreUserPreferences.kt @@ -19,13 +19,17 @@ package illyan.jay.data.network.model import com.google.firebase.Timestamp +import com.google.firebase.firestore.PropertyName +import illyan.jay.domain.model.DomainPreferences data class FirestoreUserPreferences( - val analyticsEnabled: Boolean = false, - val freeDriveAutoStart: Boolean = false, - val lastUpdate: Timestamp = Timestamp.now() + @PropertyName(FieldAnalyticsEnabled) val analyticsEnabled: Boolean = DomainPreferences.default.analyticsEnabled, + @PropertyName(FieldFreeDriveAutoStart) val freeDriveAutoStart: Boolean = DomainPreferences.default.freeDriveAutoStart, + @PropertyName(FieldLastUpdate) val lastUpdate: Timestamp = Timestamp.now() ) { companion object { const val FieldAnalyticsEnabled = "analyticsEnabled" + const val FieldFreeDriveAutoStart = "freeDriveAutoStart" + const val FieldLastUpdate = "lastUpdate" } } diff --git a/app/src/main/java/illyan/jay/domain/model/DomainPreferences.kt b/app/src/main/java/illyan/jay/domain/model/DomainPreferences.kt index 1cd16b6b..0534008a 100644 --- a/app/src/main/java/illyan/jay/domain/model/DomainPreferences.kt +++ b/app/src/main/java/illyan/jay/domain/model/DomainPreferences.kt @@ -30,7 +30,7 @@ data class DomainPreferences( val freeDriveAutoStart: Boolean = false, @Serializable(with = ZonedDateTimeSerializer::class) val lastUpdate: ZonedDateTime = ZonedDateTime.now(), - val shouldSync: Boolean = false // FIXME: change this to true, because user preferences would break bcuz it would never download cloud preferences. Maybe make sync not update lastupdate? + val shouldSync: Boolean = false ) { override fun equals(other: Any?): Boolean { return if (other != null && other is DomainPreferences) {