Skip to content

Commit

Permalink
resources: smoother downloads (fixes #5012) (#5014)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Jan 13, 2025
1 parent d0be8f8 commit 3ac0e07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2193
versionName "0.21.93"
versionCode 2194
versionName "0.21.94"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.realm.Realm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.ResponseBody
import org.ole.planet.myplanet.model.Download
import org.ole.planet.myplanet.model.RealmMyLibrary
Expand All @@ -23,7 +22,6 @@ import org.ole.planet.myplanet.utilities.FileUtils.getSDPathFromUrl
import org.ole.planet.myplanet.utilities.Utilities.header
import retrofit2.Call
import java.io.*
import kotlin.math.pow
import kotlin.math.roundToInt

class MyDownloadService : Service() {
Expand Down Expand Up @@ -218,16 +216,20 @@ class MyDownloadService : Service() {
CoroutineScope(Dispatchers.IO).launch {
if (urls.isNotEmpty() && currentIndex >= 0 && currentIndex < urls.size) {
val currentFileName = getFileNameFromUrl(urls[currentIndex])
withContext(Dispatchers.Main) {
mRealm.executeTransaction { realm ->
realm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", currentFileName)
.findAll()
?.forEach {
it.resourceOffline = true
it.downloadedRev = it._rev
}
try {
val backgroundRealm = Realm.getDefaultInstance()
backgroundRealm.use { realm ->
realm.executeTransaction {
realm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", currentFileName).findAll()
?.forEach {
it.resourceOffline = true
it.downloadedRev = it._rev
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Expand Down

0 comments on commit 3ac0e07

Please sign in to comment.