Skip to content

Commit 44290f1

Browse files
authored
all: smoother service scoping (fixes #9029) (#9007)
1 parent ce2dc10 commit 44290f1

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "org.ole.planet.myplanet"
1010
minSdk = 26
1111
targetSdk = 36
12-
versionCode = 3716
13-
versionName = "0.37.16"
12+
versionCode = 3717
13+
versionName = "0.37.17"
1414
ndkVersion = '26.3.11579264'
1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
vectorDrawables.useSupportLibrary = true

app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import java.util.concurrent.Executors
1515
import javax.inject.Inject
1616
import kotlinx.coroutines.CoroutineScope
1717
import kotlinx.coroutines.Dispatchers
18-
import kotlinx.coroutines.SupervisorJob
1918
import kotlinx.coroutines.launch
2019
import kotlinx.coroutines.withContext
2120
import okhttp3.ResponseBody
@@ -25,6 +24,8 @@ import org.ole.planet.myplanet.R
2524
import org.ole.planet.myplanet.callback.SecurityDataCallback
2625
import org.ole.planet.myplanet.callback.SuccessListener
2726
import org.ole.planet.myplanet.di.ApiInterfaceEntryPoint
27+
import org.ole.planet.myplanet.di.ApplicationScope
28+
import org.ole.planet.myplanet.di.ApplicationScopeEntryPoint
2829
import org.ole.planet.myplanet.di.AutoSyncEntryPoint
2930
import org.ole.planet.myplanet.model.MyPlanet
3031
import org.ole.planet.myplanet.model.RealmCommunity
@@ -52,19 +53,25 @@ import retrofit2.Response
5253

5354
class Service @Inject constructor(
5455
private val context: Context,
55-
private val retrofitInterface: ApiInterface
56+
private val retrofitInterface: ApiInterface,
57+
@ApplicationScope private val serviceScope: CoroutineScope,
5658
) {
5759
constructor(context: Context) : this(
5860
context,
5961
EntryPointAccessors.fromApplication(
6062
context.applicationContext,
6163
ApiInterfaceEntryPoint::class.java
62-
).apiInterface()
64+
).apiInterface(),
65+
EntryPointAccessors.fromApplication(
66+
context.applicationContext,
67+
ApplicationScopeEntryPoint::class.java
68+
).applicationScope(),
6369
)
70+
6471
private val preferences: SharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
65-
private val serviceScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
6672
private val serverAvailabilityCache = ConcurrentHashMap<String, Pair<Boolean, Long>>()
67-
private val configurationManager = ConfigurationManager(context, preferences, retrofitInterface)
73+
private val configurationManager =
74+
ConfigurationManager(context, preferences, retrofitInterface)
6875
private fun getUploadToShelfService(): UploadToShelfService {
6976
val entryPoint = EntryPointAccessors.fromApplication(
7077
context.applicationContext,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.ole.planet.myplanet.di
2+
3+
import dagger.hilt.EntryPoint
4+
import dagger.hilt.InstallIn
5+
import dagger.hilt.components.SingletonComponent
6+
import kotlinx.coroutines.CoroutineScope
7+
8+
@EntryPoint
9+
@InstallIn(SingletonComponent::class)
10+
interface ApplicationScopeEntryPoint {
11+
@ApplicationScope
12+
fun applicationScope(): CoroutineScope
13+
}

0 commit comments

Comments
 (0)