Daniel Okanin
05/02/2022, 5:59 PM@Stable
class PhotoViewModelItem(
val id: String?,
val title: String?,
val savedGalleries: List<String>?,
)
agrosner
05/02/2022, 6:38 PMList
with this:
import androidx.compose.runtime.Immutable
import java.util.Collections
/**
* Use this list instead of [List] as compose cannot infer list types properly.
*/
@Immutable
data class ImmutableList<T>
internal constructor(
val list: List<T>
) : List<T> by list
/**
* Constructs an [ImmutableList] with the specified [list].
* We copy the passed in list to ensure its fully immutable.
*/
fun <T> immutableListOf(list: List<T>): ImmutableList<T> = ImmutableList(Collections.unmodifiableList(list))
/**
* Constructs an [ImmutableList] with the specified [list].
*/
fun <T> immutableListOf(vararg items: T): ImmutableList<T> = ImmutableList(
Collections.unmodifiableList(
items.toList(),
)
)
/**
* Converts a list to an immutable kind.
*/
fun <T> List<T>.toImmutableList(): ImmutableList<T> = immutableListOf(this)
fun <T> Array<T>.toImmutableList(): ImmutableList<T> = ImmutableList(Collections.unmodifiableList(this.toList()))
Daniel Okanin
05/02/2022, 7:50 PMagrosner
05/02/2022, 8:41 PM