Skip to content

Commit

Permalink
Fix: duplicating entries when sync (#232)
Browse files Browse the repository at this point in the history
* Fix: duplicating entries when sync

* Implement capitalization on app text fields

* Adjust analytics
  • Loading branch information
alexandregpereira authored Jan 14, 2024
1 parent bd265bc commit 1438839
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ internal class MonsterDaoImpl(
override suspend fun insert(monsters: List<MonsterCompleteEntity>, deleteAll: Boolean) = withContext(dispatcher) {
monsterQueries.transaction {
if (deleteAll) {
monsterQueries.deleteAll()
deleteAllEntries(getMonstersByIsNotClone())
monsterQueries.deleteAll()
} else {
deleteAllEntries(monsters)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ class FolderPreviewStateHolder internal constructor(
addMonster(event.index)
}
is HideFolderPreview -> {
analytics.trackHideFolderPreview()
hideFolderPreview()
}
is ShowFolderPreview -> {
analytics.trackShowFolderPreview()
loadMonsters()
}
}
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fun SettingsTextField(
) = Column(modifier) {
AppTextField(
text = text,
capitalize = false,
onValueChange = onValueChange
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ 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()
}
SyncStatus.IDLE -> {
hide()
}
SyncStatus.BUSY -> {
analytics.trackSyncStatus(status, forceSync)
show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -55,7 +61,8 @@ fun AppTextField(
keyboardType = when (keyboardType) {
AppKeyboardType.TEXT -> KeyboardType.Text
AppKeyboardType.NUMBER -> KeyboardType.Number
}
},
capitalization = capitalization,
),
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() })
)
Expand Down

0 comments on commit 1438839

Please sign in to comment.