Skip to content

Commit 7e96c9e

Browse files
committed
dependency upgrades & replacements
1 parent 44bd2c6 commit 7e96c9e

3 files changed

Lines changed: 45 additions & 63 deletions

File tree

app/build.gradle.kts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.util.Base64
22

33
plugins {
4-
id("com.adarshr.test-logger") version "3.1.0"
4+
id("com.adarshr.test-logger") version "4.0.0"
55
id("com.android.application")
66
id("kotlin-android")
77
id("kotlin-parcelize")
@@ -264,7 +264,6 @@ aboutLibraries {
264264
"asdkl", // Android SDK
265265
"Dual OpenSSL and SSLeay License", // Android NDK OpenSSL
266266
"Google Maps Platform Terms of Service", // Google Maps SDK
267-
"provided without support or warranty", // org.json
268267
"Unicode/ICU License", "Unicode-3.0", // icu4j
269268
"Bouncy Castle Licence", // bcprov
270269
"CDDL + GPLv2 with classpath exception", // javax.annotation-api
@@ -316,7 +315,6 @@ dependencies {
316315
implementation("com.mikepenz:aboutlibraries:$aboutLibsVersion")
317316
implementation("com.airbnb.android:lottie:6.6.7")
318317
implementation("io.michaelrocks.bimap:bimap:1.1.0")
319-
implementation("com.google.guava:guava:29.0-android")
320318
implementation("com.github.pengrad:mapscaleview:1.6.0")
321319
implementation("com.github.romandanylyk:PageIndicatorView:b1bad589b5")
322320
implementation("com.github.erfansn:locale-config-x:1.0.1")
@@ -342,25 +340,25 @@ dependencies {
342340

343341
// Google Places
344342
googleImplementation("com.google.android.libraries.places:places:3.5.0")
345-
googleImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3")
343+
googleImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.10.2")
346344

347345
// Mapbox Geocoding
348-
implementation("com.mapbox.mapboxsdk:mapbox-sdk-services:5.5.0")
346+
implementation("com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0")
349347

350348
// navigation library
351349
implementation("androidx.navigation:navigation-fragment-ktx:$navVersion")
352350
implementation("androidx.navigation:navigation-ui-ktx:$navVersion")
353351

354352
// viewmodel library
355-
val lifecycle_version = "2.8.1"
356-
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
357-
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
353+
val lifecycleVersion = "2.9.2"
354+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
355+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")
358356

359357
// room library
360-
val room_version = "2.7.2"
361-
implementation("androidx.room:room-runtime:$room_version")
362-
ksp("androidx.room:room-compiler:$room_version")
363-
implementation("androidx.room:room-ktx:$room_version")
358+
val roomVersion = "2.7.2"
359+
implementation("androidx.room:room-runtime:$roomVersion")
360+
ksp("androidx.room:room-compiler:$roomVersion")
361+
implementation("androidx.room:room-ktx:$roomVersion")
364362
implementation("com.github.anboralabs:spatia-room:0.3.0") {
365363
exclude("com.github.dalgarins", "android-spatialite")
366364
}
@@ -370,9 +368,9 @@ dependencies {
370368
implementation("io.github.ev-map:android-spatialite:2.2.1-alpha")
371369

372370
// billing library
373-
val billing_version = "7.0.0"
374-
googleImplementation("com.android.billingclient:billing:$billing_version")
375-
googleImplementation("com.android.billingclient:billing-ktx:$billing_version")
371+
val billingVersion = "7.0.0"
372+
googleImplementation("com.android.billingclient:billing:$billingVersion")
373+
googleImplementation("com.android.billingclient:billing-ktx:$billingVersion")
376374

377375
// ACRA (crash reporting)
378376
val acraVersion = "5.12.0"
@@ -388,20 +386,18 @@ dependencies {
388386
testImplementation("junit:junit:4.13.2")
389387
testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
390388
//noinspection GradleDependency
391-
testImplementation("org.json:json:20080701")
392389
testImplementation("org.robolectric:robolectric:4.16-beta-1")
393-
testImplementation("androidx.test:core:1.5.0")
390+
testImplementation("androidx.test:core:1.7.0")
394391
testImplementation("androidx.arch.core:core-testing:2.2.0")
395392
testImplementation("androidx.car.app:app-testing:$carAppVersion")
396-
testImplementation("androidx.test:core:1.5.0")
397393

398-
androidTestImplementation("androidx.test.ext:junit:1.1.5")
399-
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
394+
androidTestImplementation("androidx.test.ext:junit:1.3.0")
395+
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
400396
androidTestImplementation("androidx.arch.core:core-testing:2.2.0")
401397

402398
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.2")
403399

404-
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
400+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
405401
}
406402

407403
fun decode(s: String, key: String): String {

app/src/main/java/net/vonforst/evmap/api/RateLimitInterceptor.kt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package net.vonforst.evmap.api
22

3-
import com.google.common.util.concurrent.RateLimiter
43
import okhttp3.Interceptor
54
import okhttp3.Response
5+
import kotlin.time.Duration
6+
import kotlin.time.Duration.Companion.seconds
7+
import kotlin.time.TimeSource
68

79

810
class RateLimitInterceptor : Interceptor {
9-
private val rateLimiter = RateLimiter.create(3.0)
11+
private val rateLimiter = SimpleRateLimiter(3.0)
1012

1113
override fun intercept(chain: Interceptor.Chain): Response {
1214
val request = chain.request()
1315
if (request.url.host == "ui-map.shellrecharge.com") {
1416
// limit requests sent to NewMotion to 3 per second
15-
rateLimiter.acquire(1)
17+
rateLimiter.acquire()
1618

1719
var response: Response = chain.proceed(request)
1820
// 403 is how the NewMotion API indicates a rate limit error
@@ -30,4 +32,27 @@ class RateLimitInterceptor : Interceptor {
3032
return chain.proceed(request)
3133
}
3234
}
35+
}
36+
37+
internal class SimpleRateLimiter(private val permitsPerSecond: Double) {
38+
private val interval: Duration = (1.0 / permitsPerSecond).seconds
39+
private var nextAvailable = TimeSource.Monotonic.markNow()
40+
41+
@Synchronized
42+
fun acquire() {
43+
val now = TimeSource.Monotonic.markNow()
44+
if (now < nextAvailable) {
45+
val waitTime = nextAvailable - now
46+
waitTime.sleep()
47+
nextAvailable += interval
48+
} else {
49+
nextAvailable = now + interval
50+
}
51+
}
52+
}
53+
54+
fun Duration.sleep() {
55+
if (this.isPositive()) {
56+
Thread.sleep(this.inWholeMilliseconds, (this.inWholeNanoseconds % 1_000_000).toInt())
57+
}
3358
}

app/src/main/java/net/vonforst/evmap/api/Utils.kt

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
11
package net.vonforst.evmap.api
22

33
import androidx.annotation.DrawableRes
4-
import kotlinx.coroutines.ExperimentalCoroutinesApi
5-
import kotlinx.coroutines.suspendCancellableCoroutine
64
import net.vonforst.evmap.R
75
import net.vonforst.evmap.model.Chargepoint
8-
import okhttp3.Call
9-
import okhttp3.Callback
10-
import okhttp3.Response
11-
import org.json.JSONArray
12-
import java.io.IOException
13-
import kotlin.coroutines.resumeWithException
14-
import kotlin.experimental.ExperimentalTypeInference
156
import kotlin.math.abs
167

17-
operator fun <T> JSONArray.iterator(): Iterator<T> =
18-
(0 until length()).asSequence().map {
19-
@Suppress("UNCHECKED_CAST")
20-
get(it) as T
21-
}.iterator()
22-
23-
@ExperimentalCoroutinesApi
24-
suspend fun Call.await(): Response {
25-
return suspendCancellableCoroutine { continuation ->
26-
enqueue(object : Callback {
27-
override fun onResponse(call: Call, response: Response) {
28-
continuation.resume(response) {}
29-
}
30-
31-
override fun onFailure(call: Call, e: IOException) {
32-
if (continuation.isCancelled) return
33-
continuation.resumeWithException(e)
34-
}
35-
})
36-
37-
continuation.invokeOnCancellation {
38-
try {
39-
cancel()
40-
} catch (ex: Throwable) {
41-
//Ignore cancel exception
42-
}
43-
}
44-
}
45-
}
46-
478
private val plugNames = mapOf(
489
Chargepoint.TYPE_1 to R.string.plug_type_1,
4910
Chargepoint.TYPE_2_UNKNOWN to R.string.plug_type_2,

0 commit comments

Comments
 (0)