Skip to content

Commit

Permalink
Merge pull request #102 from HLCaptain/94-final-fixups-for-release
Browse files Browse the repository at this point in the history
Dependency upgrade + Data Access refactoring
  • Loading branch information
HLCaptain authored Apr 28, 2023
2 parents 00ac669 + 0a73452 commit 7bf04ab
Show file tree
Hide file tree
Showing 34 changed files with 731 additions and 493 deletions.
26 changes: 18 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id 'org.jetbrains.kotlin.plugin.serialization'
id 'kotlin-kapt'
id 'kotlin-android'
id 'com.google.dagger.hilt.android'
id 'com.google.devtools.ksp' version "$kotlin_version-1.0.11-SNAPSHOT" // Depends on your kotlin version
id 'de.mannodermaus.android-junit5'
id 'kotlin-parcelize'
id 'org.jetbrains.kotlin.plugin.serialization'
id 'com.google.firebase.crashlytics'
id 'com.google.gms.google-services'
id 'com.google.dagger.hilt.android'
id 'com.google.devtools.ksp'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
id 'de.mannodermaus.android-junit5'
}

android {
Expand All @@ -40,13 +40,22 @@ android {
applicationId "illyan.jay"
minSdk 21
targetSdk 33
versionCode 13
versionName "0.3.2-alpha"
versionCode 14
versionName "0.3.3-alpha"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}

javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true"
]
}
}
}

buildTypes {
Expand Down Expand Up @@ -184,8 +193,9 @@ dependencies {
// Room
def room_version = '2.5.1'
implementation "androidx.room:room-ktx:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
ksp "androidx.room:room-compiler:$room_version"

// Serialization
implementation "androidx.datastore:datastore:1.0.0"
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/illyan/jay/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
package illyan.jay

import android.app.Application
import androidx.datastore.core.DataStore
import com.google.android.gms.ads.MobileAds
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.perf.FirebasePerformance
import dagger.hilt.android.HiltAndroidApp
import illyan.jay.data.datastore.model.AppSettings
import illyan.jay.di.CoroutineScopeIO
import illyan.jay.domain.interactor.AuthInteractor
import illyan.jay.domain.interactor.SettingsInteractor
Expand All @@ -42,7 +40,6 @@ import kotlin.coroutines.cancellation.CancellationException
class MainApplication : Application() {
@Inject lateinit var crashlyticsTree: CrashlyticsTree
@Inject lateinit var debugTree: Timber.DebugTree
@Inject lateinit var appSettingsDataStore: DataStore<AppSettings>
@Inject lateinit var authInteractor: AuthInteractor
@Inject lateinit var crashlytics: FirebaseCrashlytics
@Inject lateinit var analytics: FirebaseAnalytics
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
* This file is part of Jay.
*
* Jay is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
* Jay is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Jay.
* If not, see <https://www.gnu.org/licenses/>.
*/

package illyan.jay.data.datastore.datasource

import androidx.datastore.core.DataStore
import illyan.jay.data.datastore.model.AppSettings
import illyan.jay.domain.model.DomainPreferences
import kotlinx.coroutines.flow.map
import timber.log.Timber
import java.time.ZonedDateTime
import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AppSettingsDataSource @Inject constructor(
private val appSettingsDataStore: DataStore<AppSettings>
) {
val appSettings by lazy {
appSettingsDataStore.data.map { settings ->
if (settings.clientUUID == null) {
val newSettings = settings.copy(clientUUID = UUID.randomUUID().toString())
updateAppSettings { newSettings }
newSettings
} else {
settings
}
}
}

suspend fun updateAppSettings(transform: (AppSettings) -> AppSettings) {
appSettingsDataStore.updateData {
val newSettings = transform(it)
Timber.v("Changed settings from $it to $newSettings")
newSettings
}
}

suspend fun updateAppPreferences(transform: (DomainPreferences) -> DomainPreferences) {
Timber.v("Updating App Preferences requested")
updateAppSettings {
it.copy(preferences = transform(it.preferences).copy(lastUpdate = ZonedDateTime.now()))
}
}
}
1 change: 0 additions & 1 deletion app/src/main/java/illyan/jay/data/firestore/Mapping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import android.os.Parcelable
import com.github.luben.zstd.Zstd
import com.google.firebase.Timestamp
import com.google.firebase.firestore.Blob
import com.google.firebase.firestore.DocumentSnapshot
import illyan.jay.BuildConfig
import illyan.jay.data.DataStatus
import illyan.jay.data.firestore.model.FirestoreLocation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
/*
* Copyright (c) 2023 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
* This file is part of Jay.
*
* Jay is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
* Jay is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Jay.
* If not, see <https://www.gnu.org/licenses/>.
*/

package illyan.jay.data.firestore.datasource

import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.DocumentSnapshot
import com.google.firebase.firestore.MetadataChanges
import com.google.firebase.firestore.SnapshotMetadata
import com.google.firebase.firestore.ktx.snapshots
import illyan.jay.di.CoroutineScopeIO
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.flow.updateAndGet
import kotlinx.coroutines.launch

class FirestoreDocumentSnapshotHandler<DataType>(
private val snapshotToObject: (DocumentSnapshot) -> DataType?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package illyan.jay.data.firestore.datasource
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.SnapshotMetadata
import com.google.firebase.firestore.WriteBatch
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.channelFlow
Expand All @@ -29,15 +30,22 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlin.coroutines.cancellation.CancellationException

abstract class FirestoreSnapshotHandler<DataType, SnapshotType> {
abstract val snapshotSourceFlow: Flow<Flow<SnapshotType>?>

protected val documentReferences = MutableStateFlow<List<DocumentReference>?>(null)
val snapshots = channelFlow {
var uuidJob: Job? = null
snapshotSourceFlow.collectLatest { snapshots ->
resetState()
snapshots?.let { launch { snapshots.collectLatest { channel.send(it) } } }
uuidJob?.cancel(CancellationException("User authentication changed"))
snapshots?.let {
uuidJob = launch {
snapshots.collectLatest { send(it) }
}
}
}
}

Expand Down
Loading

0 comments on commit 7bf04ab

Please sign in to comment.