mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-03 11:17:25 +00:00
v3.1.3 - Fixed the satellite data update bug #108
This commit is contained in:
7 files changed
+42
-35
No files matched your search
@@ -20,13 +20,20 @@ package com.rtbishop.look4sat.framework.data
|
||||
import com.rtbishop.look4sat.domain.data.IRemoteDataSource
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
|
||||
class RemoteDataSource(private val ioDispatcher: CoroutineDispatcher) : IRemoteDataSource {
|
||||
class RemoteDataSource(
|
||||
private val httpClient: OkHttpClient, private val ioDispatcher: CoroutineDispatcher
|
||||
) : IRemoteDataSource {
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
override suspend fun getDataStream(url: String): InputStream? = withContext(ioDispatcher) {
|
||||
URL(url).openStream()
|
||||
try {
|
||||
val request = Request.Builder().url(url).build()
|
||||
httpClient.newCall(request).execute().body?.byteStream()
|
||||
} catch (exception: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import okhttp3.OkHttpClient
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@@ -58,7 +59,7 @@ object BaseModule {
|
||||
val fileSource = FileDataSource(context.contentResolver, Dispatchers.IO)
|
||||
val entries = LocalEntrySource(db.entriesDao())
|
||||
val radios = LocalRadioSource(db.radiosDao())
|
||||
val remoteSource = RemoteDataSource(Dispatchers.IO)
|
||||
val remoteSource = RemoteDataSource(OkHttpClient.Builder().build(), Dispatchers.IO)
|
||||
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
return DataRepository(parser, fileSource, entries, radios, remoteSource, scope, settings)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user