diff --git a/.gitignore b/.gitignore
index 4001a583fe58789836ec2b83a7e419bd4e5e6707..258f931099b5dee40995683214fc8264aa34f5eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,4 @@
.externalNativeBuild
.cxx
local.properties
-**/build/
\ No newline at end of file
+**/build/
diff --git a/android/build.gradle.kts b/android/build.gradle.kts
index 4e4f76b07336bff08125eeea689f79cfd65c1a39..e82f3b5c0f260c6a32256c990786ddc2e6b0c067 100644
--- a/android/build.gradle.kts
+++ b/android/build.gradle.kts
@@ -22,7 +22,7 @@ android {
versionProps["VERSION_CHANGE"] = "0"
versionProps["VERSION_MAJOR"] = "1"
versionProps["VERSION_MINOR"] = "0"
- versionProps["VERSION_PATCH"] = "0"
+ versionProps["VERSION_PATCH"] = "1"
versionProps["VERSION_CODE"] = "1"
versionProps.store(versionPropsFile.writer(), null)
}
diff --git a/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsActivity.kt b/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsActivity.kt
index b8082ded2db89bd488686fd89be6a1fb5fd1a2b5..184c238dc03a0f2c003d0c0184c925cb8ef4045a 100644
--- a/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsActivity.kt
+++ b/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsActivity.kt
@@ -103,7 +103,6 @@ class SettingsActivity : FragmentActivity(), OnSharedPreferenceChangeListener {
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) {
- Constants.WEATHER_API_KEY -> viewModel.onApiKeyChanged()
Constants.WEATHER_CUSTOM_LOCATION_CITY -> viewModel.onCustomLocationSet()
else -> sendBroadcast(refreshIntent)
}
diff --git a/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsViewModel.kt b/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsViewModel.kt
index ef7a9b138e62e5142f0cb71ec9845c6306fca6c4..ca03ff3f1094c3d74e6625da88f867afde515fcb 100644
--- a/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsViewModel.kt
+++ b/android/src/main/kotlin/foundation/e/blissweather/settings/SettingsViewModel.kt
@@ -48,10 +48,6 @@ constructor(
viewModelScope.launch { onCustomLocationSetImpl() }
}
- fun onApiKeyChanged() {
- viewModelScope.launch { onApiKeyChangedImpl() }
- }
-
fun setCoordinate(coordinate: Coordinate) {
appPreferences.weatherCustomLocationLat = coordinate.lat
appPreferences.weatherCustomLocationLon = coordinate.lon
@@ -82,20 +78,4 @@ constructor(
}
}
}
-
- private suspend fun onApiKeyChangedImpl() {
- when (val result = repository.getWeatherByLocationName("London")) {
- is ApiError -> {
- if (result.code == 401) {
- appPreferences.weatherApiKey = null
- _status.emit("Invalid API Key")
- }
- }
- is ApiException -> {
- appPreferences.weatherApiKey = null
- _status.emit(result.e.message ?: "Unknown error")
- }
- else -> {}
- }
- }
}
diff --git a/android/src/main/res/values-de/strings.xml b/android/src/main/res/values-de/strings.xml
index f5c3e9d54ff806513b66b381e617331bb69708f9..a71b906e7d6b6853e7323e57c5e11679bde901cb 100644
--- a/android/src/main/res/values-de/strings.xml
+++ b/android/src/main/res/values-de/strings.xml
@@ -45,9 +45,6 @@
W
NW
OpenWeather
- API-Schlüssel
- **********
- Geben Sie Ihren eigenen API-Schlüssel an
BlissWetter
NO
%1d%%, %2d%3s
diff --git a/android/src/main/res/values-es/strings.xml b/android/src/main/res/values-es/strings.xml
index 1cb035b54f5b9f93b1ea2e7ca7fcf63d937a8bef..dae46e74a5bc25973a7987ae0533e1a8925b5a3b 100644
--- a/android/src/main/res/values-es/strings.xml
+++ b/android/src/main/res/values-es/strings.xml
@@ -48,8 +48,5 @@
O
NO
OpenWeather
- Código API
- **********
- Introduce tu propia clave API
BlissWeather
\ No newline at end of file
diff --git a/android/src/main/res/values-fr/strings.xml b/android/src/main/res/values-fr/strings.xml
index 6be3e531b49007331b5f9415e66ae082ef390fb7..4abd8ac66bebd8b3e5f1e5381a3d549eccd58f64 100644
--- a/android/src/main/res/values-fr/strings.xml
+++ b/android/src/main/res/values-fr/strings.xml
@@ -36,11 +36,9 @@
Utiliser le système métrique (°C)
Météo
Appuyer pour configurer la météo
- Saisissez votre propre clé d\'API
SO
O
NO
- Clé de l\'API
N
NE
E
diff --git a/android/src/main/res/values-is/strings.xml b/android/src/main/res/values-is/strings.xml
index 22629ea1d681ba693cb61a298b4d0b906f3890e0..24e9fd902c8c45786b795d6e2eef96b808bdd7ed 100644
--- a/android/src/main/res/values-is/strings.xml
+++ b/android/src/main/res/values-is/strings.xml
@@ -48,8 +48,5 @@
V
NV
OpenWeather
- API-lykill
- **********
- Settu inn þinn eigin API-lykil
%1d%%, %2d%3s
\ No newline at end of file
diff --git a/android/src/main/res/values-it/strings.xml b/android/src/main/res/values-it/strings.xml
index 14ca2202c40bbdbf57596c2f962ff644924ff703..22738395c032fdd8301339e50cbf7845745618bb 100644
--- a/android/src/main/res/values-it/strings.xml
+++ b/android/src/main/res/values-it/strings.xml
@@ -47,9 +47,6 @@
O
NO
OpenWeather
- Chiave API
- **********
- Inserisci la tua chiave API
%1d%%, %2d%3s
N
\ No newline at end of file
diff --git a/android/src/main/res/values-ja/strings.xml b/android/src/main/res/values-ja/strings.xml
index 86209593ed44f5bca7099b14b4b0caeed911dacf..4ee17ae2bfe8e8f75cb93e895b98051e3e345799 100644
--- a/android/src/main/res/values-ja/strings.xml
+++ b/android/src/main/res/values-ja/strings.xml
@@ -6,7 +6,6 @@
位置情報
°C
OpenWeather
- APIキー
更新間隔
表示設定
時速キロメートル
@@ -27,8 +26,6 @@
天気
タップして天気を設定
%1d%%, %2d%3s
- **********
- API鍵を入力してください
°F
北
北東
diff --git a/android/src/main/res/values-nl/strings.xml b/android/src/main/res/values-nl/strings.xml
index a86920654c6e0f09bccbdc6073443e7724b43f1e..7bed8044be7a2498cd71c4229a875742fd138174 100644
--- a/android/src/main/res/values-nl/strings.xml
+++ b/android/src/main/res/values-nl/strings.xml
@@ -47,8 +47,6 @@
ZW
NW
OpenWeather
- Vul je eigen API sleutel in
- API Sleutel
%1d%%, %2d%3s
BlissWeer
\ No newline at end of file
diff --git a/android/src/main/res/values-ru/strings.xml b/android/src/main/res/values-ru/strings.xml
index 4dbc114b04ba59dbfe706da0579756a05838e4a9..87456c7f4efe44f14d081424547d3ba9deffafab 100644
--- a/android/src/main/res/values-ru/strings.xml
+++ b/android/src/main/res/values-ru/strings.xml
@@ -48,8 +48,5 @@
З
СЗ
OpenWeather
- API ключ
- **********
- Введите свой собственный API Ключ
BlissWeather
\ No newline at end of file
diff --git a/android/src/main/res/values-sv/strings.xml b/android/src/main/res/values-sv/strings.xml
index b73700571308a339014f02cef41bcfbc8b1ef2a3..9852a328a5259a98dc46d99d08b8c3ca71a4522c 100644
--- a/android/src/main/res/values-sv/strings.xml
+++ b/android/src/main/res/values-sv/strings.xml
@@ -49,7 +49,4 @@
V
NV
OpenWeather
- API-nyckel
- **********
- Ange din egen API-nyckel
\ No newline at end of file
diff --git a/android/src/main/res/values-tr/strings.xml b/android/src/main/res/values-tr/strings.xml
index c9c1074258e98fe1c1b3f3cf605a45f6a2ba28d0..ea45eb87893f206e0aec664c3bc986dd2eed1b86 100644
--- a/android/src/main/res/values-tr/strings.xml
+++ b/android/src/main/res/values-tr/strings.xml
@@ -33,9 +33,6 @@
B
KB
OpenWeather
- API Anahtarı
- **********
- Kişisel API anahtarınızı girin
F°
Hava durumu uygulamasını ayarlamak için tıklayınız
\ No newline at end of file
diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml
index baa6f60250b7aa526e369516843e0582b15042a1..262cbf96abfb9c7041f3f98fcc3bc9033d26977b 100644
--- a/android/src/main/res/values/strings.xml
+++ b/android/src/main/res/values/strings.xml
@@ -46,8 +46,4 @@
NW
OpenWeather
-
- API Key
- **********
- Enter your own API Key
diff --git a/android/src/main/res/xml/preferences_weather.xml b/android/src/main/res/xml/preferences_weather.xml
index 5a40ad6bd9f6453797089eb2fa2d9fdf47818791..b4d9f9f833e6f53c686348b89d0d230e44381fae 100644
--- a/android/src/main/res/xml/preferences_weather.xml
+++ b/android/src/main/res/xml/preferences_weather.xml
@@ -13,13 +13,6 @@
android:summary="%s"
android:title="@string/weather_source_title" />
-
-
{
kotlin {
ktfmt().kotlinlangStyle()
target("**/*.kt")
- targetExclude("**/build/")
+ targetExclude("**/build/", "preferences/src/main/java/")
trimTrailingWhitespace()
licenseHeaderFile(licenseFile)
}
diff --git a/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt b/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt
index 4e2750a73a727065c12c7ccf2eb1965a7b933188..5bf0db868aa907d8b9d06a8edd5918d2935b43f6 100644
--- a/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt
+++ b/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt
@@ -19,6 +19,8 @@ package foundation.e.blissweather.api
import foundation.e.blissweather.ApiResult
import foundation.e.blissweather.AppPreferences
+import foundation.e.blissweather.Constants
+import foundation.e.blissweather.Secrets
import foundation.e.blissweather.handleApi
import foundation.e.blissweather.models.Coordinate
import foundation.e.blissweather.models.Units
@@ -37,8 +39,7 @@ constructor(
) : OpenWeatherRepository {
private val appPreferences = prefs
- private val apiKey: String
- get() = appPreferences.weatherApiKey!!
+ private val apiKey: String = Secrets().getWeatherKey(Constants.APP_PACKAGE_NAME)
private val unit: Units
get() {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 6b5a7fcd1b114c280fd2fa8e00a8a27b34131c7c..aee44ea6b6b7ec9f59becac09fca57cf3e67e7c2 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -8,6 +8,7 @@ axHilt = "1.0.0"
coroutines = "1.7.1"
custom = "1.0.0"
googleMaterial = "1.9.0"
+hiddensecretsplugin = "0.2.1"
hilt = "2.46.1"
preference="1.2.0"
kotlin = "1.8.22"
@@ -58,3 +59,4 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
+hiddensecretsplugin = { id = "com.klaxit.hiddensecrets", version.ref = "hiddensecretsplugin" }
diff --git a/preferences/.gitignore b/preferences/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..0477ca2b007cfce549fd7b6984c54c94686afb4e
--- /dev/null
+++ b/preferences/.gitignore
@@ -0,0 +1,2 @@
+src/main/cpp/
+src/main/java/
diff --git a/preferences/build.gradle.kts b/preferences/build.gradle.kts
index 514402328a06478e979aea49cc2956af986f1f65..2d7c053522d970614a6a7585e52fe4db08c8a1ff 100644
--- a/preferences/build.gradle.kts
+++ b/preferences/build.gradle.kts
@@ -1,8 +1,12 @@
@file:Suppress("UnstableApiUsage", "DSL_SCOPE_VIOLATION")
+import java.nio.file.Files
+import java.nio.file.Paths
+
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
+ alias(libs.plugins.hiddensecretsplugin)
}
android {
@@ -13,16 +17,45 @@ android {
buildFeatures { buildConfig = true }
- buildTypes {
- configureEach {
- buildConfigField("String", "WEATHER_API_KEY", "\"${System.getenv("WEATHER_API_KEY")}\"")
- }
- }
-
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
+
+ // Enable NDK build
+ externalNativeBuild { cmake { path("src/main/cpp/CMakeLists.txt") } }
+
+ tasks.named("preBuild") { dependsOn("weatherKeyInject") }
+}
+
+tasks.register("weatherKeyInject") {
+ val weatherApiKey = System.getenv("WEATHER_API_KEY")
+
+ doFirst {
+ // List of directories to delete
+ val directories = listOf("preferences/src/main/java", "preferences/src/main/cpp")
+
+ // Iterate through the directories and delete them
+ directories.forEach { dir ->
+ val path = Paths.get(dir)
+ if (Files.exists(path)) {
+ path.toFile().deleteRecursively()
+ }
+ }
+
+ exec {
+ commandLine(
+ "./../gradlew",
+ "hideSecret",
+ "-Pkey=$weatherApiKey",
+ "-PkeyName=WeatherKey",
+ "-Ppackage=foundation.e.blissweather"
+ )
+ // Suppress output
+ standardOutput = org.gradle.internal.io.NullOutputStream.INSTANCE
+ errorOutput = org.gradle.internal.io.NullOutputStream.INSTANCE
+ }
+ }
}
dependencies {
diff --git a/preferences/src/main/kotlin/foundation/e/blissweather/AppPreferences.kt b/preferences/src/main/kotlin/foundation/e/blissweather/AppPreferences.kt
index 239f403268f561efe14c0addbfbfe31baf52765b..dd29a905f3bad1229754eb169ff466ee77780f69 100644
--- a/preferences/src/main/kotlin/foundation/e/blissweather/AppPreferences.kt
+++ b/preferences/src/main/kotlin/foundation/e/blissweather/AppPreferences.kt
@@ -19,7 +19,6 @@ package foundation.e.blissweather
import android.content.SharedPreferences
import androidx.core.content.edit
-import foundation.e.blissweather.preferences.BuildConfig
import javax.inject.Inject
class AppPreferences @Inject constructor(private val sharedPrefs: SharedPreferences) {
@@ -27,11 +26,9 @@ class AppPreferences @Inject constructor(private val sharedPrefs: SharedPreferen
val all: Map
get() = sharedPrefs.all
- var weatherApiKey: String?
- get() = sharedPrefs.getString(Constants.WEATHER_API_KEY, BuildConfig.WEATHER_API_KEY)!!
- set(value) {
- sharedPrefs.edit { putString(Constants.WEATHER_API_KEY, value?.trim()) }
- }
+ init {
+ sharedPrefs.edit { remove(Constants.WEATHER_API_KEY) }
+ }
var weatherRefreshInterval: Long
get() = sharedPrefs.getString(Constants.WEATHER_REFRESH_INTERVAL, "15")!!.toLong()
diff --git a/preferences/src/main/kotlin/foundation/e/blissweather/Constants.kt b/preferences/src/main/kotlin/foundation/e/blissweather/Constants.kt
index d3ae35ae0133e969ed4a3091d89489b3f6a8a554..17cb546a1c25f703e45ed1476b5a767aee04498b 100644
--- a/preferences/src/main/kotlin/foundation/e/blissweather/Constants.kt
+++ b/preferences/src/main/kotlin/foundation/e/blissweather/Constants.kt
@@ -27,4 +27,5 @@ object Constants {
const val WEATHER_CUSTOM_LOCATION_LON = "weather_custom_location_lon"
const val WEATHER_ICON_SET = "weather_icons"
const val WEATHER_USE_METRIC = "weather_use_metric"
+ const val APP_PACKAGE_NAME = "foundation.e.blissweather"
}