Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make common Uri class for the deeplinks support #1610

Merged
merged 5 commits into from
Oct 2, 2024
Merged
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
3 changes: 2 additions & 1 deletion MULTIPLATFORM.md
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ Compose Multiplatform core libraries can be published to local Maven with the fo
1. Use these gradle properties to set the published libraries versions

`-Pjetbrains.publication.version.CORE_BUNDLE`,
`-Pjetbrains.publication.version.CORE_URI`,
`-Pjetbrains.publication.version.COMPOSE`,
`-Pjetbrains.publication.version.COMPOSE_MATERIAL3_ADAPTIVE`,
`-Pjetbrains.publication.version.LIFECYCLE`,
@@ -73,7 +74,7 @@ Compose Multiplatform core libraries can be published to local Maven with the fo
The default value for the version is `0.0.0-SNAPSHOT`

And library groups:
`-Pjetbrains.publication.libraries=CORE_BUNDLE,COMPOSE,COMPOSE_MATERIAL3_ADAPTIVE,LIFECYCLE,NAVIGATION,SAVEDSTATE,WINDOW`
`-Pjetbrains.publication.libraries=CORE_BUNDLE,CORE_URI,COMPOSE,COMPOSE_MATERIAL3_ADAPTIVE,LIFECYCLE,NAVIGATION,SAVEDSTATE,WINDOW`

The default value includes all libraries.

Original file line number Diff line number Diff line change
@@ -367,8 +367,12 @@ private fun Project.isMultiplatformPublicationEnabled(): Boolean {
return extensions.findByType<KotlinMultiplatformExtension>() != null
}

private val coreKmpLibraries = setOf(
":core:core-bundle",
":core:core-uri",
)
private fun Project.configureMultiplatformPublication(componentFactory: SoftwareComponentFactory) {
if (project.path != ":core:core-bundle") return
if (project.path !in coreKmpLibraries) return
val multiplatformExtension = extensions.findByType<KotlinMultiplatformExtension>()!!
multiplatformExtension.targets.all { target ->
if (target is KotlinAndroidTarget) {
102 changes: 102 additions & 0 deletions core/core-uri/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import androidx.build.PlatformIdentifier
import androidx.build.Publish
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
id("AndroidXPlugin")
id("com.android.library")
}

androidXMultiplatform {
android()
desktop()
mac()
linux()
ios()
js { browser() }
wasm { browser() }

defaultPlatform(PlatformIdentifier.ANDROID)


sourceSets {
commonMain {
dependencies {
api(libs.kotlinStdlib)
}
}

jvmMain.dependsOn(commonMain)
jvmTest.dependsOn(commonTest)
jbMain.dependsOn(commonMain)
jbTest.dependsOn(commonTest)

desktopMain.dependsOn(jvmMain)
desktopMain.dependsOn(jbMain)
desktopTest.dependsOn(jvmTest)
desktopTest.dependsOn(jbTest)

androidMain.dependsOn(jvmMain)
androidTest.dependsOn(jvmTest)

nonJvmMain.dependsOn(jbMain)
nonJvmTest.dependsOn(jbTest)

nativeMain.dependsOn(nonJvmMain)
nativeTest.dependsOn(nonJvmTest)

webMain.dependsOn(nonJvmMain)
webTest.dependsOn(nonJvmTest)

targets.all { target ->
if (target.platformType == KotlinPlatformType.native) {
target.compilations["main"].defaultSourceSet.dependsOn(nativeMain)
target.compilations["test"].defaultSourceSet.dependsOn(nativeTest)
} else if (target.platformType in [
KotlinPlatformType.js,
KotlinPlatformType.wasm
]) {
target.compilations["main"].defaultSourceSet.dependsOn(webMain)
target.compilations["test"].defaultSourceSet.dependsOn(webTest)
}
}
}
}

kotlin {
watchosArm64()
watchosArm32()
watchosX64()
watchosSimulatorArm64()
tvosArm64()
tvosX64()
tvosSimulatorArm64()
mingwX64()
}

android {
namespace "androidx.core.uri"
}

androidx {
name = "androidx.core:core-uri"
publish = Publish.SNAPSHOT_AND_RELEASE
inceptionYear = "2024"
description = "Provides Uri in Kotlin Multiplatform projects"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.core.uri

public actual typealias Uri = android.net.Uri

@Suppress("NOTHING_TO_INLINE")
public actual object UriUtils {
actual inline fun encode(s: String, allow: String?): String = Uri.encode(s, allow)
actual inline fun decode(s: String): String = Uri.decode(s)
actual inline fun parse(uriString: String): Uri = Uri.parse(uriString)
}
64 changes: 64 additions & 0 deletions core/core-uri/src/commonMain/kotlin/androidx/core/uri/Uri.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.core.uri

/**
* @see android.net.Uri
*/
public expect abstract class Uri {
abstract fun getFragment(): String?
abstract fun getQuery(): String?
abstract fun getPathSegments(): List<String>
fun getQueryParameters(key: String): List<String>
fun getQueryParameterNames(): Set<String>
abstract override fun toString(): String
}

public expect object UriUtils {

/**
* Encodes characters in the given string as '%'-escaped octets
* using the UTF-8 scheme. Leaves letters ("A-Z", "a-z"), numbers
* ("0-9"), and unreserved characters ("_-!.~'()*") intact. Encodes
* all other characters with the exception of those specified in the
* allow argument.
*
* @param s string to encode
* @param allow set of additional characters to allow in the encoded form,
* null if no characters should be skipped
* @return an encoded version of s suitable for use as a URI component
*/
fun encode(s: String, allow: String? = null): String

/**
* Decodes '%'-escaped octets in the given string using the UTF-8 scheme.
* Replaces invalid octets with the unicode replacement character
* ("\\uFFFD").
*
* @param s encoded string to decode
* @return the given string with escaped octets decoded
*/
fun decode(s: String): String

/**
* Creates a Uri which parses the given encoded URI string.
*
* @param uriString an RFC 2396-compliant, encoded URI
* @return Uri for this given uri string
*/
fun parse(uriString: String): Uri
}
Loading