All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.freeletics.khonshu.navigation.deeplinks.DeepLinkDefinitions.kt Maven / Gradle / Ivy

There is a newer version: 0.29.1
Show newest version
package com.freeletics.khonshu.navigation.deeplinks

import com.freeletics.khonshu.navigation.internal.InternalNavigationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import net.peanuuutz.tomlkt.Toml

@Serializable
public data class DeepLinkDefinitions(
    val prefixes: List = emptyList(),
    val placeholders: List = emptyList(),
    val deepLinks: Map,
) {
    public companion object {
        public fun decodeFromString(string: String): DeepLinkDefinitions {
            return Toml.decodeFromString(string)
        }
    }
}

@Serializable
public data class DeepLinkDefinition(
    val patterns: List,
    val prefixes: List = emptyList(), // use global if empty
    val placeholders: List = emptyList(), // use global if empty or if key not found
    val exampleQueries: List = emptyList(),
)

@Serializable
@JvmInline
public value class PatternDefinition(
    public val value: String,
) {
    init {
        // for validation purposes
        DeepLinkHandler.Pattern(value)
    }

    @OptIn(InternalNavigationApi::class)
    public fun replacePlaceholders(replacement: (String) -> String): String {
        return DeepLinkHandler.Pattern(value).replacePlaceholders(replacement)
    }
}

@Serializable
public data class PrefixDefinition(
    val scheme: String,
    val host: String,
    val autoVerified: Boolean,
) {
    init {
        // for validation purposes
        DeepLinkHandler.Prefix("$scheme://$host")
    }
}

@Serializable
public data class PlaceholderDefinition(
    val key: String,
    val exampleValues: List,
)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy