Skip to content

Commit fac5e57

Browse files
committed
use buildkonfig to access api key
1 parent cc47538 commit fac5e57

5 files changed

Lines changed: 38 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ The `androidApp` module depends on and uses the `shared` module as a regular And
144144
This is an Xcode project that builds into an iOS application.
145145
It depends on and uses the `shared` module as a CocoaPods dependency.
146146

147+
## How to get started
148+
149+
In `local.properties` file:
150+
Generate the API key from [Unsplash API](https://unsplash.com/developers), place the key as `unsplash_api_token=<YOUR_API_KEY_HERE>`.
151+
147152
## Star History
148153

149154
[![Star History Chart](https://api.star-history.com/svg?repos=pushpalroy/JetTaskBoardKMP)](https://star-history.com/#pushpalroy/JetTaskBoardKMP)

gradle/libs.versions.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[versions]
22

33
insetsx = "0.1.0-alpha10"
4+
kfile-picker = "1.0.0"
45
kotlin = "1.9.21"
56
agp = "8.2.0"
67
compose = "1.5.11"
@@ -19,11 +20,11 @@ ktorClientContentNegotiation = "2.3.0"
1920
ktorClientCore = "2.3.0"
2021
ktorClientLogging = "2.3.2"
2122
ktorClientOkhttp = "2.3.0"
22-
ktorSerializationKotlinxJson = "2.3.0"
2323
mpfilepicker = "1.1.0"
2424
multiplatformSettingsNoArg = "1.0.0"
2525
napier = "2.6.1"
2626
slf4jSimple = "2.0.7"
27+
buildkonfig = "0.15.1"
2728

2829
[libraries]
2930

@@ -33,6 +34,7 @@ compose-uitooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "
3334
compose-ui-util = { module = "org.jetbrains.compose.ui:ui-util", version.ref = "compose" }
3435

3536
insetsx = { module = "com.moriatsushi.insetsx:insetsx", version.ref = "insetsx" }
37+
desktop-kfile-picker = { module = "com.github.Tlaster.KFilePicker:KFilePicker", version.ref = "kfile-picker" }
3638
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
3739
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
3840

@@ -66,8 +68,10 @@ slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4jSimple"
6668

6769
[plugins]
6870

69-
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
71+
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
7072
cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
7173
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
7274
android-application = { id = "com.android.application", version.ref = "agp" }
75+
androidLibrary = { id = "com.android.library", version.ref = "agp" }
7376
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
77+
buildkonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildkonfig" }

shared/build.gradle.kts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import org.jetbrains.compose.compose
2+
import java.util.Properties
3+
import com.codingfeline.buildkonfig.compiler.FieldSpec
24

35
plugins {
46
kotlin("multiplatform")
57
kotlin("native.cocoapods")
68
alias(libs.plugins.kotlinx.serialization)
7-
id("com.android.library")
9+
alias(libs.plugins.buildkonfig)
10+
alias(libs.plugins.androidLibrary)
811
id("org.jetbrains.compose")
912
id("kotlin-parcelize")
1013
}
@@ -101,7 +104,7 @@ kotlin {
101104
implementation(compose.desktop.common)
102105
implementation(libs.ktor.client.okhttp.v230)
103106
implementation(libs.slf4j.simple)
104-
implementation("com.github.Tlaster.KFilePicker:KFilePicker:1.0.0")
107+
implementation(libs.desktop.kfile.picker)
105108
implementation(libs.mpfilepicker)
106109
}
107110
}
@@ -114,7 +117,6 @@ android {
114117

115118
defaultConfig {
116119
minSdk = (findProperty("android.minSdk") as String).toInt()
117-
targetSdk = (findProperty("android.targetSdk") as String).toInt()
118120
}
119121
sourceSets["main"].apply {
120122
manifest.srcFile("src/androidMain/AndroidManifest.xml")
@@ -129,3 +131,23 @@ android {
129131
jvmToolchain(11)
130132
}
131133
}
134+
135+
val localProperties = Properties()
136+
localProperties.load(rootProject.file("local.properties").reader())
137+
138+
buildkonfig {
139+
packageName = "com.jettaskboard.multiplatform"
140+
val props = Properties()
141+
try {
142+
props.load(file("../local.properties").inputStream())
143+
} catch (e: Exception) {
144+
}
145+
146+
defaultConfigs {
147+
buildConfigField(
148+
FieldSpec.Type.STRING,
149+
"UNSPLASH_API_TOKEN",
150+
props["unsplash_api_token"]?.toString() ?: ""
151+
)
152+
}
153+
}

shared/src/commonMain/kotlin/com.jettaskboard.multiplatform/data/util/Constants.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ object Constants {
44
const val BASE_URL = "https://api.unsplash.com/"
55
const val PHOTOS_RANDOM_ENDPOINT = "photos/random"
66
const val PHOTOS_SEARCH_ENDPOINT = "search/photos"
7-
const val CLIENT_ID = "enter-your-api-key-here"
87

98
const val PARAM_AUTH_CLIENT_ID = "client_id"
109
const val PARAM_QUERY_PER_PAGE = "per_page"

shared/src/commonMain/kotlin/com.jettaskboard.multiplatform/di/NetworkModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.jettaskboard.multiplatform.di
22

3+
import com.jettaskboard.multiplatform.BuildKonfig
34
import com.jettaskboard.multiplatform.data.util.Constants
45
import com.jettaskboard.multiplatform.util.logger.initLogger
56
import io.github.aakira.napier.Napier
@@ -43,7 +44,7 @@ val networkModule = module {
4344
url {
4445
url(Constants.BASE_URL)
4546
protocol = URLProtocol.HTTPS
46-
parameters.append(Constants.PARAM_AUTH_CLIENT_ID, Constants.CLIENT_ID)
47+
parameters.append(Constants.PARAM_AUTH_CLIENT_ID, BuildKonfig.UNSPLASH_API_TOKEN)
4748
}
4849
}
4950
}

0 commit comments

Comments
 (0)