Skip to content

Commit f4b2f04

Browse files
authored
Merge pull request #73 from stslex/dev
update versions
2 parents 94b3ee3 + 57b2fb0 commit f4b2f04

16 files changed

+185
-191
lines changed

.github/workflows/android_build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111

1212
runs-on: ubuntu-latest
13-
timeout-minutes: 60
13+
timeout-minutes: 15
1414

1515
steps:
1616

@@ -50,4 +50,4 @@ jobs:
5050
run: ./gradlew build
5151

5252
- name: Junit tests with Gradle
53-
run: ./gradlew testDebugUnitTest
53+
run: ./gradlew testDebugUnitTest
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
object AppVersions {
2-
const val VERSION_NAME = "1.70"
3-
const val VERSION_CODE = 16
2+
const val VERSION_NAME = "1.71"
3+
const val VERSION_CODE = 17
44
}

build-logic/dependencies/src/main/kotlin/st.slex.csplashscreen/ComposeAndroid.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1212
* Configure Compose-specific options
1313
*/
1414
internal fun Project.configureAndroidCompose(
15-
commonExtension: CommonExtension<*, *, *, *, *>,
15+
commonExtension: CommonExtension<*, *, *, *, *, *>,
1616
) {
1717
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
1818

build-logic/dependencies/src/main/kotlin/st.slex.csplashscreen/KotlinAndroid.kt

+20-10
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import org.gradle.kotlin.dsl.provideDelegate
1313
import org.gradle.kotlin.dsl.withType
1414
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
1515
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
16+
import org.jetbrains.kotlin.konan.properties.Properties
1617

1718
/**
1819
* Configure base Kotlin with Android options
1920
*/
2021
internal fun Project.configureKotlinAndroid(
21-
commonExtension: CommonExtension<*, *, *, *, *>,
22+
commonExtension: CommonExtension<*, *, *, *, *, *>,
2223
) {
2324
commonExtension.apply {
2425

@@ -27,7 +28,13 @@ internal fun Project.configureKotlinAndroid(
2728
defaultConfig {
2829
minSdk = 28
2930
buildFeatures.buildConfig = true
30-
setLocalProperty(project.rootProject)
31+
32+
gradleLocalProperties(
33+
projectRootDir = project.rootProject.projectDir,
34+
providers = providers
35+
).let { properties ->
36+
setLocalProperties(properties)
37+
}
3138
}
3239

3340
compileOptions {
@@ -69,7 +76,7 @@ internal fun Project.configureKotlinAndroid(
6976
}
7077
}
7178

72-
private fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
79+
private fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
7380
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
7481
}
7582

@@ -108,12 +115,15 @@ private fun Project.configureKotlin() {
108115
}
109116
}
110117

111-
112-
fun DefaultConfig.setLocalProperty(
113-
dir: Project
118+
fun DefaultConfig.setLocalProperties(
119+
properties: Properties
114120
) {
115-
val key = gradleLocalProperties(dir.projectDir)["API_KEY"]
116-
?.toString()
117-
?: throw IllegalStateException("API_KEY should be initialised")
118-
buildConfigField("String", "API_KEY", key)
121+
LocalProperties.values().forEach { property ->
122+
properties[property.key]
123+
?.toString()
124+
?.let { value ->
125+
buildConfigField(property.type, property.buildName, value)
126+
}
127+
?: throw IllegalStateException("API_KEY should be initialised")
128+
}
119129
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package st.slex.csplashscreen
22

3-
internal object LocalPropertiesConstants {
4-
const val API_KEY = "API_KEY"
3+
enum class LocalProperties(
4+
val key: String,
5+
val buildName: String,
6+
val type: String,
7+
) {
8+
API_KEY(
9+
key = "API_KEY",
10+
buildName = "API_KEY",
11+
type = "String",
12+
)
513
}

build.gradle.kts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
32
plugins {
43
alias(libs.plugins.application) apply false
54
alias(libs.plugins.kotlin) apply false
65
alias(libs.plugins.library) apply false
76
alias(libs.plugins.serialization)
87
alias(libs.plugins.ksp) apply false
98
}
10-
true // Needed to make the Suppress annotation work for the plugins block
119

1210
buildscript {
1311

@@ -18,5 +16,5 @@ buildscript {
1816
}
1917

2018
tasks.register(name = "type", type = Delete::class) {
21-
delete(rootProject.buildDir)
19+
delete(rootProject.projectDir.resolve("build"))
2220
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
package st.slex.csplashscreen.core.network.client
22

33
import io.ktor.client.HttpClient
4+
import io.ktor.client.call.body
5+
import io.ktor.client.request.HttpRequestBuilder
6+
import io.ktor.client.request.get
47

58
interface NetworkClient {
69

710
suspend fun <T> request(request: suspend HttpClient.() -> T): T
811
}
12+
13+
internal suspend inline fun <reified T> NetworkClient.get(
14+
crossinline builder: suspend HttpRequestBuilder.() -> Unit
15+
): T = request {
16+
get {
17+
builder()
18+
}.body()
19+
}

core/network/src/main/java/st/slex/csplashscreen/core/network/client/NetworkClientBuilder.kt

-67
This file was deleted.

core/network/src/main/java/st/slex/csplashscreen/core/network/client/NetworkClientImpl.kt

+63-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package st.slex.csplashscreen.core.network.client
22

33
import io.ktor.client.HttpClient
4+
import io.ktor.client.HttpClientConfig
45
import io.ktor.client.engine.android.Android
6+
import io.ktor.client.engine.android.AndroidEngineConfig
57
import io.ktor.client.plugins.cache.HttpCache
8+
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
9+
import io.ktor.client.plugins.defaultRequest
10+
import io.ktor.client.plugins.logging.ANDROID
11+
import io.ktor.client.plugins.logging.EMPTY
12+
import io.ktor.client.plugins.logging.LogLevel
13+
import io.ktor.client.plugins.logging.Logger
14+
import io.ktor.client.plugins.logging.Logging
15+
import io.ktor.client.request.headers
16+
import io.ktor.http.URLProtocol
17+
import io.ktor.serialization.kotlinx.json.json
618
import kotlinx.coroutines.withContext
19+
import kotlinx.serialization.ExperimentalSerializationApi
20+
import kotlinx.serialization.json.Json
721
import st.slex.csplashscreen.core.core.coroutine.AppDispatcher
8-
import st.slex.csplashscreen.core.network.client.NetworkClientBuilder.setupDefaultRequest
9-
import st.slex.csplashscreen.core.network.client.NetworkClientBuilder.setupLogging
10-
import st.slex.csplashscreen.core.network.client.NetworkClientBuilder.setupNegotiation
22+
import st.slex.csplashscreen.core.network.BuildConfig
1123
import javax.inject.Inject
1224
import javax.inject.Singleton
1325

@@ -29,4 +41,52 @@ class NetworkClientImpl @Inject constructor(
2941
expectSuccess = true
3042
setupDefaultRequest()
3143
}
44+
45+
@OptIn(ExperimentalSerializationApi::class)
46+
fun HttpClientConfig<AndroidEngineConfig>.setupNegotiation() {
47+
install(ContentNegotiation) {
48+
json(
49+
Json {
50+
prettyPrint = true
51+
isLenient = true
52+
ignoreUnknownKeys = true
53+
explicitNulls = false
54+
}
55+
)
56+
}
57+
}
58+
59+
fun HttpClientConfig<AndroidEngineConfig>.setupDefaultRequest() {
60+
defaultRequest {
61+
url {
62+
host = HOST_URL
63+
protocol = URLProtocol.HTTPS
64+
}
65+
headers {
66+
append(
67+
HEADER_AUTH,
68+
"$HEADER_AUTH_FIELD ${BuildConfig.API_KEY}"
69+
)
70+
}
71+
}
72+
}
73+
74+
fun HttpClientConfig<AndroidEngineConfig>.setupLogging() {
75+
install(Logging) {
76+
logger = when (st.slex.csplashscreen.core.core.BuildConfig.DEBUG) {
77+
true -> Logger.ANDROID
78+
false -> Logger.EMPTY
79+
}
80+
level = when (st.slex.csplashscreen.core.core.BuildConfig.DEBUG) {
81+
true -> LogLevel.ALL
82+
false -> LogLevel.NONE
83+
}
84+
}
85+
}
86+
87+
companion object {
88+
private const val HOST_URL = "api.unsplash.com"
89+
private const val HEADER_AUTH = "Authorization"
90+
private const val HEADER_AUTH_FIELD = "Client-ID"
91+
}
3292
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package st.slex.csplashscreen.core.network.source.impl
22

3-
import io.ktor.client.call.body
4-
import io.ktor.client.request.get
53
import io.ktor.client.request.parameter
64
import io.ktor.http.appendPathSegments
75
import st.slex.csplashscreen.core.network.client.NetworkClient
6+
import st.slex.csplashscreen.core.network.client.get
87
import st.slex.csplashscreen.core.network.model.remote.collection.RemoteCollectionModel
98
import st.slex.csplashscreen.core.network.source.interf.CollectionNetworkClient
109
import st.slex.csplashscreen.core.network.utils.ServiceConstants.PARAMETER_PAGE
@@ -22,24 +21,19 @@ class CollectionNetworkClientImpl @Inject constructor(
2221
override suspend fun getCollections(
2322
page: Int,
2423
pageSize: Int
25-
): List<RemoteCollectionModel> = client.request {
26-
get {
27-
url.appendPathSegments(PATH_COLLECTIONS)
28-
parameter(PARAMETER_PAGE, page)
29-
parameter(PARAMETER_PAGE_SIZE, pageSize)
30-
}.body()
24+
): List<RemoteCollectionModel> = client.get {
25+
url.appendPathSegments(PATH_COLLECTIONS)
26+
parameter(PARAMETER_PAGE, page)
27+
parameter(PARAMETER_PAGE_SIZE, pageSize)
3128
}
3229

33-
3430
override suspend fun getUserCollections(
3531
username: String,
3632
page: Int,
3733
pageSize: Int
38-
): List<RemoteCollectionModel> = client.request {
39-
get {
40-
url.appendPathSegments(PATH_USERS, username, PATH_COLLECTIONS)
41-
parameter(PARAMETER_PAGE, page)
42-
parameter(PARAMETER_PAGE_SIZE, pageSize)
43-
}.body()
34+
): List<RemoteCollectionModel> = client.get {
35+
url.appendPathSegments(PATH_USERS, username, PATH_COLLECTIONS)
36+
parameter(PARAMETER_PAGE, page)
37+
parameter(PARAMETER_PAGE_SIZE, pageSize)
4438
}
4539
}

0 commit comments

Comments
 (0)