diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenter.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenter.kt index b57dea80eb..dfdd1c6ddb 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenter.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenter.kt @@ -64,6 +64,7 @@ class AllFavoritesPresenter @AssistedInject constructor( tool.primaryLocale ?: state.translation?.languageCode, tool.parallelLocale ), + saveLanguageSettings = true ) if (intent != null) { diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt index d8dbe6caed..604e2e5b52 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt @@ -124,6 +124,7 @@ class HomePresenter @AssistedInject constructor( tool.primaryLocale ?: state.translation?.languageCode, tool.parallelLocale ), + saveLanguageSettings = true ) if (intent != null) { diff --git a/app/src/main/kotlin/org/cru/godtools/util/ActivityUtils.kt b/app/src/main/kotlin/org/cru/godtools/util/ActivityUtils.kt index f65256ac41..4e4d6923bd 100644 --- a/app/src/main/kotlin/org/cru/godtools/util/ActivityUtils.kt +++ b/app/src/main/kotlin/org/cru/godtools/util/ActivityUtils.kt @@ -28,16 +28,22 @@ fun Tool.createToolIntent( languages: List, activeLocale: Locale? = null, showTips: Boolean = false, + saveLanguageSettings: Boolean = false, ) = code?.let { code -> when (type) { Type.TRACT -> context.createTractActivityIntent( code, *languages.toTypedArray(), activeLocale = activeLocale, - showTips = showTips + showTips = showTips, + saveLanguageSettings = saveLanguageSettings, ) Type.ARTICLE -> context.createArticlesIntent(code, languages[0]) - Type.CYOA -> context.createCyoaActivityIntent(code, *languages.toTypedArray()) + Type.CYOA -> context.createCyoaActivityIntent( + code, + *languages.toTypedArray(), + saveLanguageSettings = saveLanguageSettings + ) Type.LESSON -> context.createLessonActivityIntent(code, languages[0]) Type.META, Type.UNKNOWN -> null } diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenterTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenterTest.kt index 217cfaf9cc..f5243ae65d 100644 --- a/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenterTest.kt +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesPresenterTest.kt @@ -157,10 +157,12 @@ class AllFavoritesPresenterTest { presenter.test { expectMostRecentItem().tools[0].eventSink(ToolCard.Event.Click) - assertTrue { - assertIs(navigator.awaitNextScreen()).intent - .equalsIntent(tool.createToolIntent(context, languages = listOf(Locale.ENGLISH))) - } + val expected = tool.createToolIntent( + context, + languages = listOf(Locale.ENGLISH), + saveLanguageSettings = true + ) + assertTrue(assertIs(navigator.awaitNextScreen()).intent equalsIntent expected) } verifyAll { eventBus.post(OpenAnalyticsActionEvent(ACTION_OPEN_TOOL, tool.code, SOURCE_FAVORITE)) } @@ -181,10 +183,12 @@ class AllFavoritesPresenterTest { presenter.test { expectMostRecentItem().tools[0].eventSink(ToolCard.Event.Click) - assertTrue { - assertIs(navigator.awaitNextScreen()).intent - .equalsIntent(tool.createToolIntent(context, languages = listOf(Locale.FRENCH, Locale.GERMAN))) - } + val expected = tool.createToolIntent( + context, + languages = listOf(Locale.FRENCH, Locale.GERMAN), + saveLanguageSettings = true + ) + assertTrue(assertIs(navigator.awaitNextScreen()).intent equalsIntent expected) } verifyAll { eventBus.post(OpenAnalyticsActionEvent(ACTION_OPEN_TOOL, tool.code, SOURCE_FAVORITE)) } diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenterTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenterTest.kt index 9bc503d3c5..2daef6ca46 100644 --- a/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenterTest.kt +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenterTest.kt @@ -215,10 +215,12 @@ class HomePresenterTest { assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState -> toolState.eventSink(ToolCard.Event.Click) - assertIs(navigator.awaitNextScreen()).let { screen -> - val expected = tool.createToolIntent(context, listOf(toolState.translation!!.languageCode)) - assertTrue(expected equalsIntent screen.intent) - } + val expected = tool.createToolIntent( + context, + listOf(toolState.translation!!.languageCode), + saveLanguageSettings = true + ) + assertTrue(assertIs(navigator.awaitNextScreen()).intent equalsIntent expected) } } } @@ -232,10 +234,12 @@ class HomePresenterTest { assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState -> toolState.eventSink(ToolCard.Event.OpenTool) - assertIs(navigator.awaitNextScreen()).let { screen -> - val expected = tool.createToolIntent(context, listOf(toolState.translation!!.languageCode)) - assertTrue(expected equalsIntent screen.intent) - } + val expected = tool.createToolIntent( + context, + listOf(toolState.translation!!.languageCode), + saveLanguageSettings = true + ) + assertTrue(assertIs(navigator.awaitNextScreen()).intent equalsIntent expected) } } } @@ -249,10 +253,12 @@ class HomePresenterTest { assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState -> toolState.eventSink(ToolCard.Event.OpenTool) - assertIs(navigator.awaitNextScreen()).let { screen -> - val expected = tool.createToolIntent(context, listOf(Locale.GERMAN, Locale.FRENCH)) - assertTrue(expected equalsIntent screen.intent) - } + val expected = tool.createToolIntent( + context, + listOf(Locale.GERMAN, Locale.FRENCH), + saveLanguageSettings = true + ) + assertTrue(assertIs(navigator.awaitNextScreen()).intent equalsIntent expected) } } } diff --git a/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/activity/MultiLanguageToolActivity.kt b/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/activity/MultiLanguageToolActivity.kt index 63b1c1a8cb..7b8e471ce0 100644 --- a/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/activity/MultiLanguageToolActivity.kt +++ b/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/activity/MultiLanguageToolActivity.kt @@ -24,6 +24,7 @@ import org.cru.godtools.base.tool.analytics.model.ToolAnalyticsActionEvent import org.cru.godtools.base.tool.ui.settings.SettingsBottomSheetDialogFragment import org.cru.godtools.base.tool.ui.settings.ShareLinkSettingsAction import org.cru.godtools.base.tool.viewmodel.ToolStateHolder +import org.cru.godtools.base.ui.EXTRA_SAVE_LANGUAGE_SETTINGS import org.cru.godtools.shared.tool.analytics.ToolAnalyticsActionNames.ACTION_SETTINGS import org.cru.godtools.shared.tool.parser.model.Manifest import org.cru.godtools.shared.tool.parser.model.navBarColor @@ -162,7 +163,9 @@ abstract class MultiLanguageToolActivity( private fun showSettingsDialog() { eventBus.post(ToolAnalyticsActionEvent(null, ACTION_SETTINGS)) - SettingsBottomSheetDialogFragment().show(supportFragmentManager, null) + SettingsBottomSheetDialogFragment( + saveLanguageSettings = intent?.getBooleanExtra(EXTRA_SAVE_LANGUAGE_SETTINGS, false) ?: false, + ).show(supportFragmentManager, null) } protected fun dismissSettingsDialog() { diff --git a/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/ui/settings/SettingsBottomSheetDialogFragment.kt b/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/ui/settings/SettingsBottomSheetDialogFragment.kt index 5a7843986e..ea4ba0f6dc 100644 --- a/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/ui/settings/SettingsBottomSheetDialogFragment.kt +++ b/ui/base-tool/src/main/kotlin/org/cru/godtools/base/tool/ui/settings/SettingsBottomSheetDialogFragment.kt @@ -27,11 +27,17 @@ import org.cru.godtools.model.Language import org.cru.godtools.shared.tool.parser.model.shareable.ShareableImage import org.cru.godtools.tool.R import org.cru.godtools.tool.databinding.ToolSettingsSheetBinding +import splitties.fragmentargs.argOrDefault @AndroidEntryPoint -class SettingsBottomSheetDialogFragment : +class SettingsBottomSheetDialogFragment() : BindingBottomSheetDialogFragment(R.layout.tool_settings_sheet), ToolSettingsSheetCallbacks { + constructor(saveLanguageSettings: Boolean) : this() { + isSaveLanguageSettings = saveLanguageSettings + } + + private var isSaveLanguageSettings by argOrDefault(false) // region Lifecycle override fun onCreate(savedInstanceState: Bundle?) { @@ -159,7 +165,7 @@ class SettingsBottomSheetDialogFragment : primaryLocale: Locale? = activityDataModel.primaryLocales.value?.firstOrNull(), parallelLocale: Locale? = activityDataModel.parallelLocales.value?.firstOrNull(), ) { - if (tool != null) { + if (isSaveLanguageSettings && tool != null) { lifecycleScope.launch { toolsRepository.updateToolLocales(tool, primaryLocale, parallelLocale) } diff --git a/ui/base/src/main/kotlin/org/cru/godtools/base/ui/Activities.kt b/ui/base/src/main/kotlin/org/cru/godtools/base/ui/Activities.kt index d8674f84a7..37701836d4 100644 --- a/ui/base/src/main/kotlin/org/cru/godtools/base/ui/Activities.kt +++ b/ui/base/src/main/kotlin/org/cru/godtools/base/ui/Activities.kt @@ -16,6 +16,8 @@ import org.cru.godtools.base.ui.activity.BaseActivity import org.cru.godtools.base.ui.dashboard.Page const val EXTRA_SHOW_TIPS = "org.cru.godtools.base.tool.activity.MultiLanguageToolActivity.SHOW_TIPS" +const val EXTRA_SAVE_LANGUAGE_SETTINGS = + "org.cru.godtools.base.tool.activity.MultiLanguageToolActivity.SAVE_LANGUAGE_SETTINGS" // region DashboardActivity private const val ACTIVITY_CLASS_DASHBOARD = "org.cru.godtools.ui.dashboard.DashboardActivity" @@ -58,11 +60,13 @@ fun Context.createCyoaActivityIntent( vararg languages: Locale?, pageId: String? = null, showTips: Boolean = false, + saveLanguageSettings: Boolean = false, ) = Intent().setClassName(this, ACTIVITY_CLASS_CYOA) .putExtra(EXTRA_TOOL, toolCode) .putLanguagesExtra(*languages) .putExtra(EXTRA_PAGE, pageId) .putExtra(EXTRA_SHOW_TIPS, showTips) + .putExtra(EXTRA_SAVE_LANGUAGE_SETTINGS, saveLanguageSettings) // endregion CyoaActivity // region TractActivity @@ -76,13 +80,15 @@ fun Context.createTractActivityIntent( vararg languages: Locale?, activeLocale: Locale? = null, page: Int = 0, - showTips: Boolean = false + showTips: Boolean = false, + saveLanguageSettings: Boolean = false, ) = Intent().setClassName(this, ACTIVITY_CLASS_TRACT) .putExtra(EXTRA_TOOL, toolCode) .putLanguagesExtra(*languages) .putExtra(EXTRA_ACTIVE_LOCALE, activeLocale) .putExtra(EXTRA_PAGE, page) .putExtra(EXTRA_SHOW_TIPS, showTips) + .putExtra(EXTRA_SAVE_LANGUAGE_SETTINGS, saveLanguageSettings) // endregion TractActivity fun Context.buildToolExtras(toolCode: String, language: Locale) = BaseActivity.buildExtras(this).apply {