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

Fix language settings #726

Merged
merged 3 commits into from
Oct 9, 2021
Merged

Conversation

myoshita
Copy link
Contributor

@myoshita myoshita commented Oct 7, 2021

Issue

Overview (Required)

  • Add language setting from the DataStore to SettingViewModel.State by using combine().
  • Support switch languages in app setting.

Links

Screenshot

Before After

@myoshita myoshita changed the title Add language to state Fix language settings Oct 8, 2021
}
val configuration = resources.configuration
configuration.setLocale(locale)
resources.updateConfiguration(configuration, resources.displayMetrics)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateConfiguration() is deprecated but it can simplify implementation.
If there is a better way to implement this, it may be better to change it...

Copy link
Member

@takahirom takahirom Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this issue 👍
How about adding the following code to uicomponent-compose:core ?
This way, you don't need to rely on updateConfiguration.

private val TextSettingLocal = compositionLocalOf<>()

@Coposable
fun MultiLangText.getTextWithSetting() {
    when(LocalLangSetting.current) {
       Lang.SYSTEM -> currentLangTitle
       ...
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks your proposal !
I implemented it as a trial. 28e48c7
If it looks like ok, I'll try to rewrite the other places.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

@takahirom
Copy link
Member

👀

@github-actions github-actions bot temporarily deployed to deploygate-distribution October 8, 2021 00:46 Inactive
@github-actions github-actions bot temporarily deployed to deploygate-distribution October 8, 2021 06:16 Inactive
}

@JvmInline
value class LangSettingProvidableCompositionLocal internal constructor(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure if this value class approach is good or bad. Is there any reason for this? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm also not sure all that well.
I use this approach that is used in Coil.
It seems like a good approach that current can implement custom getter (can use composable function).
If coil, it is needed the context to get the ImageLoader so can use LocalContext, but this does not require composable functions so it might not make sense...
https://github.com/coil-kt/coil/blob/99c45789ec19895f657d0be7303da2e666b64f14/coil-compose-singleton/src/main/java/coil/compose/LocalImageLoader.kt#L51

because 0.39.0 is not supported 'value class'
@myoshita myoshita force-pushed the fix/language-settings branch from 28e48c7 to a29f7fa Compare October 8, 2021 09:38
Copy link
Contributor Author

@myoshita myoshita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put together commits 41a83ba

Comment on lines +8 to +9
@Composable
fun Lang?.getTitle(): String {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete context and add composable annotation.
This maybe resolves #694

@@ -67,7 +67,7 @@ allprojects {
targetExclude('bin/**/*.kt')
targetExclude("**/generated/**/*.kt")

ktlint("0.39.0")
ktlint("0.42.1")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade ktlint because value class is not supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@takahirom
Copy link
Member

Thank you for the cool pull request 🆒
I will check this 👀

@github-actions github-actions bot temporarily deployed to deploygate-distribution October 9, 2021 04:43 Inactive
Copy link
Member

@takahirom takahirom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the new mechanisms to DroidKaigi app!

@takahirom takahirom merged commit d8fa6a8 into DroidKaigi:main Oct 9, 2021
@myoshita myoshita deleted the fix/language-settings branch October 11, 2021 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Language settings do not work.
2 participants