ref: 68ae37f62658ef2b5dfe364bfa283d03b4f35951
app/src/main/java/xyz/apiote/bimba/czwek/repo/OfflineRepository.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
// SPDX-FileCopyrightText: Adam Evyčędo // // SPDX-License-Identifier: GPL-3.0-or-later package xyz.apiote.bimba.czwek.repo import android.content.Context import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import xyz.apiote.bimba.czwek.api.Server import xyz.apiote.bimba.czwek.api.responses.FeedsResponse import xyz.apiote.bimba.czwek.api.responses.FeedsResponseDev import xyz.apiote.bimba.czwek.api.responses.FeedsResponseV1 import xyz.apiote.bimba.czwek.api.responses.FeedsResponseV2 import java.io.File import java.io.FileInputStream import java.net.URLEncoder import java.time.LocalDate class OfflineRepository : Repository { override suspend fun getFeeds( context: Context, server: Server ): Map<String, FeedInfo>? { val file = File( context.filesDir, URLEncoder.encode(server.apiPath, "utf-8") ) if (!file.exists()) { return emptyMap() } return when (val response = withContext(Dispatchers.IO) { FeedsResponse.unmarshal(FileInputStream(file)) }) { is FeedsResponseDev -> response.feeds.associate { Pair( it.id, FeedInfo(it).copy(cached = true) ) } is FeedsResponseV2 -> response.feeds.associate { Pair( it.id, FeedInfo(it).copy(cached = true) ) } is FeedsResponseV1 -> response.feeds.associate { Pair( it.id, FeedInfo(it).copy(cached = true) ) } else -> null } } override suspend fun getDepartures( feedID: String, stop: String, line: String?, date: LocalDate?, context: Context, limit: Int? ): StopDepartures? { TODO("Not yet implemented") } override suspend fun getLocatablesIn( context: Context, bl: Position, tr: Position, ): List<Locatable>? { TODO("Not yet implemented") } override suspend fun getLine( context: Context, feedID: String, line: String, ): Line? { TODO("Not yet implemented") } override suspend fun queryQueryables( query: String, context: Context ): List<Queryable>? { TODO("Not yet implemented") } override suspend fun locateQueryables( position: Position, context: Context ): List<Queryable>? { TODO("Not yet implemented") } } |