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
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.ccci.gto.android.common.sync.SyncTracker
import org.ccci.gto.android.common.sync.rememberSyncTask
import org.ccci.gto.android.common.sync.rememberSyncTaskRegistry
import org.cru.godtools.base.ui.circuit.screen.dashboard.DashboardScreen
import org.cru.godtools.base.ui.circuit.screen.dashboard.page.DashboardPage
import org.cru.godtools.base.ui.circuit.screen.dashboard.page.HomeScreen
import org.cru.godtools.sync.GodToolsSyncService
import org.cru.godtools.ui.dashboard.DashboardPresenter.UiState
import org.cru.godtools.ui.dashboard.SyncTaskRegistry.Companion.rememberSyncRegistry
import org.cru.godtools.ui.dashboard.SyncTaskRegistry.Companion.syncTaskRegistry
import org.cru.godtools.ui.drawer.DrawerMenuPresenter
import org.cru.godtools.ui.drawer.DrawerMenuScreen

Expand All @@ -53,16 +53,8 @@ class DashboardPresenter @AssistedInject internal constructor(

@Composable
override fun present(): UiState {
val syncRegistry = rememberSyncRegistry()
DisposableEffect(syncRegistry) {
circuitContext.syncTaskRegistry = syncRegistry
val id = syncRegistry.registerSyncTask { syncData(it) }

onDispose {
circuitContext.syncTaskRegistry = null
syncRegistry.unregisterSyncTask(id)
}
}
val syncRegistry = circuitContext.rememberSyncTaskRegistry()
syncRegistry.rememberSyncTask { syncData(it) }

return UiState(
drawerState = drawerMenuPresenter.present(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.cru.godtools.ui.dashboard.lessons

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -39,6 +38,7 @@ import kotlinx.coroutines.flow.map
import org.ccci.gto.android.common.dagger.coroutines.DispatcherType
import org.ccci.gto.android.common.dagger.coroutines.DispatcherType.Type.IO
import org.ccci.gto.android.common.sync.SyncTracker
import org.ccci.gto.android.common.sync.rememberSyncTask
import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent
import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.ACTION_OPEN_LESSON
import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.SOURCE_LESSONS
Expand All @@ -51,7 +51,6 @@ import org.cru.godtools.db.repository.TranslationsRepository
import org.cru.godtools.model.Language
import org.cru.godtools.model.Language.Companion.filterByDisplayAndNativeName
import org.cru.godtools.sync.GodToolsSyncService
import org.cru.godtools.ui.dashboard.SyncTaskRegistry.Companion.syncTaskRegistry
import org.cru.godtools.ui.dashboard.filters.FilterMenu
import org.cru.godtools.ui.dashboard.lessons.LessonsPresenter.UiState
import org.cru.godtools.ui.settings.country.CountrySettingsScreen
Expand Down Expand Up @@ -219,12 +218,7 @@ class LessonsPresenter @AssistedInject internal constructor(

@Composable
private fun RegisterSyncTask(locale: Locale) {
val syncRegistry = circuitContext.syncTaskRegistry
DisposableEffect(syncRegistry, locale) {
if (syncRegistry == null) return@DisposableEffect onDispose { }
val id = syncRegistry.registerSyncTask { force -> syncData(locale, force) }
onDispose { syncRegistry.unregisterSyncTask(id) }
}
circuitContext.rememberSyncTask(locale) { syncData(locale, it) }
}

private fun SyncTracker.syncData(locale: Locale, force: Boolean = false) = launchSync {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cru.godtools.ui.dashboard.tools

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
Expand All @@ -26,6 +25,7 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.ccci.gto.android.common.sync.SyncTracker
import org.ccci.gto.android.common.sync.rememberSyncTask
import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent
import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.ACTION_OPEN_TOOL_DETAILS
import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.SOURCE_ALL_TOOLS
Expand All @@ -39,7 +39,6 @@ import org.cru.godtools.sync.GodToolsSyncService
import org.cru.godtools.ui.banner.Banner
import org.cru.godtools.ui.banner.BannerPresenter
import org.cru.godtools.ui.banner.favoritetools.FavoriteToolsBannerPresenter
import org.cru.godtools.ui.dashboard.SyncTaskRegistry.Companion.syncTaskRegistry
import org.cru.godtools.ui.dashboard.tools.ToolFiltersStateProducer.Filters
import org.cru.godtools.ui.dashboard.tools.ToolsPresenter.UiState
import org.cru.godtools.ui.dashboard.tools.ToolsPresenter.UiState.Mode
Expand Down Expand Up @@ -95,7 +94,8 @@ class ToolsPresenter @AssistedInject internal constructor(
val filters = toolFiltersStateProducer.produce(mode)
val selectedLocale by rememberUpdatedState(filters.languageFilter.selectedItem?.code)

RegisterSyncTask(selectedLocale)
val appLocale by settings.appLanguageFlow.collectAsState()
RegisterSyncTask(selectedLocale ?: appLocale)

val featuredTools = rememberFeaturedTools(
mode = mode,
Expand Down Expand Up @@ -128,13 +128,8 @@ class ToolsPresenter @AssistedInject internal constructor(
}

@Composable
private fun RegisterSyncTask(selectedLocale: Locale?) {
val syncRegistry = circuitContext.syncTaskRegistry
DisposableEffect(syncRegistry, selectedLocale) {
if (syncRegistry == null) return@DisposableEffect onDispose { }
val id = syncRegistry.registerSyncTask { force -> syncData(selectedLocale ?: settings.appLanguage, force) }
onDispose { syncRegistry.unregisterSyncTask(id) }
}
private fun RegisterSyncTask(locale: Locale) {
circuitContext.rememberSyncTask(locale) { syncData(locale, it) }
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.test.runTest
import org.ccci.gto.android.common.androidx.compose.ui.platform.AndroidUiDispatcherUtil
import org.ccci.gto.android.common.sync.SyncTaskRegistry
import org.ccci.gto.support.turbine.awaitItemMatching
import org.cru.godtools.base.ui.circuit.screen.dashboard.DashboardScreen
import org.cru.godtools.base.ui.circuit.screen.dashboard.page.HomeScreen
import org.cru.godtools.base.ui.circuit.screen.dashboard.page.LessonsScreen
import org.cru.godtools.sync.GodToolsSyncService
import org.cru.godtools.ui.dashboard.DashboardPresenter.UiEvent
import org.cru.godtools.ui.dashboard.DashboardPresenter.UiState
import org.cru.godtools.ui.dashboard.SyncTaskRegistry.Companion.syncTaskRegistry
import org.cru.godtools.ui.drawer.DrawerMenuPresenter
import org.cru.godtools.ui.drawer.DrawerMenuScreen
import org.cru.godtools.ui.tooldetails.ToolDetailsScreen
Expand Down Expand Up @@ -152,12 +152,12 @@ class DashboardPresenterTest {
// region SideEffect - SyncTaskRegistry
@Test
fun `SideEffect - SyncTaskRegistry - set on CircuitContext while presenter is active`() = runTest {
assertNull(circuitContext.syncTaskRegistry)
assertNull(circuitContext.tag<SyncTaskRegistry>())
presenter.test {
awaitInitialState()
assertNotNull(circuitContext.syncTaskRegistry)
assertNotNull(circuitContext.tag<SyncTaskRegistry>())
}
assertNull(circuitContext.syncTaskRegistry)
assertNull(circuitContext.tag<SyncTaskRegistry>())
}
// endregion SideEffect - SyncTaskRegistry

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.ccci.gto.android.common.androidx.compose.ui.platform.AndroidUiDispatcherUtil
import org.ccci.gto.android.common.sync.SyncTaskRegistry
import org.ccci.gto.android.common.sync.SyncTracker
import org.ccci.gto.android.common.util.content.equalsIntent
import org.ccci.gto.support.turbine.awaitItemMatching
Expand All @@ -58,8 +59,6 @@ import org.cru.godtools.model.Translation
import org.cru.godtools.model.randomTool
import org.cru.godtools.model.randomTranslation
import org.cru.godtools.sync.GodToolsSyncService
import org.cru.godtools.ui.dashboard.SyncTaskRegistry
import org.cru.godtools.ui.dashboard.SyncTaskRegistry.Companion.syncTaskRegistry
import org.cru.godtools.ui.dashboard.filters.FilterMenu
import org.cru.godtools.ui.dashboard.lessons.LessonsPresenter.UiEvent
import org.cru.godtools.ui.dashboard.lessons.LessonsPresenter.UiState
Expand All @@ -85,10 +84,6 @@ class LessonsPresenterTest {
private var isPersonalizationEnabled = true

private val testScope = TestScope()
@OptIn(InternalCircuitApi::class)
private val circuitContext = CircuitContext(null).apply {
syncTaskRegistry = SyncTaskRegistry(SyncTracker(testScope.backgroundScope))
}
private val context: Context = ApplicationProvider.getApplicationContext()
private val eventBus: EventBus = mockk(relaxUnitFun = true)
private val remoteConfig: FirebaseRemoteConfig = mockk {
Expand All @@ -105,6 +100,7 @@ class LessonsPresenterTest {
private val syncService: GodToolsSyncService = mockk {
coEvery { syncToolOrder(any(), any(), any()) } coAnswers { toolOrderSync.receive() }
}
private val syncTaskRegistry = SyncTaskRegistry(SyncTracker(testScope.backgroundScope))
private val lessonsFlowProducer: LessonsFlowProducer = mockk {
every { getFlow(any(), any()) } returns flowOf(emptyList())
every { getFlow(any(), Locale.ENGLISH) } returns enLessonsFlow
Expand All @@ -117,6 +113,8 @@ class LessonsPresenterTest {
}

private val backStack = SaveableBackStack(LessonsScreen)
@OptIn(InternalCircuitApi::class)
private val circuitContext = CircuitContext(null).apply { putTag(syncTaskRegistry) }
private val navigator = FakeNavigator(backStack)

private val presenter = LessonsPresenter(
Expand Down Expand Up @@ -475,7 +473,7 @@ class LessonsPresenterTest {
toolOrderSync.send(true)
coVerify { syncService.syncToolOrder(Locale.ENGLISH, "US", false) }

circuitContext.syncTaskRegistry!!.triggerSyncTasks(force = true)
syncTaskRegistry.triggerSyncTasks(force = true)
toolOrderSync.send(true)
coVerify { syncService.syncToolOrder(Locale.ENGLISH, "US", true) }
}
Expand Down
Loading