1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.navigation 18 19 /** 20 * A [NavType] for [Collection] such as arrays, lists, maps. 21 * 22 * @param T the type of the data that is supported by this NavType 23 * @param isNullableAllowed whether the argument of this type can hold a null value 24 */ 25 public abstract class CollectionNavType<T>( 26 /** 27 * Check if an argument with this type can hold a null value. 28 * 29 * @return Returns true if this type allows null values, false otherwise. 30 */ 31 isNullableAllowed: Boolean 32 ) : NavType<T>(isNullableAllowed) { 33 34 /** 35 * Serialize a value of this NavType into a list of String. 36 * 37 * Each element in the collection should be converted to an individual String element of the 38 * returned list. 39 * 40 * Note: Elements should be encoded with [Uri.encode] 41 * 42 * @param value a value of this NavType 43 * @return List containing encoded and serialized String representation of [value] 44 */ serializeAsValuesnull45 public abstract fun serializeAsValues(value: T): List<String> 46 47 /** 48 * Create and return an empty collection of type [T] 49 * 50 * For example, [T] of type List<MyType> should return emptyList<MyType>(). 51 */ 52 public abstract fun emptyCollection(): T 53 } 54