Skip to content

Commit

Permalink
Merge pull request #225 from imashnake0/mcu-refactor
Browse files Browse the repository at this point in the history
Replace our material-color-utilities fork with MaterialKolor
  • Loading branch information
imashnake0 authored Dec 28, 2024
2 parents 865758f + 16e3843 commit 21a3238
Show file tree
Hide file tree
Showing 50 changed files with 23 additions and 4,823 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Some apps that I referred to while developing:

Libraries:
- [Compose Markdown](https://github.com/boswelja/compose-markdown)
- [MaterialKolor](https://github.com/jordond/MaterialKolor)

## [License](https://github.com/imashnake0/Animite/blob/15eaac4a80c1e6eef3a4d6c861cab05670fb174b/LICENSE.txt)
```
Expand Down
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dependencies {
implementation(projects.navigation)
implementation(projects.profile)
implementation(projects.social)
implementation(projects.materialColorUtilities)

// AndroidX
implementation(libs.androidx.activityCompose)
Expand Down Expand Up @@ -87,6 +86,8 @@ dependencies {
implementation(libs.hilt.navigationCompose)
ksp(libs.hilt.android.compiler)

implementation(libs.materialKolor)

coreLibraryDesugaring(libs.android.desugaring)

testImplementation(libs.test.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
package com.imashnake.animite.dev.ext

import androidx.compose.material3.ColorScheme
import androidx.compose.ui.graphics.Color
import scheme.Scheme

fun ColorScheme.from(scheme: Scheme) =
ColorScheme(
primary = Color(scheme.primary),
onPrimary = Color(scheme.onPrimary),
primaryContainer = Color(scheme.primaryContainer),
onPrimaryContainer = Color(scheme.onPrimaryContainer),
inversePrimary = Color(scheme.inversePrimary),
secondary = Color(scheme.secondary),
onSecondary = Color(scheme.onSecondary),
secondaryContainer = Color(scheme.secondaryContainer),
onSecondaryContainer = Color(scheme.onSecondaryContainer),
tertiary = Color(scheme.tertiary),
onTertiary = Color(scheme.onTertiary),
tertiaryContainer = Color(scheme.tertiaryContainer),
onTertiaryContainer = Color(scheme.onTertiaryContainer),
background = Color(scheme.background),
onBackground = Color(scheme.onBackground),
surface = Color(scheme.surface),
onSurface = Color(scheme.onSurface),
surfaceVariant = Color(scheme.surfaceVariant),
onSurfaceVariant = Color(scheme.onSurfaceVariant),
surfaceTint = this.surfaceTint,
inverseSurface = Color(scheme.inverseSurface),
inverseOnSurface = Color(scheme.inverseOnSurface),
error = Color(scheme.error),
onError = Color(scheme.onError),
errorContainer = Color(scheme.errorContainer),
onErrorContainer = Color(scheme.onErrorContainer),
outline = Color(scheme.outline),
outlineVariant = Color(scheme.outlineVariant),
scrim = Color(scheme.scrim),
)

/**
* @see [Scheme.pastelize].
*/
fun ColorScheme.pastelize(backgroundToPrimary: Float) = with(this) {
copy(background = background.blendWith(primary, backgroundToPrimary))
}
37 changes: 0 additions & 37 deletions app/src/main/kotlin/com/imashnake/animite/dev/ext/SchemeExt.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.imashnake.animite.dev.ext.from
import androidx.compose.ui.graphics.Color
import com.imashnake.animite.core.Constants.PASTELIZE_RATIO
import com.imashnake.animite.dev.ext.pastelize
import utils.ThemeUtils
import com.materialkolor.rememberDynamicColorScheme

/**
* Remembers a new Material3 [ColorScheme] based on the given color, or falls back to the default
Expand All @@ -23,18 +23,8 @@ fun rememberColorSchemeFor(
fallbackColorScheme: ColorScheme = MaterialTheme.colorScheme,
isDark: Boolean = isSystemInDarkTheme()
): ColorScheme {
return remember(color, isDark) {
if (color != null) {
fallbackColorScheme.from(
if (isDark)
ThemeUtils.themeFromSourceColor(color).schemes.dark
else
ThemeUtils.themeFromSourceColor(color).schemes.light.pastelize(
backgroundToPrimary = 0.09f
)
)
} else {
fallbackColorScheme
}
}
return color?.let {
rememberDynamicColorScheme(Color(it), isDark = isDark, isAmoled = false)
.pastelize(PASTELIZE_RATIO)
} ?: fallbackColorScheme
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import com.imashnake.animite.core.Constants.PASTELIZE_RATIO
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.core.ui.Paddings
import com.imashnake.animite.core.ui.rememberDefaultPaddings
Expand All @@ -27,11 +28,11 @@ fun AnimiteTheme(
val darkTheme = isSystemInDarkTheme()
val animiteColorScheme = when {
dynamicColor && darkTheme -> dynamicDarkColorScheme(LocalContext.current)
dynamicColor && !darkTheme -> dynamicLightColorScheme(LocalContext.current).pastelize(
backgroundToPrimary = 0.05f
)
dynamicColor && !darkTheme -> dynamicLightColorScheme(LocalContext.current)
.pastelize(PASTELIZE_RATIO)
darkTheme -> KimiNoDarkColorScheme
else -> KimiNoLightColorScheme.pastelize(backgroundToPrimary = 0.05f)
else -> KimiNoLightColorScheme
.pastelize(PASTELIZE_RATIO)
}
val animiteRippleTheme = RippleConfiguration(
color = MaterialTheme.colorScheme.primary,
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/com/imashnake/animite/core/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ object Constants {
const val ANILIST_BASE_URL = "https://graphql.anilist.co/"
const val CROSSFADE_DURATION = 500
const val MEDIA_TYPE = "mediaType"

const val PASTELIZE_RATIO = 0.05f
}
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ detekt = "1.23.7"
# https://github.com/boswelja/compose-markdown.
composeMarkdown = "1.1.0"

# MaterialKolor
# https://github.com/jordond/MaterialKolor
materialKolor = "2.0.0"


[libraries]

Expand Down Expand Up @@ -116,6 +120,8 @@ hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "dagger" }
hilt-navigationCompose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hilt" }
test-junit = { group = "junit", name = "junit", version.ref = "junit" }
materialKolor = { group = "com.materialkolor", name = "material-kolor", version.ref = "materialKolor" }


[bundles]

Expand Down
10 changes: 0 additions & 10 deletions material-color-utilities/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions material-color-utilities/build.gradle.kts

This file was deleted.

1 change: 0 additions & 1 deletion material-color-utilities/src/main/AndroidManifest.xml

This file was deleted.

72 changes: 0 additions & 72 deletions material-color-utilities/src/main/kotlin/blend/Blend.kt

This file was deleted.

10 changes: 0 additions & 10 deletions material-color-utilities/src/main/kotlin/common/BiFunction.kt

This file was deleted.

17 changes: 0 additions & 17 deletions material-color-utilities/src/main/kotlin/common/Function.kt

This file was deleted.

Loading

0 comments on commit 21a3238

Please sign in to comment.