Skip to content

Commit

Permalink
Merge pull request #73 from stslex/dev
Browse files Browse the repository at this point in the history
update versions
  • Loading branch information
stslex authored Mar 31, 2024
2 parents 94b3ee3 + 57b2fb0 commit f4b2f04
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 191 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 15

steps:

Expand Down Expand Up @@ -50,4 +50,4 @@ jobs:
run: ./gradlew build

- name: Junit tests with Gradle
run: ./gradlew testDebugUnitTest
run: ./gradlew testDebugUnitTest
4 changes: 2 additions & 2 deletions build-logic/dependencies/src/main/kotlin/AppVersions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object AppVersions {
const val VERSION_NAME = "1.70"
const val VERSION_CODE = 16
const val VERSION_NAME = "1.71"
const val VERSION_CODE = 17
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
* Configure Compose-specific options
*/
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.konan.properties.Properties

/**
* Configure base Kotlin with Android options
*/
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
commonExtension.apply {

Expand All @@ -27,7 +28,13 @@ internal fun Project.configureKotlinAndroid(
defaultConfig {
minSdk = 28
buildFeatures.buildConfig = true
setLocalProperty(project.rootProject)

gradleLocalProperties(
projectRootDir = project.rootProject.projectDir,
providers = providers
).let { properties ->
setLocalProperties(properties)
}
}

compileOptions {
Expand Down Expand Up @@ -69,7 +76,7 @@ internal fun Project.configureKotlinAndroid(
}
}

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

Expand Down Expand Up @@ -108,12 +115,15 @@ private fun Project.configureKotlin() {
}
}


fun DefaultConfig.setLocalProperty(
dir: Project
fun DefaultConfig.setLocalProperties(
properties: Properties
) {
val key = gradleLocalProperties(dir.projectDir)["API_KEY"]
?.toString()
?: throw IllegalStateException("API_KEY should be initialised")
buildConfigField("String", "API_KEY", key)
LocalProperties.values().forEach { property ->
properties[property.key]
?.toString()
?.let { value ->
buildConfigField(property.type, property.buildName, value)
}
?: throw IllegalStateException("API_KEY should be initialised")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package st.slex.csplashscreen

internal object LocalPropertiesConstants {
const val API_KEY = "API_KEY"
enum class LocalProperties(
val key: String,
val buildName: String,
val type: String,
) {
API_KEY(
key = "API_KEY",
buildName = "API_KEY",
type = "String",
)
}
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.application) apply false
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.library) apply false
alias(libs.plugins.serialization)
alias(libs.plugins.ksp) apply false
}
true // Needed to make the Suppress annotation work for the plugins block

buildscript {

Expand All @@ -18,5 +16,5 @@ buildscript {
}

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

import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.get

interface NetworkClient {

suspend fun <T> request(request: suspend HttpClient.() -> T): T
}

internal suspend inline fun <reified T> NetworkClient.get(
crossinline builder: suspend HttpRequestBuilder.() -> Unit
): T = request {
get {
builder()
}.body()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package st.slex.csplashscreen.core.network.client

import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.android.Android
import io.ktor.client.engine.android.AndroidEngineConfig
import io.ktor.client.plugins.cache.HttpCache
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.plugins.logging.ANDROID
import io.ktor.client.plugins.logging.EMPTY
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.request.headers
import io.ktor.http.URLProtocol
import io.ktor.serialization.kotlinx.json.json
import kotlinx.coroutines.withContext
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import st.slex.csplashscreen.core.core.coroutine.AppDispatcher
import st.slex.csplashscreen.core.network.client.NetworkClientBuilder.setupDefaultRequest
import st.slex.csplashscreen.core.network.client.NetworkClientBuilder.setupLogging
import st.slex.csplashscreen.core.network.client.NetworkClientBuilder.setupNegotiation
import st.slex.csplashscreen.core.network.BuildConfig
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -29,4 +41,52 @@ class NetworkClientImpl @Inject constructor(
expectSuccess = true
setupDefaultRequest()
}

@OptIn(ExperimentalSerializationApi::class)
fun HttpClientConfig<AndroidEngineConfig>.setupNegotiation() {
install(ContentNegotiation) {
json(
Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
explicitNulls = false
}
)
}
}

fun HttpClientConfig<AndroidEngineConfig>.setupDefaultRequest() {
defaultRequest {
url {
host = HOST_URL
protocol = URLProtocol.HTTPS
}
headers {
append(
HEADER_AUTH,
"$HEADER_AUTH_FIELD ${BuildConfig.API_KEY}"
)
}
}
}

fun HttpClientConfig<AndroidEngineConfig>.setupLogging() {
install(Logging) {
logger = when (st.slex.csplashscreen.core.core.BuildConfig.DEBUG) {
true -> Logger.ANDROID
false -> Logger.EMPTY
}
level = when (st.slex.csplashscreen.core.core.BuildConfig.DEBUG) {
true -> LogLevel.ALL
false -> LogLevel.NONE
}
}
}

companion object {
private const val HOST_URL = "api.unsplash.com"
private const val HEADER_AUTH = "Authorization"
private const val HEADER_AUTH_FIELD = "Client-ID"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package st.slex.csplashscreen.core.network.source.impl

import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.http.appendPathSegments
import st.slex.csplashscreen.core.network.client.NetworkClient
import st.slex.csplashscreen.core.network.client.get
import st.slex.csplashscreen.core.network.model.remote.collection.RemoteCollectionModel
import st.slex.csplashscreen.core.network.source.interf.CollectionNetworkClient
import st.slex.csplashscreen.core.network.utils.ServiceConstants.PARAMETER_PAGE
Expand All @@ -22,24 +21,19 @@ class CollectionNetworkClientImpl @Inject constructor(
override suspend fun getCollections(
page: Int,
pageSize: Int
): List<RemoteCollectionModel> = client.request {
get {
url.appendPathSegments(PATH_COLLECTIONS)
parameter(PARAMETER_PAGE, page)
parameter(PARAMETER_PAGE_SIZE, pageSize)
}.body()
): List<RemoteCollectionModel> = client.get {
url.appendPathSegments(PATH_COLLECTIONS)
parameter(PARAMETER_PAGE, page)
parameter(PARAMETER_PAGE_SIZE, pageSize)
}


override suspend fun getUserCollections(
username: String,
page: Int,
pageSize: Int
): List<RemoteCollectionModel> = client.request {
get {
url.appendPathSegments(PATH_USERS, username, PATH_COLLECTIONS)
parameter(PARAMETER_PAGE, page)
parameter(PARAMETER_PAGE_SIZE, pageSize)
}.body()
): List<RemoteCollectionModel> = client.get {
url.appendPathSegments(PATH_USERS, username, PATH_COLLECTIONS)
parameter(PARAMETER_PAGE, page)
parameter(PARAMETER_PAGE_SIZE, pageSize)
}
}
Loading

0 comments on commit f4b2f04

Please sign in to comment.