Skip to content

Commit

Permalink
Switch from XML Themes to Compose Theme for compose components (#1975)
Browse files Browse the repository at this point in the history
* refactor themes, add initial neko, monet themes

* convert lavender

* Add Lime Theme

* Add Tako and adjust all the surface elevation for existing themes

* Rename themes internally to base colors add pink theme

* Add orange theme

* Add BlueGreen

* Fix tool tip and filter button

* Add outrun theme, remove greywolf xml

* Add Red theme

* Fix outline color and onboarding theme select

* Fix icons on filter sheet
  • Loading branch information
nonproto authored Nov 25, 2024
1 parent ca9c928 commit 168a509
Show file tree
Hide file tree
Showing 31 changed files with 1,129 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.updater.AppDownloadInstallJob
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.ui.recents.RecentMangaAdapter
import eu.kanade.tachiyomi.util.system.Themes
import java.security.SecureRandom
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Locale
import org.nekomanga.constants.MdConstants
import org.nekomanga.presentation.theme.Themes
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.PreferenceStore
import tachiyomi.core.preference.getEnum
Expand Down Expand Up @@ -61,13 +61,13 @@ class PreferencesHelper(val context: Context, val preferenceStore: PreferenceSto
fun lightTheme() =
this.preferenceStore.getEnum(
Keys.lightTheme,
if (supportsDynamic) Themes.MONET else Themes.DEFAULT,
if (supportsDynamic) Themes.Monet else Themes.Neko,
)

fun darkTheme() =
this.preferenceStore.getEnum(
Keys.darkTheme,
if (supportsDynamic) Themes.MONET else Themes.DEFAULT,
if (supportsDynamic) Themes.Monet else Themes.Neko,
)

fun showNavigationOverlayNewUser() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SettingsAppearanceController : SettingsController() {
titleRes = R.string.app_theme
lastScrollPostionLight = lastThemeXLight
lastScrollPostionDark = lastThemeXDark
summary = context.getString(context.getPrefTheme(preferences).nameRes)
summary = context.getString(context.getPrefTheme(preferences).nameRes())
activity = this@SettingsAppearanceController.activity
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.mikepenz.fastadapter.select.SelectExtension
import com.mikepenz.fastadapter.select.getSelectExtension
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.Themes
import eu.kanade.tachiyomi.util.system.appDelegateNightMode
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
Expand All @@ -33,6 +32,7 @@ import kotlin.math.max
import org.nekomanga.R
import org.nekomanga.databinding.ThemeItemBinding
import org.nekomanga.databinding.ThemesPreferenceBinding
import org.nekomanga.presentation.theme.Themes
import uy.kohesive.injekt.injectLazy

class ThemePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Expand Down Expand Up @@ -60,21 +60,21 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu
fastAdapterDark.setHasStableIds(true)
selectExtensionLight = fastAdapterLight.getSelectExtension().setThemeListener(false)
selectExtensionDark = fastAdapterDark.getSelectExtension().setThemeListener(true)
val enumConstants = Themes.values()
val enumConstants = Themes.entries.toTypedArray()
val supportsDynamic = DynamicColors.isDynamicColorAvailable()
itemAdapterLight.set(
enumConstants
.filter {
(!it.isDarkTheme || it.followsSystem) &&
(it.styleRes != R.style.Theme_Tachiyomi_Monet || supportsDynamic)
(!it.isDarkTheme() || it.followsSystem()) &&
(it.styleRes() != R.style.Theme_Tachiyomi_Monet || supportsDynamic)
}
.map { ThemeItem(it, false) }
)
itemAdapterDark.set(
enumConstants
.filter {
(it.isDarkTheme || it.followsSystem) &&
(it.styleRes != R.style.Theme_Tachiyomi_Monet || supportsDynamic)
(it.isDarkTheme() || it.followsSystem()) &&
(it.styleRes() != R.style.Theme_Tachiyomi_Monet || supportsDynamic)
}
.map { ThemeItem(it, true) }
)
Expand Down Expand Up @@ -222,9 +222,9 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu
override fun bindView(item: ThemeItem, payloads: List<Any>) {
binding.themeNameText.setText(
if (item.isDarkTheme) {
item.theme.darkNameRes
item.theme.darkNameRes()
} else {
item.theme.nameRes
item.theme.nameRes()
}
)

Expand All @@ -244,7 +244,7 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu
val configuration = Configuration(context.resources.configuration)
configuration.uiMode = if (item.isDarkTheme) UI_MODE_NIGHT_YES else UI_MODE_NIGHT_NO
val themeContext = context.createConfigurationContext(configuration)
themeContext.setTheme(item.theme.styleRes)
themeContext.setTheme(item.theme.styleRes())
val primaryText = themeContext.getResourceColor(android.R.attr.textColorPrimary)
val secondaryText = themeContext.getResourceColor(android.R.attr.textColorSecondary)
val background = themeContext.getResourceColor(R.attr.background)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
super.onConfigurationChanged(newConfig)
val lightMode = !isInNightMode()
val prefTheme = getPrefTheme(preferences)
setTheme(prefTheme.styleRes)
setTheme(prefTheme.styleRes())
val themeValue = TypedValue()
theme.resolveAttribute(android.R.attr.windowLightStatusBar, themeValue, true)

Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import org.nekomanga.presentation.theme.Themes

object ThemeUtil {

Expand All @@ -26,8 +27,8 @@ object ThemeUtil {
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
preferences.lightTheme().set(Themes.DEFAULT)
preferences.darkTheme().set(Themes.DEFAULT)
preferences.lightTheme().set(Themes.Neko)
preferences.darkTheme().set(Themes.Neko)
}

/** Migration method */
Expand All @@ -40,17 +41,17 @@ object ThemeUtil {
putString(
PreferenceKeys.lightTheme,
when (lightTheme) {
"SPRING" -> Themes.SPRING_AND_DUSK
"STRAWBERRY_DAIQUIRI" -> Themes.STRAWBERRIES
else -> Themes.DEFAULT
"SPRING" -> Themes.Pink
"STRAWBERRY_DAIQUIRI" -> Themes.Red
else -> Themes.Neko
}.name,
)
putString(
PreferenceKeys.darkTheme,
when (darkTheme) {
"DUSK" -> Themes.SPRING_AND_DUSK
"CHOCOLATE_STRAWBERRIES" -> Themes.STRAWBERRIES
else -> Themes.DEFAULT
"DUSK" -> Themes.Pink
"CHOCOLATE_STRAWBERRIES" -> Themes.Red
else -> Themes.Neko
}.name,
)
}
Expand All @@ -65,7 +66,7 @@ object ThemeUtil {
}

fun AppCompatActivity.setThemeByPref(preferences: PreferencesHelper) {
setTheme(getPrefTheme(preferences).styleRes)
setTheme(getPrefTheme(preferences).styleRes())
}

fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {
Expand Down
74 changes: 0 additions & 74 deletions app/src/main/java/eu/kanade/tachiyomi/util/system/Themes.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -86,15 +85,6 @@ fun ColumnScope.SearchFooter(
},
isError = isError,
onValueChange = { textChanged(it) },
colors =
OutlinedTextFieldDefaults.colors(
focusedLabelColor = themeColorState.buttonColor,
focusedBorderColor = themeColorState.buttonColor,
cursorColor = themeColorState.buttonColor,
errorBorderColor = MaterialTheme.colorScheme.error,
errorCursorColor = MaterialTheme.colorScheme.error,
errorLabelColor = MaterialTheme.colorScheme.error,
),
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Search),
keyboardActions =
KeyboardActions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ fun ToolTipButton(
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
state = textFieldTooltipState,
tooltip = {
PlainTooltip {
PlainTooltip(
containerColor = MaterialTheme.colorScheme.inverseSurface,
contentColor = MaterialTheme.colorScheme.inverseOnSurface,
) {
Text(
modifier = Modifier.padding(Size.tiny),
style = MaterialTheme.typography.bodyLarge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,13 @@ fun FilterBrowseSheet(
queryText = ""
resetClick()
},
shape = RoundedCornerShape(35),
shape = RoundedCornerShape(Size.extraLarge),
colors =
ButtonDefaults.textButtonColors(contentColor = themeColorState.buttonColor),
ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colorScheme.primary
),
) {
Icon(
imageVector = Icons.Default.RestartAlt,
contentDescription = null,
tint = themeColorState.buttonColor,
)
Icon(imageVector = Icons.Default.RestartAlt, contentDescription = null)
Gap(Size.tiny)
Text(
text = stringResource(id = R.string.reset),
Expand All @@ -380,17 +378,13 @@ fun FilterBrowseSheet(
) {
TextButton(
onClick = { showSaveFilterDialog = true },
shape = RoundedCornerShape(35),
shape = RoundedCornerShape(Size.extraLarge),
colors =
ButtonDefaults.textButtonColors(
contentColor = themeColorState.buttonColor
contentColor = MaterialTheme.colorScheme.primary
),
) {
Icon(
imageVector = Icons.Default.Save,
contentDescription = null,
tint = themeColorState.buttonColor,
)
Icon(imageVector = Icons.Default.Save, contentDescription = null)
Gap(Size.tiny)
Text(
text = stringResource(id = R.string.save),
Expand All @@ -401,22 +395,22 @@ fun FilterBrowseSheet(

ElevatedButton(
onClick = filterClick,
shape = RoundedCornerShape(35),
shape = RoundedCornerShape(Size.extraLarge),
colors =
ButtonDefaults.elevatedButtonColors(
containerColor = themeColorState.buttonColor
containerColor = MaterialTheme.colorScheme.primary
),
) {
Icon(
imageVector = Icons.Default.Search,
contentDescription = null,
tint = MaterialTheme.colorScheme.surface,
tint = MaterialTheme.colorScheme.onPrimary,
)
Gap(Size.tiny)
Text(
text = stringResource(id = R.string.filter),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.surface,
color = MaterialTheme.colorScheme.onPrimary,
)
}
}
Expand Down
Loading

0 comments on commit 168a509

Please sign in to comment.