generated from me/template-mit
38 lines
901 B
Kotlin
38 lines
901 B
Kotlin
package com.hyperling.weather
|
|
|
|
/**
|
|
* Platform-agnostic location storage abstraction.
|
|
*/
|
|
object LocationStorage {
|
|
/**
|
|
* Load all saved locations.
|
|
*/
|
|
fun load(): List<LocationEntry> = getStorage().load()
|
|
|
|
/**
|
|
* Save all locations (replaces existing).
|
|
*/
|
|
fun save(locations: List<LocationEntry>) = getStorage().save(locations)
|
|
|
|
/**
|
|
* Save a single location, merging with existing list.
|
|
*/
|
|
fun saveOne(location: LocationEntry) = getStorage().saveOne(location)
|
|
|
|
/**
|
|
* Delete a location by id.
|
|
*/
|
|
fun delete(id: Long) = getStorage().delete(id)
|
|
|
|
expect fun getStorage(): StorageBackend
|
|
}
|
|
|
|
interface StorageBackend {
|
|
fun load(): List<LocationEntry>
|
|
fun save(locations: List<LocationEntry>)
|
|
fun saveOne(location: LocationEntry)
|
|
fun delete(id: Long)
|
|
}
|
|
|
|
expect fun getPlatformStorage(): StorageBackend
|