mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Use Ktor/Ktorfit for API calls (#3122)
This commit is contained in:
parent
d600d182b5
commit
bec5dac9d4
13 changed files with 173 additions and 217 deletions
|
|
@ -25,7 +25,6 @@ import com.geeksville.mesh.model.DeviceHardware
|
|||
import com.geeksville.mesh.network.DeviceHardwareRemoteDataSource
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
|
@ -69,8 +68,7 @@ constructor(
|
|||
// 2. Fetch from remote API
|
||||
runCatching {
|
||||
debug("Fetching device hardware from remote API.")
|
||||
val remoteHardware =
|
||||
remoteDataSource.getAllDeviceHardware() ?: throw IOException("Empty response from server")
|
||||
val remoteHardware = remoteDataSource.getAllDeviceHardware()
|
||||
|
||||
localDataSource.insertAllDeviceHardware(remoteHardware)
|
||||
localDataSource.getByHwModel(hwModel)?.asExternalModel()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import com.geeksville.mesh.database.entity.asExternalModel
|
|||
import com.geeksville.mesh.network.FirmwareReleaseRemoteDataSource
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
|
@ -99,8 +98,7 @@ constructor(
|
|||
val remoteFetchSuccess =
|
||||
runCatching {
|
||||
debug("Fetching fresh firmware releases from remote API.")
|
||||
val networkReleases =
|
||||
remoteDataSource.getFirmwareReleases() ?: throw IOException("Empty response from server")
|
||||
val networkReleases = remoteDataSource.getFirmwareReleases()
|
||||
|
||||
// The API fetches all release types, so we cache them all at once.
|
||||
localDataSource.insertFirmwareReleases(networkReleases.releases.stable, FirmwareReleaseType.STABLE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue