Skip to content

Commit

Permalink
Move app state keys to one place
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Jul 12, 2024
1 parent fe3932f commit 91be0f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.odk.collect.android.formmanagement.download.ServerFormDownloader
import org.odk.collect.android.formmanagement.matchexactly.ServerFormsSynchronizer
import org.odk.collect.android.notifications.Notifier
import org.odk.collect.android.projects.ProjectDependencyModule
import org.odk.collect.android.state.DataKeys
import org.odk.collect.androidshared.data.AppState
import org.odk.collect.androidshared.data.getData
import org.odk.collect.forms.Form
Expand All @@ -25,10 +26,10 @@ class FormsDataService(
private val clock: Supplier<Long>
) {

private val forms = appState.getData("forms", emptyList<Form>())
private val syncing = appState.getData("syncStatusSyncing", false)
private val serverError = appState.getData<FormSourceException?>("syncStatusError", null)
private val diskError = appState.getData<String?>("diskError", null)
private val forms = appState.getData(DataKeys.FORMS, emptyList<Form>())
private val syncing = appState.getData(DataKeys.SYNC_STATUS_SYNCING, false)
private val serverError = appState.getData<FormSourceException?>(DataKeys.SYNC_STATUS_ERROR, null)
private val diskError = appState.getData<String?>(DataKeys.DISK_ERROR, null)

fun getForms(projectId: String): Flow<List<Form>> {
return forms.get(projectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.odk.collect.android.instancemanagement.autosend.getAutoSendMode
import org.odk.collect.android.notifications.Notifier
import org.odk.collect.android.openrosa.OpenRosaHttpInterface
import org.odk.collect.android.projects.ProjectDependencyModule
import org.odk.collect.android.state.DataKeys
import org.odk.collect.android.utilities.ExternalizableFormDefCache
import org.odk.collect.android.utilities.FormsUploadResultInterpreter
import org.odk.collect.androidshared.data.AppState
Expand All @@ -35,16 +36,16 @@ class InstancesDataService(
private val onUpdate: () -> Unit
) {

private val _editableCount = appState.getData("instancesEditableCount", 0)
private val _editableCount = appState.getData(DataKeys.INSTANCES_EDITABLE_COUNT, 0)
val editableCount: LiveData<Int> = _editableCount.get().asLiveData()

private val _sendableCount = appState.getData("instancesSendableCount", 0)
private val _sendableCount = appState.getData(DataKeys.INSTANCES_SENDABLE_COUNT, 0)
val sendableCount: LiveData<Int> = _sendableCount.get().asLiveData()

private val _sentCount = appState.getData("instancesSentCount", 0)
private val _sentCount = appState.getData(DataKeys.INSTANCES_SENT_COUNT, 0)
val sentCount: LiveData<Int> = _sentCount.get().asLiveData()

private val instances = appState.getData<List<Instance>>("instances", emptyList())
private val instances = appState.getData<List<Instance>>(DataKeys.INSTANCES, emptyList())

fun getInstances(projectId: String): Flow<List<Instance>> {
return instances.get(projectId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.odk.collect.android.state

object DataKeys {
const val INSTANCES_EDITABLE_COUNT = "instancesEditableCount"
const val INSTANCES_SENDABLE_COUNT = "instancesSendableCount"
const val INSTANCES_SENT_COUNT = "instancesSentCount"
const val INSTANCES = "instances"

const val FORMS = "forms"
const val SYNC_STATUS_SYNCING = "syncStatusSyncing"
const val SYNC_STATUS_ERROR = "syncStatusError"
const val DISK_ERROR = "diskError"
}

0 comments on commit 91be0f1

Please sign in to comment.