Skip to content

Commit

Permalink
added temporary oled theme #54
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Dec 26, 2023
1 parent 700b481 commit 5f67931
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ android {
applicationId "io.github.yamin8000.owl"
minSdk 21
targetSdk 34
versionCode 32
versionName "1.5.6"
versionCode 33
versionName "1.5.7"
vectorDrawables {
useSupportLibrary true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class MainActivity : ComponentActivity() {
) {
OwlTheme(
isDarkTheme = isDarkTheme(currentTheme, isSystemInDarkTheme()),
isOledTheme = currentTheme == ThemeSetting.Darker,
isDynamicColor = currentTheme == ThemeSetting.System,
content = content
)
Expand All @@ -126,6 +127,7 @@ class MainActivity : ComponentActivity() {
if (themeSetting == ThemeSetting.Light) return false
if (themeSetting == ThemeSetting.System) return isSystemInDarkTheme
if (themeSetting == ThemeSetting.Dark) return true
if (themeSetting == ThemeSetting.Darker) return true
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ import kotlinx.parcelize.Parcelize
enum class ThemeSetting(
@StringRes val persianNameStringResource: Int
) : Parcelable {
Dark(R.string.theme_dark), Light(R.string.theme_light), System(R.string.theme_system);
Dark(R.string.theme_dark), Light(R.string.theme_light), System(R.string.theme_system), Darker(R.string.theme_oled)
}
23 changes: 21 additions & 2 deletions app/src/main/java/io/github/yamin8000/owl/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ package io.github.yamin8000.owl.ui.theme
import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
Expand Down Expand Up @@ -98,19 +103,29 @@ private val darkColors = darkColorScheme(
@Composable
fun OwlTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(),
isOledTheme: Boolean = false,
isPreviewing: Boolean = false,
isDynamicColor: Boolean,
content: @Composable () -> Unit
) {
val isDynamicColorReadyDevice = isDynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S

val colors = when {
var colors = when {
isDynamicColorReadyDevice && isDarkTheme -> dynamicDarkColorScheme(LocalContext.current)
isDynamicColorReadyDevice && !isDarkTheme -> dynamicLightColorScheme(LocalContext.current)
isDarkTheme -> darkColors
else -> lightColors
}

if (isDarkTheme && isOledTheme) {
colors = colors.copy(
background = colors.background.darken(),
surface = colors.surface.darken(),
surfaceVariant = colors.surfaceVariant.darken(),
inverseOnSurface = colors.inverseOnSurface.darken()
)
}

if (!isPreviewing) {
val activity = LocalView.current.context as Activity
SideEffect {
Expand Down Expand Up @@ -141,4 +156,8 @@ fun PreviewTheme(
isDynamicColor = false,
content = content
)
}

private fun Color.darken(): Color {
return copy(alpha, red / 2, green / 2, blue / 2)
}
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@
<string name="antonym">متضاد</string>
<string name="synonym">مترادف</string>
<string name="start_blank_search">Blank startup search</string>
<string name="theme_oled">تاریک تر</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
~ along with freeDictionaryApp. If not, see <https://www.gnu.org/licenses/>.
-->

<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name" translatable="false">freeDictionary</string>
<string name="search">Search</string>
<string name="search_hint">Enter a word to search</string>
Expand Down Expand Up @@ -66,4 +66,5 @@
<string name="antonym">Antonym</string>
<string name="synonym">Synonym</string>
<string name="start_blank_search">Blank startup search</string>
<string name="theme_oled" tools:ignore="MissingTranslation">OLED/Darker</string>
</resources>

0 comments on commit 5f67931

Please sign in to comment.