Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions build-logic/src/main/java/Config.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
object Config {
const val applicationId = "com.codandotv.streamplayerapp"
const val appName = "streamplayerapp"
const val applicationId = "com.codandotv.$appName"
const val compileSdkVersion = 34
const val minSdkVersion = 24
const val targetSdkVersion = 34
Expand All @@ -8,17 +9,18 @@ object Config {
const val testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

object BuildField {
const val host_debug = "\"https://api.themoviedb.org/3/\""
const val host_release = "\"https://api.themoviedb.org/3/\""
const val api_profile_debug = "\"https://demo3364084.mockable.io/\""
const val api_profile_release = "\"https://demo3364084.mockable.io/\""
const val host_debug = "https://api.themoviedb.org/3/"
const val host_release = "https://api.themoviedb.org/3/"
const val api_profile_debug = "https://demo3364084.mockable.io/"
const val api_profile_release = "https://demo3364084.mockable.io/"

private const val tmdb_token_name_debug = "TMDB_BEARER_TOKEN_DEBUG"
private const val tmdb_token_name_release = "TMDB_BEARER_TOKEN_RELEASE"

private const val bearear_without_environment = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJiNDg2NWM4YTAzNzhmM2I4NjI0OWU1ZjNiYWFiMjU2NyIsInN1YiI6IjY0Mjk4YTg5YTNlNGJhMWM0NDgzM2U4OCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.9cIxv29vkaZ2yW88DIFRUFK_nXbK2b6KS8t96kA8WAE"

val api_bearer_debug = "\"${System.getenv(tmdb_token_name_debug) ?: bearear_without_environment}\""
val api_bearer_release = "\"${System.getenv(tmdb_token_name_release) ?: bearear_without_environment}\""
val api_bearer = System.getenv(tmdb_token_name_debug) ?: bearear_without_environment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aqui mesma coisa

val api_bearer_debug = System.getenv(tmdb_token_name_debug) ?: bearear_without_environment
val api_bearer_release = System.getenv(tmdb_token_name_release) ?: bearear_without_environment
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import extensions.dokkaPlugin
import extensions.getLibrary
import extensions.iosTarget
import extensions.setupAndroidDefaultConfig
import extensions.setupCompileOptions
import extensions.setupPackingOptions
Expand All @@ -28,6 +29,8 @@ kotlin {
jvmTarget.set(JvmTarget.JVM_17)
}
}

iosTarget()
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import extensions.dokkaPlugin
import extensions.getLibrary
import extensions.iosTarget
import extensions.setupAndroidDefaultConfig
import extensions.setupCompileOptions
import extensions.setupNameSpace
Expand Down Expand Up @@ -29,6 +30,8 @@ kotlin {
jvmTarget.set(JvmTarget.JVM_17)
}
}

iosTarget()
}

android {
Expand Down
17 changes: 17 additions & 0 deletions build-logic/src/main/java/extensions/KotlinMultiPlatformExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package extensions

import Config
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

fun KotlinMultiplatformExtension.iosTarget() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define iosTarget, but not implementing it yet

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = Config.appName
isStatic = true
}
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
alias(libs.plugins.ksp) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.kover) apply false
alias(libs.plugins.buildkonfig.plugin) apply false
}

tasks.register("clean", Delete::class) {
Expand Down
12 changes: 8 additions & 4 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ plugins {
}
kotlin {
sourceSets {
androidMain.dependencies {
implementation(libs.koin.android)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Koin android is android specific

implementation(libs.lottie)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lottie is also android specific

}
commonMain.dependencies {
implementation(projects.featureListStreams)
implementation(projects.featureDetail)
Expand All @@ -19,13 +23,13 @@ kotlin {
implementation(projects.coreLocalStorage)

implementation(libs.navigation.compose)

implementation(compose.material3)
implementation(compose.ui)
implementation(compose.preview)
implementation(libs.bundles.koin)
implementation(libs.bundles.androidSupport)
implementation(libs.bundles.kotlin)
implementation(libs.lottie)

implementation(libs.koin.core)
implementation(libs.koin.compose)
}
}
}
Expand Down
17 changes: 1 addition & 16 deletions core-local-storage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,8 @@ kotlin {
commonMain.dependencies {
implementation(libs.room.bundled)
implementation(libs.room.runtime)
implementation(libs.bundles.kotlin)
implementation(libs.bundles.koin)
}
}

listOf(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this definition to the base conventional plugin

iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "composeApp"
isStatic = true
implementation(libs.koin.core)
}
}
}
Expand All @@ -33,10 +22,6 @@ dependencies {
add("kspIosArm64", libs.room.compiler)
}

configurations.implementation{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need it anymore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This we need (bringing back):

   add("kspIosSimulatorArm64", libs.room.compiler)
    add("kspIosX64", libs.room.compiler)
    add("kspIosArm64", libs.room.compiler)

what we don't need is:

configurations.implementation...

exclude(group = "com.intellij", module = "annotations")
}

