Skip to content

Commit

Permalink
only store language setting changes when launched from favorite tools
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Dec 19, 2024
1 parent 578a82d commit 7ef895a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
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 @@ -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

0 comments on commit 7ef895a

Please sign in to comment.