Add "Allow black theme" feature flag
This commit is contained in:
parent
104ae4752a
commit
5e6a6af409
16 changed files with 139 additions and 9 deletions
|
|
@ -20,6 +20,10 @@ enum class Theme {
|
|||
Light,
|
||||
}
|
||||
|
||||
private fun Theme.coerceBlackTheme(allowBlackTheme: Boolean): Theme {
|
||||
return if (this == Theme.Black && !allowBlackTheme) Theme.Dark else this
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Theme.isDark(): Boolean {
|
||||
return when (this) {
|
||||
|
|
@ -29,9 +33,9 @@ fun Theme.isDark(): Boolean {
|
|||
}
|
||||
}
|
||||
|
||||
fun Flow<String?>.mapToTheme(): Flow<Theme> = map {
|
||||
fun Flow<String?>.mapToTheme(allowBlackTheme: Boolean = true): Flow<Theme> = map {
|
||||
when (it) {
|
||||
null -> Theme.System
|
||||
else -> Theme.valueOf(it)
|
||||
}
|
||||
}.coerceBlackTheme(allowBlackTheme)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import app.cash.molecule.RecompositionMode
|
|||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
|
|
@ -72,4 +73,14 @@ class ThemeTest {
|
|||
assertThat(awaitItem()).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `mapToTheme falls back to dark when black theme is disabled`() = runTest {
|
||||
flowOf(Theme.Black.name)
|
||||
.mapToTheme(allowBlackTheme = false)
|
||||
.test {
|
||||
assertThat(awaitItem()).isEqualTo(Theme.Dark)
|
||||
awaitComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue