mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-03 19:47:21 +00:00
Integrated the data update fix from v3.1.3
This commit is contained in:
1 parent
7e2b3bc712
commit
9bb73f28b7
7 files changed
+55
-43
No files matched your search
@@ -27,6 +27,7 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import okhttp3.OkHttpClient
|
||||
import org.osmdroid.config.Configuration
|
||||
|
||||
class MainContainer(private val context: Context) {
|
||||
@@ -57,8 +58,9 @@ class MainContainer(private val context: Context) {
|
||||
}
|
||||
|
||||
private fun provideDatabaseRepo(): IDatabaseRepo {
|
||||
val httpClient = OkHttpClient.Builder().build()
|
||||
val dataParser = DataParser(Dispatchers.Default)
|
||||
val dataSource = DataSource(context.contentResolver, Dispatchers.IO)
|
||||
val dataSource = DataSource(context.contentResolver, httpClient, Dispatchers.IO)
|
||||
return DatabaseRepo(Dispatchers.Default, dataParser, dataSource, localStorage, settingsRepo)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,18 +22,26 @@ import android.net.Uri
|
||||
import com.rtbishop.look4sat.data.IDataSource
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
|
||||
class DataSource(
|
||||
private val resolver: ContentResolver, private val dispatcher: CoroutineDispatcher
|
||||
private val contentResolver: ContentResolver,
|
||||
private val httpClient: OkHttpClient,
|
||||
private val dispatcher: CoroutineDispatcher
|
||||
) : IDataSource {
|
||||
|
||||
override suspend fun getFileStream(uri: String): InputStream? {
|
||||
return withContext(dispatcher) { resolver.openInputStream(Uri.parse(uri)) }
|
||||
return withContext(dispatcher) { contentResolver.openInputStream(Uri.parse(uri)) }
|
||||
}
|
||||
|
||||
override suspend fun getNetworkStream(url: String): InputStream? {
|
||||
return withContext(dispatcher) { URL(url).openStream() }
|
||||
override suspend fun getNetworkStream(url: String): InputStream? = withContext(dispatcher) {
|
||||
try {
|
||||
val request = Request.Builder().url(url).build()
|
||||
httpClient.newCall(request).execute().body?.byteStream()
|
||||
} catch (exception: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user