Skip to content

Commit

Permalink
Fix - add delay between API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Melisa69 committed Nov 15, 2022
1 parent 605df0f commit 49bc92a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion sdk/config/gradle/versioning.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext.versions = [

// Main SDK
'sdk': '4.0.13',
'sdk': '4.0.14',

// Build time plugins
'androidgradleplugin': '3.4.2',
Expand Down
79 changes: 41 additions & 38 deletions sdk/src/main/java/me/digi/sdk/Init.kt
Original file line number Diff line number Diff line change
Expand Up @@ -652,53 +652,56 @@ class Init(

DMELog.d("Fetching file list.")
if (activeSyncStatus != FileList.SyncStatus.COMPLETED()) {
readFileList(userAccessToken) { fileList, listFetchError ->
Handler(Looper.getMainLooper()).postDelayed({
readFileList(userAccessToken) { fileList, listFetchError ->

when {
fileList != null -> DMELog.d("File list obtained; Sync syncStatus is ${fileList.syncStatus.rawValue}.")
listFetchError != null -> DMELog.d("Error fetching file list: ${listFetchError.message}.")
}
when {
fileList != null -> DMELog.d("File list obtained; Sync syncStatus is ${fileList.syncStatus.rawValue}.")
listFetchError != null -> DMELog.d("Error fetching file list: ${listFetchError.message}.")
}

val syncStatus = fileList?.syncStatus ?: FileList.SyncStatus.RUNNING()
val syncStatus = fileList?.syncStatus ?: FileList.SyncStatus.RUNNING()

latestFileList = fileList
val updatedFileIds = fileListItemCache?.updateCacheWithItemsAndDeduceChanges(
fileList?.fileList.orEmpty()
).orEmpty()
latestFileList = fileList
val updatedFileIds = fileListItemCache?.updateCacheWithItemsAndDeduceChanges(
fileList?.fileList.orEmpty()
).orEmpty()

DMELog.i(
"${
fileList?.fileList.orEmpty().count()
} files discovered. Of these, ${updatedFileIds.count()} have updates and need downloading."
)

if (updatedFileIds.count() > 0 && fileList != null) {
fileListUpdateHandler?.invoke(fileList, updatedFileIds)
stalePollCount = 0
} else if (++stalePollCount == max(configuration.maxStalePolls, 20)) {
fileListCompletionHandler?.invoke(
fileList,
SDKError.FileListPollingTimeout()
DMELog.i(
"${
fileList?.fileList.orEmpty().count()
} files discovered. Of these, ${updatedFileIds.count()} have updates and need downloading."
)
return@readFileList
}

when (syncStatus) {
FileList.SyncStatus.PENDING(),
FileList.SyncStatus.RUNNING() -> {
DMELog.i("Sync still in progress, continuing to poll for updates.")
scheduleNextPoll(userAccessToken)
if (updatedFileIds.count() > 0 && fileList != null) {
fileListUpdateHandler?.invoke(fileList, updatedFileIds)
stalePollCount = 0
} else if (++stalePollCount == max(configuration.maxStalePolls, 20)) {
fileListCompletionHandler?.invoke(
fileList,
SDKError.FileListPollingTimeout()
)
return@readFileList
}
FileList.SyncStatus.COMPLETED(),
FileList.SyncStatus.PARTIAL() -> fileListCompletionHandler?.invoke(
fileList,
listFetchError
)
else -> Unit

when (syncStatus) {
FileList.SyncStatus.PENDING(),
FileList.SyncStatus.RUNNING() -> {
DMELog.i("Sync still in progress, continuing to poll for updates.")
scheduleNextPoll(userAccessToken)
}
FileList.SyncStatus.COMPLETED(),
FileList.SyncStatus.PARTIAL() -> fileListCompletionHandler?.invoke(
fileList,
listFetchError
)
else -> Unit
}

activeSyncStatus = syncStatus
}

activeSyncStatus = syncStatus
}
}, 1000)
}
}

Expand Down

0 comments on commit 49bc92a

Please sign in to comment.