NavDeepLink.Builder


class NavDeepLink.Builder


A builder for constructing NavDeepLink instances.

Summary

Public functions

NavDeepLink

Build the NavDeepLink specified by this builder.

NavDeepLink.Builder
setAction(action: String)

Set the action for the NavDeepLink.

NavDeepLink.Builder
setMimeType(mimeType: String)

Set the mimeType for the NavDeepLink.

NavDeepLink.Builder
setUriPattern(uriPattern: String)

Set the uri pattern for the NavDeepLink.

inline NavDeepLink.Builder
<T : Any> setUriPattern(basePath: String, typeMap: Map<KTypeNavType<*>>)

Set the uri pattern for the NavDeepLink.

Public functions

build

Added in 2.3.0
fun build(): NavDeepLink

Build the NavDeepLink specified by this builder.

Returns
NavDeepLink

the newly constructed NavDeepLink.

setAction

Added in 2.3.0
fun setAction(action: String): NavDeepLink.Builder

Set the action for the NavDeepLink.

Parameters
action: String

the intent action for the NavDeepLink

Returns
NavDeepLink.Builder

This builder.

Throws
kotlin.IllegalArgumentException

if the action is empty.

setMimeType

Added in 2.3.0
fun setMimeType(mimeType: String): NavDeepLink.Builder

Set the mimeType for the NavDeepLink.

Parameters
mimeType: String

the mimeType for the NavDeepLink

Returns
NavDeepLink.Builder

This builder.

setUriPattern

Added in 2.3.0
fun setUriPattern(uriPattern: String): NavDeepLink.Builder

Set the uri pattern for the NavDeepLink.

Parameters
uriPattern: String

The uri pattern to add to the NavDeepLink

Returns
NavDeepLink.Builder

This builder.

setUriPattern

inline fun <T : Any> setUriPattern(
    basePath: String,
    typeMap: Map<KTypeNavType<*>> = emptyMap()
): NavDeepLink.Builder

Set the uri pattern for the NavDeepLink.

Arguments extracted from destination T will be automatically appended to the base path provided in basePath.

Arguments are appended based on property name and in the same order as their declaration order in T. They are appended as query parameters if the argument has either:

  1. a default value

  2. a NavType of CollectionNavType

Otherwise, the argument will be appended as path parameters. The final uriPattern is generated by concatenating uriPattern + path parameters + query parameters.

For example, the name property in this class does not meet either conditions and will be appended as a path param.

@Serializable
class
MyClass(val name: String)

Given a uriPattern of "www.example.com", the generated final uriPattern will be www.example.com/{name}.

The name property in this class has a default value and will be appended as a query.

@Serializable
class
MyClass(val name: String = "default")

Given a uriPattern of "www.example.com", the final generated uriPattern will be www.example.com?name={name}

The append order is based on their declaration order in T

@Serializable
class
MyClass(val name: String = "default", val id: Int, val code: Int)

Given a uriPattern of "www.example.com", the final generated uriPattern will be www.example.com/{id}/{code}?name={name}. In this example, name is appended first as a query param, then id and code respectively as path params. The final pattern is then concatenated with uriPattern + path + query.

Parameters
<T : Any>

The destination's route from KClass

basePath: String

The base uri path to append arguments onto

typeMap: Map<KTypeNavType<*>> = emptyMap()

map of destination arguments' kotlin type KType to its respective custom NavType. May be empty if T does not use custom NavTypes.

Returns
NavDeepLink.Builder

This builder.