Skip to content

Commit

Permalink
Remove GlobalScope usages
Browse files Browse the repository at this point in the history
  • Loading branch information
kamerok committed Aug 25, 2024
1 parent 2b14ea6 commit 9adb612
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/easydone/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.kamer.builder.StartFlow
import com.kamer.builder.WorkScheduler
import com.kamer.easydone.BuildConfig
import kotlinx.coroutines.MainScope
import okhttp3.Interceptor
import timber.log.LogcatTree
import timber.log.Timber


class App : Application(), Configuration.Provider {

private val applicationScope = MainScope()

override fun onCreate() {
super.onCreate()
var debugInterceptor: Interceptor? = null
Expand All @@ -21,8 +24,13 @@ class App : Application(), Configuration.Provider {
Timber.plant(LogcatTree())
}
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
StartFlow.initDependencies(this, BuildConfig.TRELLO_API_KEY, debugInterceptor)
StartFlow.startWidgetUpdates()
StartFlow.initDependencies(
application = this,
applicationScope = applicationScope,
trelloApiKey = BuildConfig.TRELLO_API_KEY,
debugInterceptor = debugInterceptor
)
StartFlow.startWidgetUpdates(applicationScope)
WorkScheduler.schedulePeriodicSync(this)
}

Expand Down
15 changes: 5 additions & 10 deletions builder/src/main/java/com/kamer/builder/StartFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import easydone.library.navigation.Navigator
import easydone.service.trello.TrelloRemoteDataSource
import easydone.service.trello.api.TrelloApi
import easydone.widget.updateWidget
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import okhttp3.Interceptor
Expand Down Expand Up @@ -70,14 +69,15 @@ object StartFlow {

fun initDependencies(
application: Application,
applicationScope: CoroutineScope,
trelloApiKey: String,
debugInterceptor: Interceptor?
) {
val module = module {
single { DomainRepository(get()) }
single<SyncDelegate> { WorkManagerSyncDelegate(get()) }
single { Synchronizer(get(), get()) }
single { SyncScheduler(get(), get()) }
single { SyncScheduler(get(), get(), applicationScope) }
single {
TrelloRemoteDataSource(
api = get(),
Expand Down Expand Up @@ -139,13 +139,12 @@ object StartFlow {
}
}

@OptIn(DelicateCoroutinesApi::class)
fun startWidgetUpdates() {
fun startWidgetUpdates(scope: CoroutineScope) {
val repo = GlobalContext.get().get<DomainRepository>()
val context = GlobalContext.get().get<Context>()
repo.getAllTasks()
.onEach { updateWidget(context) }
.launchIn(GlobalScope)
.launchIn(scope)
}

fun workManagerConfiguration(): Configuration = Configuration.Builder()
Expand All @@ -170,10 +169,6 @@ object StartFlow {
private fun startInitialFlow() {
val navigator: Navigator = GlobalContext.get().get()
navigator.clearStack()
startMainFlow(navigator)
}

private fun startMainFlow(navigator: Navigator) {
navigator.openScreen(MainNavigationFragment::class.java)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package easydone.core.domain

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand All @@ -10,7 +9,7 @@ import kotlinx.coroutines.flow.onEach
class SyncScheduler(
private val localDataSource: LocalDataSource,
private val syncDelegate: SyncDelegate,
scope: CoroutineScope = GlobalScope
scope: CoroutineScope
) {

init {
Expand Down

0 comments on commit 9adb612

Please sign in to comment.