Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Upgrade to Kotlin 1.9.0 and Compose MP 1.5.0-dev #1395

Merged
merged 20 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
cache-disabled: true

- name: Build Desktop App
run: ./gradlew jvmTest :desktop-app:package
run: ./gradlew jvmTest :desktop-app:packageDistributionForCurrentOS

- name: Upload build outputs
if: always()
Expand Down Expand Up @@ -274,7 +274,8 @@ jobs:
cache-disabled: true

- name: iosX64Test
run: ./gradlew iosX64Test
# Disable CC due to https://github.com/google/ksp/issues/1463
run: ./gradlew iosX64Test --no-configuration-cache

- name: Upload reports
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android-app/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id("app.tivi.android.application")
id("app.tivi.kotlin.android")
alias(libs.plugins.ksp)
alias(libs.plugins.composeMultiplatform)
id("app.tivi.compose")
}

val appVersionCode = properties["TIVI_VERSIONCODE"]?.toString()?.toInt() ?: 1000
Expand Down
8 changes: 4 additions & 4 deletions android-app/app/src/main/kotlin/app/tivi/home/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class MainActivity : TiviActivity() {
val navigator = rememberCircuitNavigator(backstack)

component.tiviContent(
backstack = backstack,
navigator = navigator,
onOpenUrl = { url ->
backstack,
navigator,
{ url ->
val intent = CustomTabsIntent.Builder().build()
intent.launchUrl(this@MainActivity, Uri.parse(url))
},
modifier = Modifier.semantics {
Modifier.semantics {
// Enables testTag -> UiAutomator resource id
// See https://developer.android.com/jetpack/compose/testing#uiautomator-interop
@OptIn(ExperimentalComposeUiApi::class)
Expand Down
2 changes: 1 addition & 1 deletion common/imageloading/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plugins {
id("app.tivi.android.library")
id("app.tivi.kotlin.multiplatform")
alias(libs.plugins.composeMultiplatform)
id("app.tivi.compose")
}

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion common/ui/circuit-overlay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plugins {
id("app.tivi.android.library")
id("app.tivi.kotlin.multiplatform")
alias(libs.plugins.composeMultiplatform)
id("app.tivi.compose")
}

android {
Expand Down
6 changes: 1 addition & 5 deletions common/ui/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plugins {
id("app.tivi.android.library")
id("app.tivi.kotlin.multiplatform")
alias(libs.plugins.composeMultiplatform)
id("app.tivi.compose")
}

kotlin {
Expand Down Expand Up @@ -39,10 +39,6 @@ kotlin {

val jvmCommon by creating {
dependsOn(commonMain)

dependencies {
implementation(projects.thirdparty.composeMaterialDialogs.datetime)
}
}

val jvmMain by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fun <T : Any> LazyGridScope.items(
val item = items.peek(index)
when {
item != null && span != null -> span(item)
else -> GridItemSpan(0)
else -> GridItemSpan(1)
}
},
contentType = { index ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun TopAppBarWithBottomContent(
title = title,
navigationIcon = navigationIcon,
actions = actions,
colors = TopAppBarDefaults.smallTopAppBarColors(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
titleContentColor = LocalContentColor.current,
actionIconContentColor = LocalContentColor.current,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ expect fun TimePickerDialog(
},
confirmLabel: String = LocalStrings.current.buttonConfirm,
title: String = "",
is24Hour: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -126,7 +126,7 @@ fun ClickableReadOnlyOutlinedTextField(
onClick: () -> Unit,
modifier: Modifier = Modifier,
label: (@Composable () -> Unit)? = null,
shape: Shape = TextFieldDefaults.outlinedShape,
shape: Shape = OutlinedTextFieldDefaults.shape,
) {
val borderColor = MaterialTheme.colorScheme.primary.copy(
alpha = if (value.isNotEmpty()) 1f else 0.4f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.with
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -104,10 +104,10 @@ fun AsyncImage(
transitionSpec = {
val (_, xfade) = targetState
when {
xfade -> fadeIn(tween(200)) with fadeOut(tween(200))
xfade -> fadeIn(tween(200)) togetherWith fadeOut(tween(200))
else -> {
// If it's loaded from the memory cache, don't fade it in
EnterTransition.None with ExitTransition.None
EnterTransition.None togetherWith ExitTransition.None
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ actual fun TimePickerDialog(
selectedTime: LocalTime,
confirmLabel: String,
title: String,
is24Hour: Boolean,
) {
DatePickerViewController(
selectedDate = NSCalendar.currentCalendar().dateBySettingHour(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
package app.tivi.common.compose.ui

import androidx.compose.material3.Button
import androidx.compose.material3.DatePicker
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TimePicker
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.material3.rememberTimePickerState
import androidx.compose.runtime.Composable
import com.vanpra.composematerialdialogs.datetime.date.DatePicker
import com.vanpra.composematerialdialogs.datetime.time.TimePicker
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.snapshotFlow
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.atTime
import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime

@Composable
actual fun TimePickerDialog(
Expand All @@ -21,8 +31,14 @@ actual fun TimePickerDialog(
selectedTime: LocalTime,
confirmLabel: String,
title: String,
is24Hour: Boolean,
) {
val timePickerState = rememberTimePickerState(selectedTime.hour, selectedTime.minute)

LaunchedEffect(timePickerState) {
snapshotFlow { LocalTime(timePickerState.hour, timePickerState.minute, 0, 0) }
.collect { onTimeChanged(it) }
}

AlertDialog(
onDismissRequest = onDismissRequest,
confirmButton = {
Expand All @@ -31,12 +47,7 @@ actual fun TimePickerDialog(
}
},
text = {
TimePicker(
title = title,
initialTime = selectedTime,
is24HourClock = false,
onTimeChange = onTimeChanged,
)
TimePicker(state = timePickerState)
},
)
}
Expand All @@ -51,6 +62,14 @@ actual fun DatePickerDialog(
maximumDate: LocalDate?,
title: String,
) {
val datePickerState = rememberDatePickerState(
initialSelectedDateMillis = selectedDate
.atTime(hour = 12, minute = 0)
.toInstant(TimeZone.currentSystemDefault())
.toEpochMilliseconds(),
yearRange = 1900..Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date.year,
)

AlertDialog(
onDismissRequest = onDismissRequest,
confirmButton = {
Expand All @@ -60,10 +79,11 @@ actual fun DatePickerDialog(
},
text = {
DatePicker(
title = title,
initialDate = selectedDate,
onDateChange = onDateChanged,
allowedDateValidator = { date ->
state = datePickerState,
dateValidator = { epoch ->
val date = Instant.fromEpochMilliseconds(epoch)
.toLocalDateTime(TimeZone.currentSystemDefault())
.date
when {
minimumDate != null && date < minimumDate -> false
maximumDate != null && date > maximumDate -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app.tivi.common.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.window.DialogWindow
import androidx.compose.ui.window.rememberDialogState

@Composable
Expand All @@ -12,7 +13,7 @@ actual fun Dialog(
properties: DialogProperties,
content: @Composable () -> Unit,
) {
androidx.compose.ui.window.Dialog(
DialogWindow(
onCloseRequest = onDismissRequest,
state = rememberDialogState(size = properties.size),
title = properties.title,
Expand Down
2 changes: 1 addition & 1 deletion common/ui/resources/fonts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plugins {
id("app.tivi.android.library")
id("app.tivi.kotlin.multiplatform")
alias(libs.plugins.composeMultiplatform)
id("app.tivi.compose")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,42 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import kotlinx.coroutines.runBlocking
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.resource
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.usePinned
import platform.Foundation.NSBundle
import platform.Foundation.NSData
import platform.Foundation.NSFileManager
import platform.posix.memcpy

private val cache: MutableMap<String, Font> = mutableMapOf()

@OptIn(ExperimentalResourceApi::class)
@Composable
actual fun font(fontName: String, resourceId: String, weight: FontWeight, style: FontStyle): Font {
return cache.getOrPut(resourceId) {
val byteArray = runBlocking {
resource("$resourceId.ttf").readBytes()
// Ideally we'd use the resource() API here, but it doesn't seem to be working
// in multi-module projects
androidx.compose.ui.text.platform.Font(
identity = resourceId,
data = readBundleFile("$resourceId.ttf"),
weight = weight,
style = style,
)
}
}

@OptIn(ExperimentalForeignApi::class)
private fun readBundleFile(path: String): ByteArray {
val fileManager = NSFileManager.defaultManager()
val composeResourcesPath = NSBundle.mainBundle.resourcePath + "/" + path
val contentsAtPath: NSData? = fileManager.contentsAtPath(composeResourcesPath)
if (contentsAtPath != null) {
val byteArray = ByteArray(contentsAtPath.length.toInt())
byteArray.usePinned {
memcpy(it.addressOf(0), contentsAtPath.bytes, contentsAtPath.length)
}
androidx.compose.ui.text.platform.Font(resourceId, byteArray, weight, style)
return byteArray
} else {
error("File $path not found in Bundle")
}
}
2 changes: 1 addition & 1 deletion desktop-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
// We have to use KMP due to Moko-resources
// https://github.com/icerockdev/moko-resources/issues/263
id("app.tivi.kotlin.multiplatform")
alias(libs.plugins.composeMultiplatform)
id("app.tivi.compose")
}

kotlin {
Expand Down
8 changes: 4 additions & 4 deletions desktop-app/src/jvmMain/kotlin/app/tivi/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ fun main() = application {
val navigator = rememberCircuitNavigator(backstack) { /* no-op */ }

component.tiviContent(
backstack = backstack,
navigator = navigator,
onOpenUrl = { /* no-op for now */ },
modifier = Modifier,
backstack,
navigator,
{ /* no-op for now */ },
Modifier,
)
}
}
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8

# https://docs.gradle.org/7.6/userguide/configuration_cache.html
# Disabled due to KMP plugin. Should be fixed in Kotlin 1.9:
# https://youtrack.jetbrains.com/issue/KT-49933/Support-Gradle-Configuration-caching-with-HMPP
org.gradle.configuration-cache=false
org.gradle.configuration-cache=true

# AndroidX
android.useAndroidX=true
Expand Down
6 changes: 6 additions & 0 deletions gradle/build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.spotless.gradlePlugin)
compileOnly(libs.compose.gradlePlugin)
}

gradlePlugin {
Expand Down Expand Up @@ -64,5 +65,10 @@ gradlePlugin {
id = "app.tivi.android.test"
implementationClass = "app.tivi.gradle.AndroidTestConventionPlugin"
}

register("compose") {
id = "app.tivi.compose"
implementationClass = "app.tivi.gradle.ComposeMultiplatformConventionPlugin"
}
}
}
Loading