Skip to content

Commit bee7811

Browse files
committed
refactor: use if guards
1 parent 446ee64 commit bee7811

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

app/src/main/java/to/bitkit/repositories/BackupRepo.kt

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ class BackupRepo @Inject constructor(
128128
.distinctUntilChanged()
129129
.drop(1)
130130
.collect {
131-
if (!isRestoring) {
132-
markBackupRequired(BackupCategory.SETTINGS)
133-
}
131+
if (isRestoring) return@collect
132+
markBackupRequired(BackupCategory.SETTINGS)
134133
}
135134
}
136135
dataListenerJobs.add(settingsJob)
@@ -140,9 +139,8 @@ class BackupRepo @Inject constructor(
140139
.distinctUntilChanged()
141140
.drop(1)
142141
.collect {
143-
if (!isRestoring) {
144-
markBackupRequired(BackupCategory.WIDGETS)
145-
}
142+
if (isRestoring) return@collect
143+
markBackupRequired(BackupCategory.WIDGETS)
146144
}
147145
}
148146
dataListenerJobs.add(widgetsJob)
@@ -153,9 +151,8 @@ class BackupRepo @Inject constructor(
153151
.distinctUntilChanged()
154152
.drop(1)
155153
.collect {
156-
if (!isRestoring) {
157-
markBackupRequired(BackupCategory.WALLET)
158-
}
154+
if (isRestoring) return@collect
155+
markBackupRequired(BackupCategory.WALLET)
159156
}
160157
}
161158
dataListenerJobs.add(transfersJob)
@@ -166,9 +163,8 @@ class BackupRepo @Inject constructor(
166163
.distinctUntilChanged()
167164
.drop(1)
168165
.collect {
169-
if (!isRestoring) {
170-
markBackupRequired(BackupCategory.METADATA)
171-
}
166+
if (isRestoring) return@collect
167+
markBackupRequired(BackupCategory.METADATA)
172168
}
173169
}
174170
dataListenerJobs.add(tagMetadataJob)
@@ -179,9 +175,8 @@ class BackupRepo @Inject constructor(
179175
.distinctUntilChanged()
180176
.drop(1)
181177
.collect {
182-
if (!isRestoring) {
183-
markBackupRequired(BackupCategory.METADATA)
184-
}
178+
if (isRestoring) return@collect
179+
markBackupRequired(BackupCategory.METADATA)
185180
}
186181
}
187182
dataListenerJobs.add(cacheMetadataJob)
@@ -191,9 +186,8 @@ class BackupRepo @Inject constructor(
191186
blocktankRepo.blocktankState
192187
.drop(1)
193188
.collect {
194-
if (!isRestoring) {
195-
markBackupRequired(BackupCategory.BLOCKTANK)
196-
}
189+
if (isRestoring) return@collect
190+
markBackupRequired(BackupCategory.BLOCKTANK)
197191
}
198192
}
199193
dataListenerJobs.add(blocktankJob)
@@ -203,9 +197,8 @@ class BackupRepo @Inject constructor(
203197
activityRepo.activitiesChanged
204198
.drop(1)
205199
.collect {
206-
if (!isRestoring) {
207-
markBackupRequired(BackupCategory.ACTIVITY)
208-
}
200+
if (isRestoring) return@collect
201+
markBackupRequired(BackupCategory.ACTIVITY)
209202
}
210203
}
211204
dataListenerJobs.add(activityChangesJob)
@@ -217,10 +210,9 @@ class BackupRepo @Inject constructor(
217210
val lastSync = lightningService.status?.latestLightningWalletSyncTimestamp?.toLong()
218211
?.let { it * 1000 } // Convert seconds to millis
219212
?: return@collect
220-
if (!isRestoring) {
221-
cacheStore.updateBackupStatus(BackupCategory.LIGHTNING_CONNECTIONS) {
222-
it.copy(required = lastSync, synced = lastSync, running = false)
223-
}
213+
if (isRestoring) return@collect
214+
cacheStore.updateBackupStatus(BackupCategory.LIGHTNING_CONNECTIONS) {
215+
it.copy(required = lastSync, synced = lastSync, running = false)
224216
}
225217
}
226218
}

0 commit comments

Comments
 (0)