mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +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
+3
-2
@@ -12,8 +12,8 @@ android {
|
||||
applicationId "com.rtbishop.look4sat"
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
versionCode 312
|
||||
versionName "3.1.2"
|
||||
versionCode 313
|
||||
versionName '3.1.3'
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -69,6 +69,7 @@ dependencies {
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
|
||||
implementation "androidx.navigation:navigation-compose:$navigation_version"
|
||||
// Utility
|
||||
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
|
||||
implementation "org.osmdroid:osmdroid-android:$osmdroid_version"
|
||||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
|
||||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
|
||||
|
||||
@@ -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