Skip to content

Commit 3613ea7

Browse files
committed
feat: [ANDROAPP-7370] Support 6 and 12 hours metadata sync
1 parent 165951d commit 3613ea7

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

app/src/main/java/org/dhis2/usescases/settings/SettingsRepository.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ class SettingsRepository(
4949
null
5050
}
5151
private val programSettings: ProgramSettings?
52-
get() =
53-
if (d2.settingModule().programSetting().blockingExists()) {
54-
d2.settingModule().programSetting().blockingGet()
55-
} else {
56-
null
57-
}
52+
get() = syncSettings?.programSettings()
5853
private val smsConfig: ConfigCase.SmsConfig
5954
get() =
6055
d2
@@ -179,13 +174,13 @@ class SettingsRepository(
179174
.isNotEmpty()
180175

181176
private fun metadataPeriod(): Int =
182-
generalSettings?.metadataSync()?.toSeconds() ?: prefs.getInt(
177+
syncSettings?.metadataSync()?.toSeconds() ?: prefs.getInt(
183178
Preference.TIME_META,
184179
TIME_WEEKLY,
185180
)
186181

187182
private fun dataPeriod(): Int =
188-
generalSettings?.dataSync()?.toSeconds() ?: prefs.getInt(
183+
syncSettings?.dataSync()?.toSeconds() ?: prefs.getInt(
189184
Preference.TIME_DATA,
190185
TIME_DAILY,
191186
)
@@ -231,14 +226,11 @@ class SettingsRepository(
231226
private fun getLimitedScopeFromPreferences(): LimitScope {
232227
val byOrgUnit = prefs.getBoolean(Constants.LIMIT_BY_ORG_UNIT, false)
233228
val byProgram = prefs.getBoolean(Constants.LIMIT_BY_PROGRAM, false)
234-
return if (byOrgUnit && !byProgram) {
235-
LimitScope.PER_ORG_UNIT
236-
} else if (!byOrgUnit && byProgram) {
237-
LimitScope.PER_PROGRAM
238-
} else if (byOrgUnit && byProgram) {
239-
LimitScope.PER_OU_AND_PROGRAM
240-
} else {
241-
LimitScope.GLOBAL
229+
return when {
230+
byOrgUnit && byProgram -> LimitScope.PER_OU_AND_PROGRAM
231+
byOrgUnit && !byProgram -> LimitScope.PER_ORG_UNIT
232+
!byOrgUnit && byProgram -> LimitScope.PER_PROGRAM
233+
else -> LimitScope.GLOBAL
242234
}
243235
}
244236

@@ -253,6 +245,7 @@ class SettingsRepository(
253245
suspend fun saveLimitScope(limitScope: LimitScope) {
254246
when (limitScope) {
255247
LimitScope.ALL_ORG_UNITS -> {
248+
// Do nothing
256249
}
257250

258251
LimitScope.GLOBAL -> {
@@ -289,7 +282,7 @@ class SettingsRepository(
289282
.setGatewayNumber(gatewayNumber)
290283
.blockingAwait()
291284
} catch (e: Exception) {
292-
Timber.d(e.message)
285+
Timber.d(e)
293286
}
294287
}
295288

app/src/main/java/org/dhis2/usescases/settings/ui/SyncMetadataSettingItem.kt

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dhis2.usescases.settings.ui
22

33
import android.content.Context
4+
import androidx.annotation.StringRes
45
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
56
import androidx.compose.foundation.layout.Column
67
import androidx.compose.foundation.layout.fillMaxWidth
@@ -21,9 +22,11 @@ import androidx.compose.ui.text.capitalize
2122
import androidx.compose.ui.text.intl.Locale
2223
import androidx.compose.ui.unit.dp
2324
import org.dhis2.R
25+
import org.dhis2.bindings.EVERY_12_HOUR
2426
import org.dhis2.bindings.EVERY_24_HOUR
27+
import org.dhis2.bindings.EVERY_6_HOUR
2528
import org.dhis2.bindings.EVERY_7_DAYS
26-
import org.dhis2.commons.Constants
29+
import org.dhis2.commons.Constants.TIME_MANUAL
2730
import org.dhis2.usescases.settings.SettingItem
2831
import org.dhis2.usescases.settings.models.MetadataSettingsViewModel
2932
import org.hisp.dhis.mobile.ui.designsystem.component.AdditionalInfoItem
@@ -77,11 +80,18 @@ internal fun SyncMetadataSettingItem(
7780
if (metadataSettings.canEdit) {
7881
val metaSyncPeriods =
7982
listOf(
80-
stringResource(R.string.a_day),
81-
stringResource(R.string.a_week),
82-
stringResource(R.string.Manual),
83+
SyncMetadataPeriods.Every6Hours,
84+
SyncMetadataPeriods.Every12Hours,
85+
SyncMetadataPeriods.Every24Hours,
86+
SyncMetadataPeriods.EveryWeek,
87+
SyncMetadataPeriods.Manual,
8388
)
8489

90+
val dropdownItemLabel =
91+
metaSyncPeriods.map {
92+
stringResource(it.label)
93+
}
94+
8595
var selectedItem by
8696
remember {
8797
mutableStateOf(
@@ -101,21 +111,14 @@ internal fun SyncMetadataSettingItem(
101111
itemCount = metaSyncPeriods.size,
102112
onSearchOption = {},
103113
fetchItem = { index ->
104-
DropdownItem(metaSyncPeriods[index])
114+
DropdownItem(dropdownItemLabel[index])
105115
},
106116
selectedItem = selectedItem,
107117
onResetButtonClicked = { },
108118
onItemSelected = { index, newItem ->
109119
selectedItem = newItem
110120
inputSyncConfigurationState = InputShellState.UNFOCUSED
111-
when (index) {
112-
0 -> onSyncMetaPeriodChanged(EVERY_24_HOUR)
113-
1 -> onSyncMetaPeriodChanged(EVERY_7_DAYS)
114-
2 -> onSyncMetaPeriodChanged(Constants.TIME_MANUAL)
115-
else -> {
116-
// do nothing
117-
}
118-
}
121+
onSyncMetaPeriodChanged(metaSyncPeriods[index].syncPeriod)
119122
},
120123
showSearchBar = false,
121124
loadOptions = {},
@@ -193,3 +196,18 @@ private fun provideSyncInProgressInfoItems(
193196
isConstantItem = true,
194197
),
195198
)
199+
200+
internal sealed class SyncMetadataPeriods(
201+
@StringRes val label: Int,
202+
val syncPeriod: Int,
203+
) {
204+
data object Every24Hours : SyncMetadataPeriods(R.string.a_day, EVERY_24_HOUR)
205+
206+
data object Every12Hours : SyncMetadataPeriods(R.string.every_12_hours, EVERY_12_HOUR)
207+
208+
data object Every6Hours : SyncMetadataPeriods(R.string.every_6_hours, EVERY_6_HOUR)
209+
210+
data object EveryWeek : SyncMetadataPeriods(R.string.a_week, EVERY_7_DAYS)
211+
212+
data object Manual : SyncMetadataPeriods(R.string.Manual, TIME_MANUAL)
213+
}

gradle/verification-metadata.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11530,8 +11530,16 @@
1153011530
</artifact>
1153111531
</component>
1153211532
<component group="org.jetbrains.kotlin" name="kotlin-stdlib" version="1.9.21">
11533+
<artifact name="kotlin-stdlib-1.9.21-all.jar">
11534+
<sha256 value="cec38bc3302e72a8aaf9cde436b5a9071ee0331e2ad05e84d8bb897334d7e9d4"
11535+
origin="Generated by Gradle" />
11536+
</artifact>
1153311537
<artifact name="kotlin-stdlib-1.9.21.jar">
1153411538
<sha256 value="3b479313ab6caea4e5e25d3dee8ca80c302c89ba73e1af4dafaa100f6ef9296a" origin="Generated by Gradle"/>
11539+
</artifact>
11540+
<artifact name="kotlin-stdlib-1.9.21.module">
11541+
<sha256 value="d3019f7f0d71924ce47298c9cc46af0245f75219719b35c5915fbcc7e7a69395"
11542+
origin="Generated by Gradle" />
1153511543
</artifact>
1153611544
<artifact name="kotlin-stdlib-1.9.21.pom">
1153711545
<sha256 value="c807d92f7c6aa1b65c06cf87232363504e690fca3f3c1e27206630a1322fd7e0" origin="Generated by Gradle"/>

0 commit comments

Comments
 (0)