Skip to content

Commit

Permalink
Update Kotlin, Compose, and Compose O'Clock
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCAD committed Jun 20, 2024
1 parent ffb4c25 commit 9eeb7b3
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 95 deletions.
3 changes: 0 additions & 3 deletions app-phone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies {
AndroidX.compose.material3()
AndroidX.compose.ui.toolingPreview()
AndroidX.activity.compose()
platform(AndroidX.compose.bom)
AndroidX.compose.ui()
AndroidX.compose.ui.graphics()
AndroidX.compose.ui.toolingPreview()
Expand All @@ -38,11 +37,9 @@ dependencies {
androidTestImplementation {
AndroidX.test.ext.junit()
AndroidX.test.espresso.core()
platform(AndroidX.compose.bom)
AndroidX.compose.ui.testJunit4()
}
debugImplementation {
platform(AndroidX.compose.bom)
AndroidX.compose.ui.tooling()
AndroidX.compose.ui.testManifest()
}
Expand Down
3 changes: 0 additions & 3 deletions app-watch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies {
libs.compose.oclock.watchface.renderer()
AndroidX.wear.watchFace.editor()

platform(AndroidX.compose.bom)
AndroidX.wear.compose.material()
AndroidX.wear.compose.foundation()
AndroidX.activity.compose()
Expand All @@ -34,11 +33,9 @@ dependencies {
Splitties.toast()
}
androidTestImplementation {
platform(AndroidX.compose.bom)
AndroidX.compose.ui.testJunit4()
}
debugImplementation {
platform(AndroidX.compose.bom)
AndroidX.compose.ui.tooling()
AndroidX.compose.ui.testManifest()
}
Expand Down
1 change: 1 addition & 0 deletions convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
implementation {
Android.tools.build.gradlePlugin()
Kotlin.gradlePlugin()
plugin("org.jetbrains.kotlin.plugin.compose", "_")()
Google.playServicesGradlePlugin()
Firebase.crashlyticsGradlePlugin()
plugin("de.fayard.refreshVersions", "_")()
Expand Down
2 changes: 1 addition & 1 deletion convention-plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pluginManagement {
}
plugins {
id("org.splitties.dependencies-dsl") version "0.1.0"
id("de.fayard.refreshVersions") version "0.60.4"
id("de.fayard.refreshVersions") version "0.60.5"
}
}

Expand Down
6 changes: 1 addition & 5 deletions convention-plugins/src/main/kotlin/android-app.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import de.fayard.refreshVersions.core.versionFor
import java.io.FileNotFoundException

plugins {
kotlin("android")
id("com.android.application")
kotlin("plugin.compose")
}

android {
Expand Down Expand Up @@ -60,7 +60,6 @@ android {
}
}
kotlinOptions {
freeCompilerArgs += "-opt-in=splitties.experimental.ExperimentalSplittiesApi"
jvmTarget = "1.8"
freeCompilerArgs += "-Xcontext-receivers"
}
Expand All @@ -69,9 +68,6 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}
buildFeatures.compose = true
composeOptions {
kotlinCompilerExtensionVersion = versionFor(AndroidX.compose.compiler)
}
packagingOptions.resources {
excludes += setOf(
"META-INF/ASL2.0",
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }

[versions]
composeOClock = "0.1.0-SNAPSHOT"
composeOClock = "0.2.0-SNAPSHOT"
roborazzi = "1.10.1"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pluginManagement {
}

plugins {
id("de.fayard.refreshVersions") version "0.60.4"
id("de.fayard.refreshVersions") version "0.60.5"
id("org.splitties.settings-include-dsl") version "0.2.6"
id("org.splitties.dependencies-dsl") version "0.2.0"
id("org.splitties.version-sync") version "0.2.6"
Expand Down
8 changes: 2 additions & 6 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@file:Suppress("UnstableApiUsage")

import de.fayard.refreshVersions.core.versionFor

plugins {
id("android-lib")
kotlin("plugin.compose")
alias(libs.plugins.roborazzi)
}

Expand All @@ -19,9 +18,6 @@ android {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = versionFor(AndroidX.compose.compiler)
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
Expand All @@ -38,8 +34,8 @@ dependencies {
libs.compose.oclock.core()
Google.android.playServices.wearOS()

platform(AndroidX.compose.bom)
AndroidX.compose.ui()
AndroidX.compose.ui.graphics()
AndroidX.compose.ui.toolingPreview()
AndroidX.compose.ui.text.googleFonts()

Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/kotlin/ComposeOClockWatermark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fun ComposeOClockWatermark(finalBrush: Brush) {
@WatchFacePreview
@Composable
private fun ComposeOClockWatermarkPreview(
@PreviewParameter(WearPreviewSizesProvider::class) size: Dp
@PreviewParameter(WearPreviewSizes::class) size: Dp
) = WatchFacePreview(size) {
ComposeOClockWatermark(SolidColor(Color.Magenta))
}
16 changes: 14 additions & 2 deletions shared/src/main/kotlin/WatchFacePreview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,31 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.wear.watchface.complications.data.ComplicationData
import kotlinx.coroutines.flow.*
import org.splitties.compose.oclock.ExperimentalComposeOClockApi
import org.splitties.compose.oclock.OClockRootCanvas
import org.splitties.compose.oclock.PreviewTime

class WearPreviewSizesProvider : PreviewParameterProvider<Dp> {
class WearPreviewSizes : PreviewParameterProvider<Dp> {
override val values: Sequence<Dp> = sequenceOf(
WatchFacePreview.Size.small,
WatchFacePreview.Size.large
)
}

class WearSmallest : PreviewParameterProvider<Dp> {
override val values: Sequence<Dp> = sequenceOf(
WatchFacePreview.Size.small
)
}

/**
* Example usage:
*
* ```kotlin
* @WatchFacePreview
* @Composable
* private fun MyFunClockPreview(
* @PreviewParameter(WearPreviewSizesProvider::class) size: Dp
* @PreviewParameter(WearPreviewSizes::class) size: Dp
* ) = WatchFacePreview(size) {
* MyFunClock()
* }
Expand All @@ -57,6 +65,8 @@ annotation class WatchFacePreview {
@Composable
fun WatchFacePreview(
size: Dp,
@OptIn(ExperimentalComposeOClockApi::class)
previewTime: PreviewTime.Config = PreviewTime.rememberConfig(),
content: @Composable (complicationData: Map<Int, StateFlow<ComplicationData>>) -> Unit
) {
val spacing = 8.dp
Expand All @@ -80,11 +90,13 @@ fun WatchFacePreview(
val modifier = Modifier.requiredSize(size).clip(CircleShape)
OClockRootCanvas(
modifier = modifier,
previewTime = previewTime,
isAmbientFlow = isAmbientFlow
) { content(it) }
AnimatedVisibility(touched.not()) {
OClockRootCanvas(
modifier = modifier,
previewTime = previewTime,
isAmbientFlow = remember { MutableStateFlow(true) }
) { content(it) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.splitties.compose.oclock.sample.cleanthisbeforerelease.complications
import android.app.PendingIntent
import android.os.Build
import androidx.compose.runtime.Composable
import androidx.compose.runtime.NoLiveLiterals
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.BlendMode
Expand Down Expand Up @@ -31,6 +32,7 @@ import org.splitties.compose.oclock.complications.rememberDrawableAsState
import org.splitties.compose.oclock.complications.rememberMeasuredAsState
import org.splitties.compose.oclock.sample.extensions.topCenterAsTopLeft

@NoLiveLiterals // Because compilation fails otherwise. TODO: Report issue
@Composable
fun PixelWatchStyleComplication(
complicationDataFlow: StateFlow<ComplicationData>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.rotate
import androidx.compose.ui.unit.dp
import org.splitties.compose.oclock.sample.extensions.drawOval
import org.splitties.compose.oclock.sample.extensions.rotate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.splitties.compose.oclock.sample.cleanthisbeforerelease.elements
import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.rotate
import androidx.compose.ui.unit.dp
import androidx.wear.compose.ui.tooling.preview.WearPreviewSmallRound
import org.splitties.compose.oclock.OClockCanvas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.rotate
import androidx.compose.ui.unit.dp
import org.splitties.compose.oclock.LocalIsAmbient
import org.splitties.compose.oclock.OClockCanvas
Expand All @@ -26,9 +27,8 @@ import org.splitties.compose.oclock.sample.extensions.lineTo
import org.splitties.compose.oclock.sample.extensions.moveTo
import org.splitties.compose.oclock.sample.extensions.offsetBy
import org.splitties.compose.oclock.sample.extensions.plus
import org.splitties.compose.oclock.sample.extensions.quadraticBezierTo
import org.splitties.compose.oclock.sample.extensions.quadraticTo
import org.splitties.compose.oclock.sample.extensions.rememberStateWithSize
import org.splitties.compose.oclock.sample.extensions.rotate
import org.splitties.compose.oclock.sample.extensions.rotateAround
import kotlin.math.sqrt

Expand Down Expand Up @@ -158,7 +158,7 @@ private fun Path.setToStarX(
moveTo(topMiddle)
for (i in 1..count) {
val target = topMiddle.rotateAround(pivot = center, degrees = 360f * i / count)
quadraticBezierTo(center, target)
quadraticTo(center, target)
}
close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import androidx.compose.ui.util.fastForEachIndexed
import org.splitties.compose.oclock.LocalIsAmbient
import org.splitties.compose.oclock.OClockCanvas
import org.splitties.compose.oclock.sample.WatchFacePreview
import org.splitties.compose.oclock.sample.WearPreviewSizesProvider
import org.splitties.compose.oclock.sample.WearPreviewSizes
import org.splitties.compose.oclock.sample.extensions.centerAsTopLeft
import org.splitties.compose.oclock.sample.extensions.drawTextOnPath
import org.splitties.compose.oclock.sample.extensions.rememberStateWithSize
Expand Down Expand Up @@ -173,7 +173,7 @@ fun TextOnPathExperiment(finalBrush: Brush) {
@WatchFacePreview
@Composable
private fun TextOnPathExperimentPreview(
@PreviewParameter(WearPreviewSizesProvider::class) size: Dp
@PreviewParameter(WearPreviewSizes::class) size: Dp
) = WatchFacePreview(size) {
TextOnPathExperiment(finalBrush = SolidColor(Color.Magenta))
}
4 changes: 2 additions & 2 deletions shared/src/main/kotlin/elements/MyPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.splitties.compose.oclock.sample.extensions.lineTo
import org.splitties.compose.oclock.sample.extensions.moveTo
import org.splitties.compose.oclock.sample.extensions.offsetBy
import org.splitties.compose.oclock.sample.extensions.plus
import org.splitties.compose.oclock.sample.extensions.quadraticBezierTo
import org.splitties.compose.oclock.sample.extensions.quadraticTo
import org.splitties.compose.oclock.sample.extensions.rotateAround
import kotlin.math.sqrt

Expand All @@ -34,7 +34,7 @@ fun Path.setToStarX(
moveTo(topMiddle)
for (i in 1..count) {
val target = topMiddle.rotateAround(pivot = center, degrees = 360f * i / count)
quadraticBezierTo(center, target)
quadraticTo(center, target)
}
close()
}
Expand Down
18 changes: 9 additions & 9 deletions shared/src/main/kotlin/elements/SinusoidalCrown.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ import org.splitties.compose.oclock.LocalIsAmbient
import org.splitties.compose.oclock.LocalTime
import org.splitties.compose.oclock.OClockCanvas
import org.splitties.compose.oclock.sample.WatchFacePreview
import org.splitties.compose.oclock.sample.WearPreviewSizesProvider
import org.splitties.compose.oclock.sample.WearPreviewSizes
import org.splitties.compose.oclock.sample.elements.vectors.rememberComposeMultiplatformVectorPainter
import org.splitties.compose.oclock.sample.elements.vectors.rememberWearOsLogoVectorPainter
import org.splitties.compose.oclock.sample.extensions.centerAsTopLeft
import org.splitties.compose.oclock.sample.extensions.drawPainter
import org.splitties.compose.oclock.sample.extensions.moveTo
import org.splitties.compose.oclock.sample.extensions.quadraticBezierTo
import org.splitties.compose.oclock.sample.extensions.quadraticTo
import org.splitties.compose.oclock.sample.extensions.rememberStateWithSize
import org.splitties.compose.oclock.sample.extensions.rotateAround

@WatchFacePreview
@Composable
fun SinusoidalCrownPreview(
@PreviewParameter(WearPreviewSizesProvider::class) size: Dp
@PreviewParameter(WearPreviewSizes::class) size: Dp
) = WatchFacePreview(size) {
val time = LocalTime.current
SinusoidalCrown(getRatio = { time.minutesWithSeconds / 60f })
Expand Down Expand Up @@ -111,11 +111,11 @@ private fun Path.setToSineWaveLike(size: Size) {
for (i in 1..count) {
val ratio = i.toFloat() / count
val anglePeriod = 360f / count
quadraticBezierTo(
quadraticTo(
p1 = start.copy(y = 0f).rotateAround(center, anglePeriod * (i - .75f)),
p2 = start.rotateAround(pivot = center, degrees = anglePeriod * (i - .5f))
)
quadraticBezierTo(
quadraticTo(
p1 = start.copy(y = amplitude).rotateAround(center, anglePeriod * (i - .25f)),
p2 = start.rotateAround(pivot = center, degrees = anglePeriod * (i))
)
Expand All @@ -132,13 +132,13 @@ private fun Path.setToDecoration(size: Size) {
val ratio = i.toFloat() / count
val topForward = start.rotateAround(pivot = size.center, degrees = 360f * ratio)
val bottomForward = start.copy(y = amplitude).rotateAround(size.center, 360f * ratio)
quadraticBezierTo(
quadraticTo(
p1 = topForward,
p2 = bottomForward
)
val p3 = bottomForward.rotateAround(pivot = size.center, degrees = 360f / count / 2f)
val p4 = topForward.rotateAround(pivot = size.center, degrees = 360f / count / 2f)
quadraticBezierTo(
quadraticTo(
p3, p4
)
}
Expand All @@ -156,13 +156,13 @@ private fun Path.setToAccidentalArt1(size: Size) {
val anglePeriod = 360f / count
val topForward = start.rotateAround(pivot = center, degrees = 360f * ratio)
val bottomForward = start.copy(y = amplitude).rotateAround(size.center, 360f * ratio)
quadraticBezierTo(
quadraticTo(
p1 = topForward,
p2 = start.rotateAround(center, anglePeriod)
)
val p3 = bottomForward.rotateAround(pivot = size.center, degrees = 360f / count / 2f)
val p4 = topForward.rotateAround(pivot = size.center, degrees = 360f / count / 2f)
quadraticBezierTo(
quadraticTo(
p3, p4
)
}
Expand Down
Loading

0 comments on commit 9eeb7b3

Please sign in to comment.