Skip to content

Commit 366513c

Browse files
committed
fix(auto-upload): calls
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 884fd5e commit 366513c

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import com.owncloud.android.operations.DownloadType
4343
import kotlinx.coroutines.CoroutineScope
4444
import kotlinx.coroutines.Dispatchers
4545
import kotlinx.coroutines.launch
46+
import java.time.Duration
4647
import java.util.Date
4748
import java.util.UUID
4849
import java.util.concurrent.TimeUnit
@@ -267,19 +268,22 @@ internal class BackgroundJobManagerImpl(
267268
return workInfo.map { it -> it.map { fromWorkInfo(it) ?: JobInfo() }.sortedBy { it.started }.reversed() }
268269
}
269270

271+
@Suppress("MagicNumber")
270272
override fun scheduleContentObserverJob() {
271273
val constrains = Constraints.Builder()
272274
.addContentUriTrigger(MediaStore.Images.Media.INTERNAL_CONTENT_URI, true)
273275
.addContentUriTrigger(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true)
274276
.addContentUriTrigger(MediaStore.Video.Media.INTERNAL_CONTENT_URI, true)
275277
.addContentUriTrigger(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true)
278+
.setTriggerContentUpdateDelay(Duration.ofSeconds(5))
279+
.setTriggerContentUpdateDelay(Duration.ofSeconds(10))
276280
.build()
277281

278-
val request = periodicRequestBuilder(ContentObserverWork::class, JOB_CONTENT_OBSERVER)
282+
val request = oneTimeRequestBuilder(ContentObserverWork::class, JOB_CONTENT_OBSERVER)
279283
.setConstraints(constrains)
280284
.build()
281285

282-
workManager.enqueueUniquePeriodicWork(JOB_CONTENT_OBSERVER, ExistingPeriodicWorkPolicy.KEEP, request)
286+
workManager.enqueueUniqueWork(JOB_CONTENT_OBSERVER, ExistingWorkPolicy.REPLACE, request)
283287
}
284288

285289
override fun schedulePeriodicContactsBackup(user: User) {

app/src/main/java/com/nextcloud/client/jobs/ContentObserverWork.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class ContentObserverWork(
6363
} catch (e: Exception) {
6464
Log_OC.e(TAG, "❌ Exception in ContentObserverWork: ${e.message}", e)
6565
Result.retry()
66+
} finally {
67+
Log_OC.d(TAG, "🔄" + "re-scheduling job")
68+
backgroundJobManager.scheduleContentObserverJob()
6669
}
6770
}
6871

0 commit comments

Comments
 (0)