From 8b4a41d43173530bf68442106bb77ff14cf701e2 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Wed, 10 Apr 2024 11:59:27 -0400 Subject: [PATCH] Put FileSystem before Path in APIs (#1952) --- CHANGELOG.md | 1 + .../api/android/redwood-treehouse-host.api | 4 ++- .../api/redwood-treehouse-host.klib.api | 2 ++ .../treehouse/treehouseAppFactoryAndroid.kt | 29 ++++++++++++++++++- .../cash/redwood/treehouse/TreehouseApp.kt | 6 ++-- .../treehouse/treehouseAppFactoryIos.kt | 28 +++++++++++++++++- .../android/composeui/EmojiSearchActivity.kt | 2 +- .../android/views/EmojiSearchActivity.kt | 2 +- .../testing/android/views/TestAppActivity.kt | 2 +- 9 files changed, 67 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5519ef8f6..92554058e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ New: Changed: - Removed generated `typealias`es for package names which changed in 0.10.0. - In `UIViewLazyList`'s `UITableView`, adding special-case handling for programmatic scroll-to-top calls. +- APIs accepting a `FileSystem` and `Path` now have the `FileSystem` coming before the `Path` in the parameter list. Compatibility functions are retained for this version, but will be removed in the next version. Fixed: - Work around a problem with our memory-leak fix where our old LazyList code would crash when its placeholders were unexpectedly removed. diff --git a/redwood-treehouse-host/api/android/redwood-treehouse-host.api b/redwood-treehouse-host/api/android/redwood-treehouse-host.api index 5b51dc383f..77c1a6b1a9 100644 --- a/redwood-treehouse-host/api/android/redwood-treehouse-host.api +++ b/redwood-treehouse-host/api/android/redwood-treehouse-host.api @@ -109,7 +109,9 @@ public abstract class app/cash/redwood/treehouse/TreehouseApp$Spec { } public final class app/cash/redwood/treehouse/TreehouseAppFactoryAndroidKt { - public static final fun TreehouseAppFactory (Landroid/content/Context;Lokhttp3/OkHttpClient;Lapp/cash/zipline/loader/ManifestVerifier;Lokio/Path;Lokio/FileSystem;Ljava/lang/String;JILapp/cash/redwood/treehouse/StateStore;)Lapp/cash/redwood/treehouse/TreehouseApp$Factory; + public static final fun TreehouseAppFactory (Landroid/content/Context;Lokhttp3/OkHttpClient;Lapp/cash/zipline/loader/ManifestVerifier;Lokio/FileSystem;Lokio/Path;Ljava/lang/String;JILapp/cash/redwood/treehouse/StateStore;)Lapp/cash/redwood/treehouse/TreehouseApp$Factory; + public static final synthetic fun TreehouseAppFactory (Landroid/content/Context;Lokhttp3/OkHttpClient;Lapp/cash/zipline/loader/ManifestVerifier;Lokio/Path;Lokio/FileSystem;Ljava/lang/String;JILapp/cash/redwood/treehouse/StateStore;)Lapp/cash/redwood/treehouse/TreehouseApp$Factory; + public static synthetic fun TreehouseAppFactory$default (Landroid/content/Context;Lokhttp3/OkHttpClient;Lapp/cash/zipline/loader/ManifestVerifier;Lokio/FileSystem;Lokio/Path;Ljava/lang/String;JILapp/cash/redwood/treehouse/StateStore;ILjava/lang/Object;)Lapp/cash/redwood/treehouse/TreehouseApp$Factory; public static synthetic fun TreehouseAppFactory$default (Landroid/content/Context;Lokhttp3/OkHttpClient;Lapp/cash/zipline/loader/ManifestVerifier;Lokio/Path;Lokio/FileSystem;Ljava/lang/String;JILapp/cash/redwood/treehouse/StateStore;ILjava/lang/Object;)Lapp/cash/redwood/treehouse/TreehouseApp$Factory; } diff --git a/redwood-treehouse-host/api/redwood-treehouse-host.klib.api b/redwood-treehouse-host/api/redwood-treehouse-host.klib.api index 743bf8dd3a..645092a5c1 100644 --- a/redwood-treehouse-host/api/redwood-treehouse-host.klib.api +++ b/redwood-treehouse-host/api/redwood-treehouse-host.klib.api @@ -161,4 +161,6 @@ final class app.cash.redwood.treehouse/TreehouseUIView : app.cash.redwood.treeho final fun (app.cash.redwood.treehouse/StateSnapshot.Id) // app.cash.redwood.treehouse/TreehouseUIView.stateSnapshotId.|(app.cash.redwood.treehouse.StateSnapshot.Id){}[0] } // Targets: [ios] +final fun app.cash.redwood.treehouse/TreehouseAppFactory(app.cash.zipline.loader/ZiplineHttpClient, app.cash.zipline.loader/ManifestVerifier, okio/FileSystem? =..., okio/Path? =..., kotlin/String =..., kotlin/Long =..., kotlin/Int =..., app.cash.redwood.treehouse/StateStore =...): app.cash.redwood.treehouse/TreehouseApp.Factory // app.cash.redwood.treehouse/TreehouseAppFactory|TreehouseAppFactory(app.cash.zipline.loader.ZiplineHttpClient;app.cash.zipline.loader.ManifestVerifier;okio.FileSystem?;okio.Path?;kotlin.String;kotlin.Long;kotlin.Int;app.cash.redwood.treehouse.StateStore){}[0] +// Targets: [ios] final fun app.cash.redwood.treehouse/TreehouseAppFactory(app.cash.zipline.loader/ZiplineHttpClient, app.cash.zipline.loader/ManifestVerifier, okio/Path? =..., okio/FileSystem? =..., kotlin/String =..., kotlin/Long =..., kotlin/Int =..., app.cash.redwood.treehouse/StateStore =...): app.cash.redwood.treehouse/TreehouseApp.Factory // app.cash.redwood.treehouse/TreehouseAppFactory|TreehouseAppFactory(app.cash.zipline.loader.ZiplineHttpClient;app.cash.zipline.loader.ManifestVerifier;okio.Path?;okio.FileSystem?;kotlin.String;kotlin.Long;kotlin.Int;app.cash.redwood.treehouse.StateStore){}[0] diff --git a/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryAndroid.kt b/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryAndroid.kt index 8b97ae6431..c7fc4af8f2 100644 --- a/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryAndroid.kt +++ b/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryAndroid.kt @@ -18,6 +18,7 @@ package app.cash.redwood.treehouse import android.content.Context import app.cash.zipline.loader.ManifestVerifier import app.cash.zipline.loader.asZiplineHttpClient +import kotlin.DeprecationLevel.HIDDEN import okhttp3.OkHttpClient import okio.FileSystem import okio.Path @@ -27,8 +28,8 @@ public fun TreehouseAppFactory( context: Context, httpClient: OkHttpClient, manifestVerifier: ManifestVerifier, - embeddedDir: Path? = null, embeddedFileSystem: FileSystem? = null, + embeddedDir: Path? = null, cacheName: String = "zipline", cacheMaxSizeInBytes: Long = 50L * 1024L * 1024L, concurrentDownloads: Int = 8, @@ -39,8 +40,34 @@ public fun TreehouseAppFactory( httpClient = httpClient.asZiplineHttpClient(), frameClockFactory = AndroidChoreographerFrameClock.Factory(), manifestVerifier = manifestVerifier, + embeddedFileSystem = embeddedFileSystem, embeddedDir = embeddedDir, + cacheName = cacheName, + cacheMaxSizeInBytes = cacheMaxSizeInBytes, + concurrentDownloads = concurrentDownloads, + stateStore = stateStore, +) + +@Deprecated("", level = HIDDEN) // TODO Delete overload once 0.11.0 ships. +@Suppress("FunctionName") +public fun TreehouseAppFactory( + context: Context, + httpClient: OkHttpClient, + manifestVerifier: ManifestVerifier, + embeddedDir: Path? = null, + embeddedFileSystem: FileSystem? = null, + cacheName: String = "zipline", + cacheMaxSizeInBytes: Long = 50L * 1024L * 1024L, + concurrentDownloads: Int = 8, + stateStore: StateStore = MemoryStateStore(), +): TreehouseApp.Factory = TreehouseApp.Factory( + platform = AndroidTreehousePlatform(context), + dispatchers = AndroidTreehouseDispatchers(), + httpClient = httpClient.asZiplineHttpClient(), + frameClockFactory = AndroidChoreographerFrameClock.Factory(), + manifestVerifier = manifestVerifier, embeddedFileSystem = embeddedFileSystem, + embeddedDir = embeddedDir, cacheName = cacheName, cacheMaxSizeInBytes = cacheMaxSizeInBytes, concurrentDownloads = concurrentDownloads, diff --git a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseApp.kt b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseApp.kt index d27160cf0d..e4ca849674 100644 --- a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseApp.kt +++ b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseApp.kt @@ -151,10 +151,10 @@ public class TreehouseApp private constructor( cache = factory.cache, ) - if (factory.embeddedDir != null && factory.embeddedFileSystem != null) { + if (factory.embeddedFileSystem != null && factory.embeddedDir != null) { loader = loader.withEmbedded( - embeddedDir = factory.embeddedDir, embeddedFileSystem = factory.embeddedFileSystem, + embeddedDir = factory.embeddedDir, ) } } @@ -199,8 +199,8 @@ public class TreehouseApp private constructor( internal val httpClient: ZiplineHttpClient, internal val frameClockFactory: FrameClock.Factory, internal val manifestVerifier: ManifestVerifier, - internal val embeddedDir: Path?, internal val embeddedFileSystem: FileSystem?, + internal val embeddedDir: Path?, private val cacheName: String, private val cacheMaxSizeInBytes: Long, internal val concurrentDownloads: Int, diff --git a/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryIos.kt b/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryIos.kt index 9384da1c22..60c297cfa0 100644 --- a/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryIos.kt +++ b/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/treehouseAppFactoryIos.kt @@ -17,6 +17,7 @@ package app.cash.redwood.treehouse import app.cash.zipline.loader.ManifestVerifier import app.cash.zipline.loader.ZiplineHttpClient +import kotlin.DeprecationLevel.HIDDEN import okio.FileSystem import okio.Path @@ -24,8 +25,8 @@ import okio.Path public fun TreehouseAppFactory( httpClient: ZiplineHttpClient, manifestVerifier: ManifestVerifier, - embeddedDir: Path? = null, embeddedFileSystem: FileSystem? = null, + embeddedDir: Path? = null, cacheName: String = "zipline", cacheMaxSizeInBytes: Long = 50L * 1024L * 1024L, concurrentDownloads: Int = 8, @@ -36,8 +37,33 @@ public fun TreehouseAppFactory( httpClient = httpClient, frameClockFactory = IosDisplayLinkClock, manifestVerifier = manifestVerifier, + embeddedFileSystem = embeddedFileSystem, embeddedDir = embeddedDir, + cacheName = cacheName, + cacheMaxSizeInBytes = cacheMaxSizeInBytes, + concurrentDownloads = concurrentDownloads, + stateStore = stateStore, +) + +@Deprecated("", level = HIDDEN) // TODO Delete overload once 0.11.0 ships. +@Suppress("FunctionName") +public fun TreehouseAppFactory( + httpClient: ZiplineHttpClient, + manifestVerifier: ManifestVerifier, + embeddedDir: Path? = null, + embeddedFileSystem: FileSystem? = null, + cacheName: String = "zipline", + cacheMaxSizeInBytes: Long = 50L * 1024L * 1024L, + concurrentDownloads: Int = 8, + stateStore: StateStore = MemoryStateStore(), +): TreehouseApp.Factory = TreehouseApp.Factory( + platform = IosTreehousePlatform(), + dispatchers = IosTreehouseDispatchers(), + httpClient = httpClient, + frameClockFactory = IosDisplayLinkClock, + manifestVerifier = manifestVerifier, embeddedFileSystem = embeddedFileSystem, + embeddedDir = embeddedDir, cacheName = cacheName, cacheMaxSizeInBytes = cacheMaxSizeInBytes, concurrentDownloads = concurrentDownloads, diff --git a/samples/emoji-search/android-composeui/src/main/kotlin/com/example/redwood/emojisearch/android/composeui/EmojiSearchActivity.kt b/samples/emoji-search/android-composeui/src/main/kotlin/com/example/redwood/emojisearch/android/composeui/EmojiSearchActivity.kt index 3a6fcaabd7..19ec388d0f 100644 --- a/samples/emoji-search/android-composeui/src/main/kotlin/com/example/redwood/emojisearch/android/composeui/EmojiSearchActivity.kt +++ b/samples/emoji-search/android-composeui/src/main/kotlin/com/example/redwood/emojisearch/android/composeui/EmojiSearchActivity.kt @@ -141,8 +141,8 @@ class EmojiSearchActivity : ComponentActivity() { context = applicationContext, httpClient = httpClient, manifestVerifier = ManifestVerifier.Companion.NO_SIGNATURE_CHECKS, - embeddedDir = "/".toPath(), embeddedFileSystem = applicationContext.assets.asFileSystem(), + embeddedDir = "/".toPath(), ) val manifestUrlFlow = flowOf("http://10.0.2.2:8080/manifest.zipline.json") diff --git a/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt b/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt index 147776c044..1c8222c468 100644 --- a/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt +++ b/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt @@ -142,8 +142,8 @@ class EmojiSearchActivity : ComponentActivity() { context = applicationContext, httpClient = httpClient, manifestVerifier = ManifestVerifier.NO_SIGNATURE_CHECKS, - embeddedDir = "/".toPath(), embeddedFileSystem = applicationContext.assets.asFileSystem(), + embeddedDir = "/".toPath(), stateStore = FileStateStore( json = Json { useArrayPolymorphism = true diff --git a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt index aa2e7298ce..f49f4cabd8 100644 --- a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt +++ b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt @@ -126,8 +126,8 @@ class TestAppActivity : ComponentActivity() { context = applicationContext, httpClient = httpClient, manifestVerifier = ManifestVerifier.NO_SIGNATURE_CHECKS, - embeddedDir = "/".toPath(), embeddedFileSystem = applicationContext.assets.asFileSystem(), + embeddedDir = "/".toPath(), stateStore = FileStateStore( json = Json { serializersModule = testAppSerializersModule