Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdk = 26
targetSdk = 36
versionCode = 5362
versionName = "0.53.62"
versionCode = 5363
versionName = "0.53.63"
ndkVersion = '26.3.11579264'
vectorDrawables.useSupportLibrary = true
}
Expand Down
35 changes: 25 additions & 10 deletions app/src/main/java/org/ole/planet/myplanet/services/UploadManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import java.io.IOException
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import org.ole.planet.myplanet.MainApplication
Expand Down Expand Up @@ -456,16 +461,26 @@ class UploadManager @Inject constructor(
activitiesToUpload.chunked(BATCH_SIZE).forEach { batch ->
val successfulUpdates = mutableMapOf<String, com.google.gson.JsonObject?>()

batch.forEach { activityData ->
try {
val `object` = apiInterface.postDoc(
UrlUtils.header, "application/json",
"${UrlUtils.getUrl()}/login_activities", activityData.serialized
).body()

successfulUpdates[activityData.id] = `object`
} catch (e: java.io.IOException) {
Log.e(TAG, "Exception in UploadManager", e)
val semaphore = Semaphore(6)
coroutineScope {
val deferreds = batch.map { activityData ->
async {
try {
val `object` = semaphore.withPermit {
apiInterface.postDoc(
UrlUtils.header, "application/json",
"${UrlUtils.getUrl()}/login_activities", activityData.serialized
).body()
}
activityData.id to `object`
} catch (e: java.io.IOException) {
Log.e(TAG, "Exception in UploadManager", e)
null
}
}
}
deferreds.awaitAll().filterNotNull().forEach { (id, obj) ->
successfulUpdates[id] = obj
}
}

Expand Down
Loading