room {
schemaDirectory("$projectDir/schemas")
}
2 changes: 1 addition & 1 deletion core-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ plugins {
kotlin {
sourceSets {
commonMain.dependencies {
implementation(libs.bundles.kotlin)
implementation(libs.navigation.compose)

implementation(compose.material3)
implementation(compose.components.resources)
}
Expand Down
49 changes: 32 additions & 17 deletions core-networking/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
import com.codingfeline.buildkonfig.compiler.FieldSpec
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding BuildKonfig to deal with the build config variables in multiplatform world

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep buildtype release, cause is good example how to use


plugins {
id("com.streamplayer.kmp-library")
alias(libs.plugins.jetbrains.compose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.buildkonfig.plugin)
}

android {
buildFeatures {
buildConfig = true
buildkonfig {
packageName = "core.networking"

defaultConfigs {
buildConfigField(FieldSpec.Type.STRING, "HOST", Config.BuildField.host_debug)
buildConfigField(FieldSpec.Type.STRING, "API_BEARER_AUTH", Config.BuildField.api_bearer_debug)
buildConfigField(FieldSpec.Type.STRING, "PROFILE", Config.BuildField.api_profile_debug)
}
buildTypes {
debug {
buildConfigField("String", "HOST", Config.BuildField.host_debug)
buildConfigField("String", "API_BEARER_AUTH", Config.BuildField.api_bearer_debug)
buildConfigField("String", "PROFILE", Config.BuildField.api_profile_debug)

}
getByName("release") {
buildConfigField("String", "HOST", Config.BuildField.host_release)
buildConfigField("String", "API_BEARER_AUTH", Config.BuildField.api_bearer_release)
buildConfigField("String", "PROFILE", Config.BuildField.api_profile_release)
}
defaultConfigs("release") {
buildConfigField(FieldSpec.Type.STRING, "HOST", Config.BuildField.host_release)
buildConfigField(FieldSpec.Type.STRING, "API_BEARER_AUTH", Config.BuildField.api_bearer_release)
buildConfigField(FieldSpec.Type.STRING, "PROFILE", Config.BuildField.api_profile_release)
}
}

kotlin {
sourceSets {
commonMain.dependencies {
implementation(libs.bundles.kotlin)
implementation(libs.bundles.networking)
implementation(libs.bundles.koin)
implementation(libs.kotlin.stdlib)

implementation(libs.koin.core)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.content.serialization.json)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.logger)
implementation(libs.ktor.client.auth)

implementation(compose.components.resources)
implementation(compose.runtime)
}

androidMain.dependencies {
implementation(libs.okhttp)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android specific network dependencies


implementation(libs.interceptor)

implementation(libs.ktor.client.okhttp)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codandotv.streamplayerapp.core_networking

import io.ktor.client.engine.HttpClientEngine
import io.ktor.client.engine.okhttp.OkHttpConfig
import io.ktor.client.engine.okhttp.OkHttpEngine

actual fun httpClientEnginePlatform() : HttpClientEngine = OkHttpEngine(OkHttpConfig())
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:Suppress("EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE")

package com.codandotv.streamplayerapp.core_networking

import io.ktor.client.engine.HttpClientEngine

expect fun httpClientEnginePlatform(): HttpClientEngine
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.codandotv.streamplayerapp.core_networking.di

import android.util.Log
import com.codandotv.streamplayerapp.core.networking.BuildConfig
import com.codandotv.streamplayerapp.core_networking.di.Network.TIMEOUT
import com.codandotv.streamplayerapp.core_networking.handleError.validator
import com.squareup.moshi.Moshi
import com.codandotv.streamplayerapp.core_networking.httpClientEnginePlatform
import core.networking.BuildKonfig
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.engine.okhttp.OkHttpConfig
import io.ktor.client.plugins.HttpResponseValidator
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.providers.BearerTokens
Expand All @@ -23,81 +18,63 @@ import io.ktor.client.request.accept
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
import org.koin.dsl.module

object NetworkModule {
val module = module {
single(QualifierHost) { BuildConfig.HOST }
single(QualifierProfile) { BuildConfig.PROFILE }
single(QualifierHost) { BuildKonfig.HOST }
single(QualifierProfile) { BuildKonfig.PROFILE }

single {
provideKtorHttpClient(
moshi = get(),
baseUrl = get(QualifierHost),
)
}

single(QualifierProfileHttpClient) {
provideKtorHttpClient(
moshi = get(),
baseUrl = get(QualifierProfile),
)
}

single { Moshi.Builder().build() }
}

private fun provideKtorHttpClient(
moshi: Moshi,
baseUrl: String,
): HttpClient {
return HttpClient(OkHttp) {
installPlugins(moshi, baseUrl)
}
}

private fun HttpClientConfig<OkHttpConfig>.installPlugins(
moshi: Moshi,
baseUrl: String,
) {
expectSuccess = false

install(ContentNegotiation) {
json(Json {
explicitNulls = false
ignoreUnknownKeys = true
})
}
return HttpClient(engine = httpClientEnginePlatform()) {
expectSuccess = false

install(HttpTimeout) {
socketTimeoutMillis = TIMEOUT
requestTimeoutMillis = TIMEOUT
connectTimeoutMillis = TIMEOUT
}
install(ContentNegotiation) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

não entendi, pq precisou mudar essas coisas

json(Json {
explicitNulls = false
ignoreUnknownKeys = true
})
}

defaultRequest {
url(baseUrl)
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
}
install(HttpTimeout) {
socketTimeoutMillis = TIMEOUT
requestTimeoutMillis = TIMEOUT
connectTimeoutMillis = TIMEOUT
}

validator(moshi)
defaultRequest {
url(baseUrl)
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
}

install(Auth) {
bearer {
loadTokens {
BearerTokens(
accessToken = BuildConfig.API_BEARER_AUTH,
refreshToken = ""
)
install(Auth) {
bearer {
loadTokens {
BearerTokens(
accessToken = BuildKonfig.API_BEARER_AUTH,
refreshToken = ""
)
}
}
}
}

if (BuildConfig.DEBUG) {
install(Logging) {
level = LogLevel.ALL
logger = object : Logger {
Expand All @@ -110,6 +87,6 @@ object NetworkModule {
}
}

internal object Network{
internal object Network {
const val TIMEOUT = 10000L
}
Loading