Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: duplicating entries when sync #232

Merged
merged 4 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading