From 1438839bc29c78f5ea72e24ff0f34b277f62608c Mon Sep 17 00:00:00 2001 From: Alexandre G Pereira Date: Sun, 14 Jan 2024 13:26:30 -0300 Subject: [PATCH] Fix: duplicating entries when sync (#232) * Fix: duplicating entries when sync * Implement capitalization on app text fields * Adjust analytics --- .../hunter/analytics/FirebaseAnalytics.kt | 8 +++++++- .../hunter/data/database/dao/MonsterDaoImpl.kt | 2 +- .../hunter/folder/preview/FolderPreviewState.kt | 6 ------ .../folder/preview/FolderPreviewStateHolder.kt | 16 +++++++++++++--- .../hunter/settings/ui/SettingsTextField.kt | 1 + .../hunter/sync/SyncStateHolder.kt | 3 ++- .../hunter/ui/compose/AppTextField.kt | 9 ++++++++- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/core/analytics/src/androidMain/kotlin/br/alexandregpereira/hunter/analytics/FirebaseAnalytics.kt b/core/analytics/src/androidMain/kotlin/br/alexandregpereira/hunter/analytics/FirebaseAnalytics.kt index fa49da74..527e1c95 100644 --- a/core/analytics/src/androidMain/kotlin/br/alexandregpereira/hunter/analytics/FirebaseAnalytics.kt +++ b/core/analytics/src/androidMain/kotlin/br/alexandregpereira/hunter/analytics/FirebaseAnalytics.kt @@ -1,6 +1,7 @@ package br.alexandregpereira.hunter.analytics import android.os.Bundle +import android.util.Log import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.crashlytics.FirebaseCrashlytics @@ -24,7 +25,12 @@ internal class FirebaseAnalytics( is Double -> bundle.putDouble(key, value) } } - analytics.logEvent(eventNameNormalized, bundle) + + if (BuildConfig.DEBUG) { + Log.d("FirebaseAnalytics", "event name: $eventNameNormalized. params: $params") + } else { + analytics.logEvent(eventNameNormalized, bundle) + } } override fun logException(throwable: Throwable) { diff --git a/domain/app/data/src/commonMain/kotlin/br/alexandregpereira/hunter/data/database/dao/MonsterDaoImpl.kt b/domain/app/data/src/commonMain/kotlin/br/alexandregpereira/hunter/data/database/dao/MonsterDaoImpl.kt index 45d39c02..1b44e855 100644 --- a/domain/app/data/src/commonMain/kotlin/br/alexandregpereira/hunter/data/database/dao/MonsterDaoImpl.kt +++ b/domain/app/data/src/commonMain/kotlin/br/alexandregpereira/hunter/data/database/dao/MonsterDaoImpl.kt @@ -102,8 +102,8 @@ internal class MonsterDaoImpl( override suspend fun insert(monsters: List, deleteAll: Boolean) = withContext(dispatcher) { monsterQueries.transaction { if (deleteAll) { - monsterQueries.deleteAll() deleteAllEntries(getMonstersByIsNotClone()) + monsterQueries.deleteAll() } else { deleteAllEntries(monsters) } diff --git a/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewState.kt b/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewState.kt index 9998233a..0c9600b3 100644 --- a/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewState.kt +++ b/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewState.kt @@ -28,9 +28,3 @@ internal fun FolderPreviewState.changeMonsters( ): FolderPreviewState { return this.copy(monsters = monsters) } - -internal fun FolderPreviewState.changeShowPreview( - show: Boolean, -): FolderPreviewState { - return this.copy(showPreview = show) -} diff --git a/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewStateHolder.kt b/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewStateHolder.kt index bcc2624d..c9e6c667 100644 --- a/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewStateHolder.kt +++ b/feature/folder-preview/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/folder/preview/FolderPreviewStateHolder.kt @@ -103,11 +103,9 @@ class FolderPreviewStateHolder internal constructor( addMonster(event.index) } is HideFolderPreview -> { - analytics.trackHideFolderPreview() hideFolderPreview() } is ShowFolderPreview -> { - analytics.trackShowFolderPreview() loadMonsters() } } @@ -141,7 +139,9 @@ class FolderPreviewStateHolder internal constructor( val showPreview = monsters.isNotEmpty() _state.value = state.value.changeMonsters(monsters = monsters) .changeShowPreview(showPreview).also { - analytics.trackLoadMonstersResult(it) + if (it.monsters.isNotEmpty() || it.showPreview) { + analytics.trackLoadMonstersResult(it) + } } dispatchFolderPreviewVisibilityChangesEvent() } @@ -162,6 +162,16 @@ class FolderPreviewStateHolder internal constructor( .launchIn(scope) } + private fun FolderPreviewState.changeShowPreview( + show: Boolean, + ): FolderPreviewState { + if (show != showPreview) { + if (show) analytics.trackShowFolderPreview() + else analytics.trackHideFolderPreview() + } + return this.copy(showPreview = show) + } + private fun hideFolderPreview() { _state.value = _state.value.changeShowPreview(show = false) dispatchFolderPreviewVisibilityChangesEvent() diff --git a/feature/settings/android/src/main/java/br/alexandregpereira/hunter/settings/ui/SettingsTextField.kt b/feature/settings/android/src/main/java/br/alexandregpereira/hunter/settings/ui/SettingsTextField.kt index 3dfd19ff..87e936e8 100644 --- a/feature/settings/android/src/main/java/br/alexandregpereira/hunter/settings/ui/SettingsTextField.kt +++ b/feature/settings/android/src/main/java/br/alexandregpereira/hunter/settings/ui/SettingsTextField.kt @@ -37,6 +37,7 @@ fun SettingsTextField( ) = Column(modifier) { AppTextField( text = text, + capitalize = false, onValueChange = onValueChange ) diff --git a/feature/sync/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/sync/SyncStateHolder.kt b/feature/sync/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/sync/SyncStateHolder.kt index a3bc041b..d34095e6 100644 --- a/feature/sync/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/sync/SyncStateHolder.kt +++ b/feature/sync/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/sync/SyncStateHolder.kt @@ -74,9 +74,9 @@ class SyncStateHolder internal constructor( setState { copy(hasError = true) } } .onEach { status -> - analytics.trackSyncStatus(status, forceSync) when (status) { SyncStatus.SYNCED -> { + analytics.trackSyncStatus(status, forceSync) syncEventManager.dispatchEvent(Finished) hide() } @@ -84,6 +84,7 @@ class SyncStateHolder internal constructor( hide() } SyncStatus.BUSY -> { + analytics.trackSyncStatus(status, forceSync) show() } } diff --git a/ui/core/src/main/kotlin/br/alexandregpereira/hunter/ui/compose/AppTextField.kt b/ui/core/src/main/kotlin/br/alexandregpereira/hunter/ui/compose/AppTextField.kt index e932267d..d2b16244 100644 --- a/ui/core/src/main/kotlin/br/alexandregpereira/hunter/ui/compose/AppTextField.kt +++ b/ui/core/src/main/kotlin/br/alexandregpereira/hunter/ui/compose/AppTextField.kt @@ -27,6 +27,7 @@ import androidx.compose.material.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.KeyboardType @Composable @@ -36,9 +37,14 @@ fun AppTextField( label: String = "", keyboardType: AppKeyboardType = AppKeyboardType.TEXT, multiline: Boolean = false, + capitalize: Boolean = true, onValueChange: (String) -> Unit = {} ) { val focusManager = LocalFocusManager.current + val capitalization = if (capitalize) { + KeyboardCapitalization.Sentences + } else KeyboardCapitalization.None + OutlinedTextField( value = text, onValueChange = onValueChange, @@ -55,7 +61,8 @@ fun AppTextField( keyboardType = when (keyboardType) { AppKeyboardType.TEXT -> KeyboardType.Text AppKeyboardType.NUMBER -> KeyboardType.Number - } + }, + capitalization = capitalization, ), keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }) )