Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-2314 only store language setting changes when launched from favorite tools #3827

Merged
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 @@ -64,6 +64,7 @@ class AllFavoritesPresenter @AssistedInject constructor(
tool.primaryLocale ?: state.translation?.languageCode,
tool.parallelLocale
),
saveLanguageSettings = true
)

if (intent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class HomePresenter @AssistedInject constructor(
tool.primaryLocale ?: state.translation?.languageCode,
tool.parallelLocale
),
saveLanguageSettings = true
)

if (intent != null) {
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/kotlin/org/cru/godtools/util/ActivityUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ fun Tool.createToolIntent(
languages: List<Locale>,
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ class AllFavoritesPresenterTest {
presenter.test {
expectMostRecentItem().tools[0].eventSink(ToolCard.Event.Click)

assertTrue {
assertIs<IntentScreen>(navigator.awaitNextScreen()).intent
.equalsIntent(tool.createToolIntent(context, languages = listOf(Locale.ENGLISH)))
}
val expected = tool.createToolIntent(
context,
languages = listOf(Locale.ENGLISH),
saveLanguageSettings = true
)
assertTrue(assertIs<IntentScreen>(navigator.awaitNextScreen()).intent equalsIntent expected)
}

verifyAll { eventBus.post(OpenAnalyticsActionEvent(ACTION_OPEN_TOOL, tool.code, SOURCE_FAVORITE)) }
Expand All @@ -181,10 +183,12 @@ class AllFavoritesPresenterTest {
presenter.test {
expectMostRecentItem().tools[0].eventSink(ToolCard.Event.Click)

assertTrue {
assertIs<IntentScreen>(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<IntentScreen>(navigator.awaitNextScreen()).intent equalsIntent expected)
}

verifyAll { eventBus.post(OpenAnalyticsActionEvent(ACTION_OPEN_TOOL, tool.code, SOURCE_FAVORITE)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ class HomePresenterTest {
assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState ->
toolState.eventSink(ToolCard.Event.Click)

assertIs<IntentScreen>(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<IntentScreen>(navigator.awaitNextScreen()).intent equalsIntent expected)
}
}
}
Expand All @@ -232,10 +234,12 @@ class HomePresenterTest {
assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState ->
toolState.eventSink(ToolCard.Event.OpenTool)

assertIs<IntentScreen>(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<IntentScreen>(navigator.awaitNextScreen()).intent equalsIntent expected)
}
}
}
Expand All @@ -249,10 +253,12 @@ class HomePresenterTest {
assertNotNull(expectMostRecentItem().favoriteTools[0]) { toolState ->
toolState.eventSink(ToolCard.Event.OpenTool)

assertIs<IntentScreen>(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<IntentScreen>(navigator.awaitNextScreen()).intent equalsIntent expected)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -162,7 +163,9 @@ abstract class MultiLanguageToolActivity<B : ViewDataBinding>(

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToolSettingsSheetBinding>(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?) {
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading