From 7a60d488de01d4db9e6c152315eca951a52c2e9d Mon Sep 17 00:00:00 2001 From: althafvly Date: Fri, 15 Nov 2024 13:26:01 +0530 Subject: [PATCH 1/3] feat: Remove unused api key change option --- .../blissweather/settings/SettingsActivity.kt | 1 - .../settings/SettingsViewModel.kt | 20 ------------------- android/src/main/res/values-de/strings.xml | 3 --- android/src/main/res/values-es/strings.xml | 3 --- android/src/main/res/values-fr/strings.xml | 2 -- android/src/main/res/values-is/strings.xml | 3 --- android/src/main/res/values-it/strings.xml | 3 --- android/src/main/res/values-ja/strings.xml | 3 --- android/src/main/res/values-nl/strings.xml | 2 -- android/src/main/res/values-ru/strings.xml | 3 --- android/src/main/res/values-sv/strings.xml | 3 --- android/src/main/res/values-tr/strings.xml | 3 --- android/src/main/res/values/strings.xml | 4 ---- .../src/main/res/xml/preferences_weather.xml | 7 ------- .../api/OpenWeatherRepositoryImpl.kt | 4 ++-- .../e/blissweather/AppPreferences.kt | 9 +++------ 16 files changed, 5 insertions(+), 68 deletions(-) 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 b8082de..184c238 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 ef7a9b1..ca03ff3 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 f5c3e9d..a71b906 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 1cb035b..dae46e7 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 6be3e53..4abd8ac 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 22629ea..24e9fd9 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 14ca220..2273839 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 8620959..4ee17ae 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 a869206..7bed804 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 4dbc114..87456c7 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 b737005..9852a32 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 c9c1074..ea45eb8 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 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 baa6f60..262cbf9 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 5a40ad6..b4d9f9f 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" /> - - 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() -- GitLab From 13cc61d1143944b623f40b0974c9816bf185b3b9 Mon Sep 17 00:00:00 2001 From: althafvly Date: Fri, 15 Nov 2024 17:17:54 +0530 Subject: [PATCH 2/3] feat: Store api keys in libs --- .gitignore | 2 +- .../e/blissweather/SpotlessPlugin.kt | 2 +- .../api/OpenWeatherRepositoryImpl.kt | 5 ++- gradle/libs.versions.toml | 2 + preferences/.gitignore | 2 + preferences/build.gradle.kts | 45 ++++++++++++++++--- .../foundation/e/blissweather/Constants.kt | 1 + 7 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 preferences/.gitignore diff --git a/.gitignore b/.gitignore index 4001a58..258f931 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ .externalNativeBuild .cxx local.properties -**/build/ \ No newline at end of file +**/build/ diff --git a/build-logic/src/main/java/foundation/e/blissweather/SpotlessPlugin.kt b/build-logic/src/main/java/foundation/e/blissweather/SpotlessPlugin.kt index c664ede..0f50e6c 100644 --- a/build-logic/src/main/java/foundation/e/blissweather/SpotlessPlugin.kt +++ b/build-logic/src/main/java/foundation/e/blissweather/SpotlessPlugin.kt @@ -36,7 +36,7 @@ class SpotlessPlugin : Plugin { 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 75a95c3..5bf0db8 100644 --- a/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt +++ b/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt @@ -19,13 +19,14 @@ 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 import foundation.e.blissweather.models.WeatherCity import foundation.e.blissweather.models.WeatherData import foundation.e.blissweather.models.WeatherDayResponse -import foundation.e.blissweather.preferences.BuildConfig import java.util.Locale import javax.inject.Inject @@ -38,7 +39,7 @@ constructor( ) : OpenWeatherRepository { private val appPreferences = prefs - private val apiKey: String = BuildConfig.OWM_API_KEY + 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 6b5a7fc..aee44ea 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 0000000..0477ca2 --- /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 5144023..2d7c053 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/Constants.kt b/preferences/src/main/kotlin/foundation/e/blissweather/Constants.kt index d3ae35a..17cb546 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" } -- GitLab From 6c99a216ab0a70f684f0d187a5b1d7b2a3359524 Mon Sep 17 00:00:00 2001 From: althafvly Date: Fri, 15 Nov 2024 20:51:00 +0530 Subject: [PATCH 3/3] feat: Bump version to 1.0.1 --- android/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 4e4f76b..e82f3b5 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) } -- GitLab