diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2313e18 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +root = true + +[*{kt,kts}] + +# sometimes this is good for readibility +ktlint_standard_string-template = disabled + +# sometimes this is good thing when a lot of code is packed +ktlint_standard_no-empty-first-line-in-method-block = disabled + +# maybe in the future +ktlint_standard_spacing-between-declarations-with-comments = disabled + +# this is no JS or TS +ktlint_standard_trailing-comma-on-call-site = disabled +ktlint_standard_trailing-comma-on-declaration-site = disabled + +# not sure about this, but i dont like it :) +ktlint_standard_colon-spacing = disabled + +# this is nitpicking +ktlint_standard_import-ordering = disabled +ktlint_standard_no-wildcard-imports = disabled + +# sometimes this is good thing +ktlint_standard_filename = disabled \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b742b4..e8d4e82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,8 +7,6 @@ on: - main - release/* pull_request: - schedule: - - cron: '25 6 * * *' jobs: build: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..80047d4 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,18 @@ +name: Lint + +on: + push: + branches: + - develop + - release/* + pull_request: + +jobs: + ktlint: + name: ktlint + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + - name: Run lint script + run: ./scripts/lint.sh diff --git a/build.gradle.kts b/build.gradle.kts index 0b57d41..7b2f984 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,4 +39,4 @@ allprojects { tasks.register("clean", Delete::class) { delete(rootProject.buildDir) -} \ No newline at end of file +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6f18ba9..e3df117 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,4 +1,4 @@ -plugins{ +plugins { `kotlin-dsl` } @@ -16,4 +16,4 @@ val dokkaVersion: String by System.getProperties() dependencies { implementation("com.android.tools.build", "gradle", androidPluginVersion) implementation(kotlin("gradle-plugin", kotlinVersion)) -} \ No newline at end of file +} diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index bf3adda..cca05cb 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -38,4 +38,4 @@ object Constants { const val minSdkVersion = 21 const val buildToolsVersion = "33.0.2" } -} \ No newline at end of file +} diff --git a/ktlint b/ktlint new file mode 100755 index 0000000..5bcc56f Binary files /dev/null and b/ktlint differ diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 4035dbe..f4dd26f 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -50,6 +50,17 @@ android { suppressWarnings = false } } + + // Custom ktlint script + tasks.register("ktlint") { + logger.lifecycle("ktlint") + exec { + commandLine = listOf("./../scripts/lint.sh", "--no-error") + } + } + + // Make ktlint run before build + tasks.getByName("preBuild").dependsOn("ktlint") } dependencies { @@ -65,4 +76,4 @@ dependencies { compileOnly("io.getlime.core:rest-model-base:1.2.0") } -apply("android-release-aar.gradle") \ No newline at end of file +apply("android-release-aar.gradle") diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt b/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt index b74d0f8..e2e8e75 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/Api.kt @@ -43,7 +43,6 @@ import com.wultra.android.powerauth.networking.utils.getCurrentLocale import io.getlime.security.powerauth.core.EciesCryptogram import io.getlime.security.powerauth.core.EciesEncryptor import io.getlime.security.powerauth.networking.response.IGetEciesEncryptorListener -import io.getlime.security.powerauth.networking.response.ITimeSynchronizationListener import io.getlime.security.powerauth.sdk.PowerAuthAuthentication import io.getlime.security.powerauth.sdk.PowerAuthSDK import io.getlime.security.powerauth.sdk.PowerAuthToken @@ -52,7 +51,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient.Builder import okhttp3.RequestBody.Companion.toRequestBody import java.io.IOException -import java.util.* interface IApiCallResponseListener { fun onSuccess(result: T) @@ -77,8 +75,8 @@ abstract class Api( @PublishedApi internal val gsonBuilder: GsonBuilder, @PublishedApi internal val appContext: Context, tokenProvider: IPowerAuthTokenProvider? = null, - @PublishedApi internal val userAgent: UserAgent = UserAgent.libraryDefault(appContext)) { - + @PublishedApi internal val userAgent: UserAgent = UserAgent.libraryDefault(appContext) +) { /** * Language sent in request header. Default value is "en". */ @@ -101,9 +99,9 @@ abstract class Api( endpoint: EndpointBasic, headers: HashMap? = null, okHttpInterceptor: OkHttpBuilderInterceptor? = null, - listener: IApiCallResponseListener) { - - makeCall(getBodyBytes(data), endpoint, headers ?: hashMapOf(), okHttpInterceptor, listener) + listener: IApiCallResponseListener + ) { + makeCall(getBodyBytes(data), endpoint, headers ?: hashMapOf(), okHttpInterceptor, listener) } inline fun post( @@ -112,22 +110,23 @@ abstract class Api( authentication: PowerAuthAuthentication, headers: HashMap? = null, okHttpInterceptor: OkHttpBuilderInterceptor? = null, - listener: IApiCallResponseListener) { + listener: IApiCallResponseListener + ) { - val bodyBytes = getBodyBytes(data) + val bodyBytes = getBodyBytes(data) - val authorizationHeader = powerAuthSDK.requestSignatureWithAuthentication( - appContext, - authentication, - "POST", - endpoint.uriId, - bodyBytes - ) + val authorizationHeader = powerAuthSDK.requestSignatureWithAuthentication( + appContext, + authentication, + "POST", + endpoint.uriId, + bodyBytes + ) - val newHeaders = headers ?: hashMapOf() - newHeaders[authorizationHeader.key] = authorizationHeader.value + val newHeaders = headers ?: hashMapOf() + newHeaders[authorizationHeader.key] = authorizationHeader.value - makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener) + makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener) } inline fun post( @@ -135,26 +134,26 @@ abstract class Api( endpoint: EndpointSignedWithToken, headers: HashMap? = null, okHttpInterceptor: OkHttpBuilderInterceptor? = null, - listener: IApiCallResponseListener) { - - tokenProvider.getTokenAsync( - endpoint.tokenName, - object : IPowerAuthTokenListener { - override fun onReceived(token: PowerAuthToken) { - - val tokenHeader = token.generateHeader() - val bodyBytes = getBodyBytes(data) - val newHeaders = headers ?: hashMapOf() - newHeaders[tokenHeader.key] = tokenHeader.value - - makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener) - } + listener: IApiCallResponseListener + ) { + tokenProvider.getTokenAsync( + endpoint.tokenName, + object : IPowerAuthTokenListener { + override fun onReceived(token: PowerAuthToken) { + + val tokenHeader = token.generateHeader() + val bodyBytes = getBodyBytes(data) + val newHeaders = headers ?: hashMapOf() + newHeaders[tokenHeader.key] = tokenHeader.value + + makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener) + } - override fun onFailed(e: Throwable) { - listener.onFailure(ApiError(e)) - } + override fun onFailed(e: Throwable) { + listener.onFailure(ApiError(e)) } - ) + } + ) } // PRIVATE API @@ -172,7 +171,8 @@ abstract class Api( endpoint: Endpoint, headers: HashMap, okHttpInterceptor: OkHttpBuilderInterceptor? = null, - listener: IApiCallResponseListener) { + listener: IApiCallResponseListener + ) { var bytes = bodyBytes @@ -272,7 +272,7 @@ abstract class Api( internal inline fun getEncryptor( endpoint: Endpoint, crossinline callback: (Result) -> Unit - ) { + ) { val listener = object : IGetEciesEncryptorListener { override fun onGetEciesEncryptorSuccess(encryptor: EciesEncryptor) { @@ -327,7 +327,7 @@ class UserAgent internal constructor(@PublishedApi internal val value: String? = @SerializedName("mac") val mac: String?, @SerializedName("nonce") val nonce: String?, @SerializedName("timestamp") val timestamp: Long? - ) +) /** Envelope for E2EE responses. */ @PublishedApi @@ -338,4 +338,4 @@ internal class E2EEResponse( @SerializedName("timestamp") val timestamp: Long? ) { fun toCryptogram() = EciesCryptogram(null, encryptedData, mac, null, nonce, timestamp ?: 0) -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/ECIESInterceptor.kt b/library/src/main/java/com/wultra/android/powerauth/networking/ECIESInterceptor.kt index 2ca3c18..1aa9a38 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/ECIESInterceptor.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/ECIESInterceptor.kt @@ -31,4 +31,4 @@ interface ECIESInterceptor: Interceptor { * @param decrypted Decrypted payload */ fun encryptedResponseReceived(url: URL, decrypted: ByteArray) -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/Endpoint.kt b/library/src/main/java/com/wultra/android/powerauth/networking/Endpoint.kt index df62737..68c4313 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/Endpoint.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/Endpoint.kt @@ -72,4 +72,4 @@ enum class E2EEConfiguration { ACTIVATION_SCOPE, /** Endpoint is not encrypted. */ NOT_ENCRYPTED -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/data/Requests.kt b/library/src/main/java/com/wultra/android/powerauth/networking/data/Requests.kt index 0d7a9c5..9635d13 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/data/Requests.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/data/Requests.kt @@ -26,4 +26,4 @@ open class BaseRequest /** * Common request format with data object inside the `requestObject` property. */ -abstract class ObjectRequest(@SerializedName("requestObject") val requestObject: T): BaseRequest() \ No newline at end of file +abstract class ObjectRequest(@SerializedName("requestObject") val requestObject: T): BaseRequest() diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/data/Responses.kt b/library/src/main/java/com/wultra/android/powerauth/networking/data/Responses.kt index 30f9b24..838d92f 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/data/Responses.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/data/Responses.kt @@ -35,4 +35,4 @@ open class StatusResponse(@SerializedName("status") val status: Status) { /** * Common response where data returned are inside the `responseObject` property. */ -abstract class ObjectResponse(@SerializedName("responseObject") val responseObject: T, status: Status): StatusResponse(status) \ No newline at end of file +abstract class ObjectResponse(@SerializedName("responseObject") val responseObject: T, status: Status): StatusResponse(status) diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiError.kt b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiError.kt index ebce05f..ac19b79 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiError.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiError.kt @@ -34,5 +34,4 @@ data class ApiError(val e: Throwable) { null } } - -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorCode.kt b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorCode.kt index 346583a..b44082f 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorCode.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorCode.kt @@ -144,4 +144,4 @@ enum class ApiErrorCode(val message: String) { */ fun errorCodeFromCodeString(code: String): ApiErrorCode? = map[code] } -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorException.kt b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorException.kt index 06c8d6a..327462f 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorException.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiErrorException.kt @@ -57,4 +57,4 @@ class ApiErrorException( return if (t is ApiErrorException) t else ApiErrorException(t) } } -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiHttpException.kt b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiHttpException.kt index cd41be5..da35a3c 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiHttpException.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/error/ApiHttpException.kt @@ -37,4 +37,4 @@ class ApiHttpException( /** Response code */ val code: Int = response.code override val message: String = response.message -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponse.kt b/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponse.kt index 88316f9..dd1e8bf 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponse.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponse.kt @@ -21,4 +21,4 @@ import com.wultra.android.powerauth.networking.data.ObjectResponse /** * Model class for error response - the wrapper responseObject. */ -class ErrorResponse(responseObject: ErrorResponseObject, status: Status): ObjectResponse(responseObject, status) \ No newline at end of file +class ErrorResponse(responseObject: ErrorResponseObject, status: Status): ObjectResponse(responseObject, status) diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponseObject.kt b/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponseObject.kt index 934729f..3e8a2a4 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponseObject.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/error/ErrorResponseObject.kt @@ -22,14 +22,14 @@ import com.google.gson.annotations.SerializedName * Model class for error response. */ data class ErrorResponseObject( - @SerializedName("code") - val code: String, - - @SerializedName("message") - val message: String) { + @SerializedName("code") + val code: String, + @SerializedName("message") + val message: String +) { val errorCode: ApiErrorCode? get() { return ApiErrorCode.errorCodeFromCodeString(code) } -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/log/WPNLogListener.kt b/library/src/main/java/com/wultra/android/powerauth/networking/log/WPNLogListener.kt index f69c47e..1c11f16 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/log/WPNLogListener.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/log/WPNLogListener.kt @@ -21,4 +21,4 @@ interface WPNLogListener { /** Debug log */ fun debug(message: String) -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/processing/GsonRequestBodyBytes.kt b/library/src/main/java/com/wultra/android/powerauth/networking/processing/GsonRequestBodyBytes.kt index e3ea100..6d8c47a 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/processing/GsonRequestBodyBytes.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/processing/GsonRequestBodyBytes.kt @@ -50,4 +50,4 @@ internal class GsonRequestBodyBytes(private val gson: Gson, private val adapt companion object { private val UTF_8 = Charset.forName("UTF-8") } -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/ssl/ISSLPinningProvider.kt b/library/src/main/java/com/wultra/android/powerauth/networking/ssl/ISSLPinningProvider.kt index 1c09cfb..20f4aa2 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/ssl/ISSLPinningProvider.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/ssl/ISSLPinningProvider.kt @@ -18,7 +18,6 @@ package com.wultra.android.powerauth.networking.ssl import okhttp3.OkHttpClient - /** * SSL pinning provider configures HTTP client to verify SSL certificates */ @@ -29,4 +28,4 @@ interface ISSLPinningProvider { * @param builder OkHttpClient builder to configure */ fun configureOkHttpClient(builder: OkHttpClient.Builder) -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/ssl/SSLValidationStrategy.kt b/library/src/main/java/com/wultra/android/powerauth/networking/ssl/SSLValidationStrategy.kt index be4d112..5dbcead 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/ssl/SSLValidationStrategy.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/ssl/SSLValidationStrategy.kt @@ -63,7 +63,6 @@ internal class DefaultSSLValidationStrategy: SSLValidationStrategy() { // Nothing to change, use default return builder } - } internal class NoSSLValidationStrategy: SSLValidationStrategy() { override fun configure(builder: OkHttpClient.Builder): OkHttpClient.Builder { @@ -73,7 +72,6 @@ internal class NoSSLValidationStrategy: SSLValidationStrategy() { builder.hostnameVerifier(noValidationStrategy.hostnameVerifier!!) return builder } - } internal class PinningSSLValidationStrategy(private val provider: ISSLPinningProvider): SSLValidationStrategy() { override fun configure(builder: OkHttpClient.Builder): OkHttpClient.Builder { @@ -81,4 +79,3 @@ internal class PinningSSLValidationStrategy(private val provider: ISSLPinningPro return builder } } - diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/ssl/TrustAllCertsTrustManager.kt b/library/src/main/java/com/wultra/android/powerauth/networking/ssl/TrustAllCertsTrustManager.kt index 7db09a8..535679f 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/ssl/TrustAllCertsTrustManager.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/ssl/TrustAllCertsTrustManager.kt @@ -40,4 +40,4 @@ internal class TrustAllCertsTrustManager : X509TrustManager { override fun getAcceptedIssuers(): Array { return arrayOf() } -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenListener.kt b/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenListener.kt index e4682b4..f8ba631 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenListener.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenListener.kt @@ -24,4 +24,4 @@ import io.getlime.security.powerauth.sdk.PowerAuthToken interface IPowerAuthTokenListener { fun onReceived(token: PowerAuthToken) fun onFailed(e: Throwable) -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenProvider.kt b/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenProvider.kt index f306d2a..7ffb07a 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenProvider.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/tokens/IPowerAuthTokenProvider.kt @@ -21,4 +21,4 @@ package com.wultra.android.powerauth.networking.tokens */ interface IPowerAuthTokenProvider { fun getTokenAsync(tokenName: String, listener: IPowerAuthTokenListener) -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/tokens/TokenManager.kt b/library/src/main/java/com/wultra/android/powerauth/networking/tokens/TokenManager.kt index 9d7d83c..456d246 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/tokens/TokenManager.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/tokens/TokenManager.kt @@ -28,7 +28,8 @@ import io.getlime.security.powerauth.sdk.PowerAuthTokenStore */ internal class TokenManager( private val appContext: Context, - private val powerAuthTokenStore: PowerAuthTokenStore) : IPowerAuthTokenProvider { + private val powerAuthTokenStore: PowerAuthTokenStore +) : IPowerAuthTokenProvider { override fun getTokenAsync(tokenName: String, listener: IPowerAuthTokenListener) { val localPowerAuthToken = powerAuthTokenStore.getLocalToken(appContext, tokenName) @@ -37,18 +38,23 @@ internal class TokenManager( } else { val authentication = PowerAuthAuthentication.possession() try { - powerAuthTokenStore.requestAccessToken(appContext, tokenName, authentication, object : IGetTokenListener { - override fun onGetTokenSucceeded(token: PowerAuthToken) { - listener.onReceived(token) - } + powerAuthTokenStore.requestAccessToken( + appContext, + tokenName, + authentication, + object : IGetTokenListener { + override fun onGetTokenSucceeded(token: PowerAuthToken) { + listener.onReceived(token) + } - override fun onGetTokenFailed(t: Throwable) { - listener.onFailed(t) + override fun onGetTokenFailed(t: Throwable) { + listener.onFailed(t) + } } - }) + ) } catch (t: Throwable) { listener.onFailed(t) } } } -} \ No newline at end of file +} diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt b/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt index 6c928db..a9f76b4 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/utils/AppUtils.kt @@ -54,7 +54,7 @@ object ConnectionMonitor { try { val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager status = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - getConnectionStatus(connectivityManager) + getConnectionStatus(connectivityManager) } else { val activeNetworkInfo = connectivityManager.activeNetworkInfo if (activeNetworkInfo != null && activeNetworkInfo.isConnected) { diff --git a/library/src/main/java/com/wultra/android/powerauth/networking/utils/DeviceInfoUtils.kt b/library/src/main/java/com/wultra/android/powerauth/networking/utils/DeviceInfoUtils.kt index b1ad96c..95c9656 100644 --- a/library/src/main/java/com/wultra/android/powerauth/networking/utils/DeviceInfoUtils.kt +++ b/library/src/main/java/com/wultra/android/powerauth/networking/utils/DeviceInfoUtils.kt @@ -31,7 +31,6 @@ fun Context.getCurrentLocale(): Locale { } } - /** * Returns a well-formed IETF BCP 47 language tag representing * this locale. @@ -43,7 +42,7 @@ fun Locale.toBcp47LanguageTag(): String { return this.toLanguageTag() } - val sep = '-' // we will use a dash as per BCP 47 + val sep = '-' // we will use a dash as per BCP 47 var language = this.language var region = this.country var variant = variant @@ -57,14 +56,14 @@ fun Locale.toBcp47LanguageTag(): String { } if (language.isEmpty() || !language.matches("\\p{Alpha}{2,8}".toRegex())) { - language = "und" // Follow the Locale#toLanguageTag() implementation + language = "und" // Follow the Locale#toLanguageTag() implementation // which says to return "und" for Undetermined } else if (language == "iw") { - language = "he" // correct deprecated "Hebrew" + language = "he" // correct deprecated "Hebrew" } else if (language == "in") { - language = "id" // correct deprecated "Indonesian" + language = "id" // correct deprecated "Indonesian" } else if (language == "ji") { - language = "yi" // correct deprecated "Yiddish" + language = "yi" // correct deprecated "Yiddish" } // ensure valid country code, if not well formed, it's omitted @@ -86,4 +85,4 @@ fun Locale.toBcp47LanguageTag(): String { } return bcp47Tag.toString() -} \ No newline at end of file +} diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100755 index 0000000..6d651d6 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +#set -x +set -e + +KTLINT_VERSION="0.49.1" +NO_ERROR=false + +TOP=$(dirname $0) +pushd "${TOP}/.." + +function download +{ + curl -sSLO "https://github.com/pinterest/ktlint/releases/download/${KTLINT_VERSION}/ktlint" && chmod +x ktlint +} + +while [[ $# -gt 0 ]] +do + opt="$1" + case "$opt" in + -ne | --no-error) + NO_ERROR=true + ;; + esac + shift +done + +echo "" +echo "##################################" +echo " CUSTOM KTLINT SCRIPT " +echo "##################################" +echo "" + +if [ ! -f "ktlint" ]; then + echo "downloading ktlint ${KTLINT_VERSION}..." + download +else + current=$(./ktlint -V) + # current="0.48.2" + if [ "${KTLINT_VERSION}" != "${current}" ]; then + echo "ktlint ${current} already downloaded, but ${KTLINT_VERSION} is required, removing and downloading." + rm "ktlint" + download + else + echo "ktlint ${KTLINT_VERSION} already downloaded." + fi +fi + +EXIT_CODE=0 +./ktlint "**/*.kt" "**/*.kts" || EXIT_CODE=$? + + +echo "" +echo "##################################" +if [ $EXIT_CODE -eq 0 ]; then + echo " NO KTLINT ERRORS " +else + echo " THERE ARE KTLINT ERRORS! " + if [ $NO_ERROR == true ]; then + echo " (ignoring exit code)" + EXIT_CODE=0 + else + echo " (exiting with error)" + EXIT_CODE=1 + fi +fi +echo "##################################" +echo "" + +exit $EXIT_CODE \ No newline at end of file