File tree 9 files changed +13
-19
lines changed
androidMain/kotlin/dev/johnoreilly/common
commonMain/kotlin/dev/johnoreilly/common
iosMain/kotlin/dev/johnoreilly/common
jvmMain/kotlin/dev/johnoreilly/common
macosMain/kotlin/dev/johnoreilly/common 9 files changed +13
-19
lines changed Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common
2
2
3
- import io.ktor.client.engine.android.*
4
3
import java.util.Locale
5
4
6
- actual val httpClientEngine = Android .create()
7
-
8
5
actual fun getCountryName (countryCode : String ): String {
9
6
val locale = Locale (" " , countryCode)
10
7
return locale.displayCountry
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package dev.johnoreilly.common.di
3
3
import dev.johnoreilly.common.ui.CountryListScreen
4
4
import dev.johnoreilly.common.ui.NetworkListScreen
5
5
import dev.johnoreilly.common.ui.StationsScreen
6
+ import io.ktor.client.engine.android.Android
6
7
import me.tatarka.inject.annotations.Component
7
8
8
9
@@ -16,5 +17,7 @@ abstract class AndroidApplicationComponent: SharedApplicationComponent {
16
17
abstract val networkListScreen: NetworkListScreen
17
18
abstract val stationsScreen: StationsScreen
18
19
20
+ override fun getHttpClientEngine () = Android .create()
21
+
19
22
companion object
20
23
}
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common.di
2
2
3
- import dev.johnoreilly.common.httpClientEngine
4
3
import dev.johnoreilly.common.remote.CityBikesApi
5
4
import dev.johnoreilly.common.repository.CityBikesRepository
6
5
import dev.johnoreilly.common.repository.NetworkDb
@@ -49,7 +48,10 @@ interface SharedApplicationComponent {
49
48
}
50
49
51
50
@Provides
52
- fun httpClient (): HttpClient = createHttpClient(httpClientEngine, json)
51
+ fun getHttpClientEngine (): HttpClientEngine
52
+
53
+ @Provides
54
+ fun httpClient (): HttpClient = createHttpClient(getHttpClientEngine(), json)
53
55
}
54
56
55
57
fun createHttpClient (httpClientEngine : HttpClientEngine , json : Json ) = HttpClient (httpClientEngine) {
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common
2
2
3
- import io.ktor.client.engine.HttpClientEngine
4
-
5
-
6
- expect val httpClientEngine: HttpClientEngine
7
-
8
3
expect fun getCountryName (countryCode : String ): String
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common
2
2
3
- import io.ktor.client.engine.darwin.Darwin
4
3
import platform.Foundation.NSLocale
5
4
import platform.Foundation.NSLocaleCountryCode
6
5
import platform.Foundation.currentLocale
7
6
8
7
9
- actual val httpClientEngine = Darwin .create()
10
-
11
8
actual fun getCountryName (countryCode : String ): String {
12
9
return NSLocale .currentLocale.displayNameForKey(NSLocaleCountryCode , countryCode) ? : countryCode
13
10
}
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common.di
2
2
3
+ import io.ktor.client.engine.darwin.Darwin
3
4
import me.tatarka.inject.annotations.Component
4
5
5
6
6
7
@Component
7
8
@Singleton
8
9
abstract class IosApplicationComponent : SharedApplicationComponent {
9
10
11
+ override fun getHttpClientEngine () = Darwin .create()
12
+
10
13
companion object
11
14
}
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common
2
2
3
- import io.ktor.client.engine.java.*
4
3
import java.util.Locale
5
4
6
- actual val httpClientEngine = Java .create()
7
-
8
5
actual fun getCountryName (countryCode : String ): String {
9
6
val locale = Locale (" " , countryCode)
10
7
return locale.displayCountry
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common.di
2
2
3
+ import io.ktor.client.engine.java.Java
3
4
import me.tatarka.inject.annotations.Component
4
5
5
6
@Component
6
7
@Singleton
7
8
abstract class DesktopApplicationComponent : SharedApplicationComponent {
8
9
10
+ override fun getHttpClientEngine () = Java .create()
11
+
9
12
companion object
10
13
}
Original file line number Diff line number Diff line change 1
1
package dev.johnoreilly.common
2
2
3
- import io.ktor.client.engine.darwin.Darwin
4
3
import platform.Foundation.NSLocale
5
4
import platform.Foundation.NSLocaleCountryCode
6
5
import platform.Foundation.currentLocale
7
6
8
7
9
- actual val httpClientEngine = Darwin .create()
10
-
11
8
actual fun getCountryName (countryCode : String ): String {
12
9
return NSLocale .currentLocale.displayNameForKey(NSLocaleCountryCode , countryCode) ? : countryCode
13
10
}
You can’t perform that action at this time.
0 commit comments