Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 82ca900

Browse files
author
neon
committed
refactor&update: little changes
1 parent 139cad9 commit 82ca900

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codee.app.core
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
6+
@SuppressLint("StaticFieldLeak")
7+
object ContextDI {
8+
internal lateinit var context: Context
9+
fun init(context: Context) {
10+
this.context = context
11+
}
12+
}

‎app-core/src/main/java/com/codee/app/core/extensions/Colors.kt‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ val lightThemeColors = mutableStateOf(LightThemeColors().toComposeColors())
2525
*/
2626
val darkThemeColors = mutableStateOf(DarkThemeColors().toComposeColors())
2727

28-
internalfun ThemeColors.toComposeColors() = Colors(
28+
fun ThemeColors.toComposeColors() = Colors(
2929
primary.toComposeColor(),
3030
primaryVariant.toComposeColor(),
3131
secondary.toComposeColor(),
@@ -41,20 +41,7 @@ internal fun ThemeColors.toComposeColors() = Colors(
4141
this is LightThemeColors
4242
)
4343

44-
internalfun Color.toComposeColor() = when (this) {
44+
fun Color.toComposeColor() = when (this) {
4545
is Hex -> ComposeColor(AndroidColor.parseColor(hex))
4646
is RGB -> ComposeColor(AndroidColor.rgb(red, green, blue))
47-
}
48-
49-
/**
50-
* Compose representation of codee theme.
51-
*/
52-
@Composable
53-
fun CodeeTheme(
54-
darkTheme: Boolean = isSystemInDarkTheme(),
55-
content: @Composable () -> Unit
56-
) = MaterialTheme(
57-
colors = if (darkTheme) remember { darkThemeColors.value }
58-
else remember { lightThemeColors.value },
59-
content = content
60-
)
47+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.codee.app.core.extensions
2+
3+
import com.codee.app.resources.locale.Locale
4+
import java.util.Locale as JavaLocale
5+
6+
internal fun JavaLocale.toCodeeLocale(): Locale = Locale(country, language)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codee.app.core.extensions
2+
3+
import androidx.core.os.ConfigurationCompat
4+
import com.codee.app.core.ContextDI.context
5+
import com.codee.app.resources.locale.Localized
6+
import com.codee.app.resources.locale.get
7+
8+
fun <T> Localized<T>.localize(): T {
9+
val locale = ConfigurationCompat.getLocales(context.resources.configuration)[0]
10+
.toCodeeLocale()
11+
val vars = variants.toList()
12+
return if(vars.any { it.first.languageCode == locale.languageCode }) {
13+
if(vars.any { it.first.countryCode == locale.countryCode })
14+
vars.first { it.first == locale }.second
15+
vars.first { it.first.languageCode == locale.languageCode }.second
16+
} else default
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /