Skip to content

Commit 1cc11e7

Browse files
authored
Fixes for some warnings reported by build (#65)
There are some fixes for warnings during build _(`./gradlew build`)_ that're easy to fix _(aka low hanging fruits)_. For the other warnings we should create issues and fix them separately and test the fixes thoroughly.
1 parent 0320338 commit 1cc11e7

File tree

14 files changed

+39
-32
lines changed

14 files changed

+39
-32
lines changed

core/src/main/java/io/snabble/sdk/checkin/CheckInLocationManager.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class CheckInLocationManager(val application: Application) {
5757

5858
override fun onFlushComplete(requestCode: Int) {}
5959

60-
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {}
61-
6260
override fun onProviderEnabled(provider: String) {}
6361

6462
override fun onProviderDisabled(provider: String) {}
@@ -127,4 +125,4 @@ class CheckInLocationManager(val application: Application) {
127125
locationManager.removeUpdates(locationListener)
128126
}
129127
}
130-
}
128+
}

core/src/main/java/io/snabble/sdk/checkout/CheckoutApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ data class SignedCheckoutInfo(
156156
get() {
157157
try {
158158
if (checkoutInfo?.has("requiredInformation") == true) {
159-
val jsonArray = checkoutInfo?.getAsJsonArray("requiredInformation")
159+
val jsonArray = checkoutInfo.getAsJsonArray("requiredInformation")
160160
jsonArray?.forEach { element ->
161161
val id = element.asJsonObject["id"].asString
162162
val hasValue = element.asJsonObject.has("value")
@@ -173,7 +173,7 @@ data class SignedCheckoutInfo(
173173

174174
fun getAvailablePaymentMethods(): List<PaymentMethodInfo> {
175175
if (checkoutInfo?.has("paymentMethods") == true) {
176-
val jsonArray = checkoutInfo?.getAsJsonArray("paymentMethods")
176+
val jsonArray = checkoutInfo.getAsJsonArray("paymentMethods")
177177
if (jsonArray != null) {
178178
val type = object : TypeToken<List<PaymentMethodInfo>?>() {}.type
179179
return Gson().fromJson(jsonArray, type)
@@ -338,4 +338,4 @@ data class CheckoutProcessResponse(
338338

339339
data class Pricing(
340340
val price: Price? = null,
341-
)
341+
)

core/src/main/java/io/snabble/sdk/checkout/DefaultCheckoutApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class DefaultCheckoutApi(private val project: Project,
238238
}
239239
)
240240

241-
var url = signedCheckoutInfo?.checkoutProcessLink
241+
var url = signedCheckoutInfo.checkoutProcessLink
242242
if (url == null) {
243243
paymentProcessResult?.onError()
244244
return
@@ -308,4 +308,4 @@ class DefaultCheckoutApi(private val project: Project,
308308
companion object {
309309
private val JSON: MediaType = "application/json".toMediaType()
310310
}
311-
}
311+
}

core/src/main/java/io/snabble/sdk/coupons/Coupon.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.snabble.sdk.coupons
33
import android.graphics.Color
44
import android.os.Parcelable
55
import android.util.DisplayMetrics
6-
import androidx.annotation.ColorInt
76
import com.google.gson.annotations.SerializedName
87
import io.snabble.sdk.ColorUtils.parseColor
98
import io.snabble.sdk.Snabble
@@ -31,7 +30,7 @@ data class Coupon (
3130
val isValid: Boolean
3231
get() = when(type) {
3332
CouponType.DIGITAL -> image != null
34-
CouponType.MANUAL -> name != null
33+
CouponType.MANUAL,
3534
CouponType.PRINTED -> true
3635
}
3736

core/src/main/java/io/snabble/sdk/coupons/Coupons.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class Coupons (
7979

8080
override fun onResponse(call: Call, response: Response) {
8181
if (response.isSuccessful) {
82-
val response = response.body?.string()
82+
val responseBody = response.body?.string()
8383
val localizedResponse = GsonBuilder().create()
84-
.fromJson(response, CouponResponse::class.java)
84+
.fromJson(responseBody, CouponResponse::class.java)
8585
postValue(localizedResponse.coupons.filter { coupon ->
8686
coupon.isValid
8787
})
@@ -108,4 +108,4 @@ class Coupons (
108108
private data class CouponResponse(
109109
val coupons: List<Coupon>
110110
)
111-
}
111+
}

core/src/test/java/io/snabble/sdk/TestUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ inline infix fun <reified T : Any> T.merge(other: T): T {
1919
}
2020

2121
@Throws(InterruptedException::class)
22-
fun <T> LiveData<T>.getOrAwaitValue(): T? {
22+
inline fun <reified T> LiveData<T>.getOrAwaitValue(): T? {
2323
val data = arrayOfNulls<Any>(1)
2424
val latch = CountDownLatch(1)
2525
val observer: Observer<T> = object : Observer<T> {
@@ -34,4 +34,4 @@ fun <T> LiveData<T>.getOrAwaitValue(): T? {
3434
throw RuntimeException("LiveData value was never set.")
3535
}
3636
return data[0] as T?
37-
}
37+
}

kotlin-compose-sample/src/main/java/io/snabble/sdk/composesample/MainActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ class MainActivity : AppCompatActivity() {
5656
val navController = rememberNavController()
5757

5858
with(navController) {
59-
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.SHOW_BARCODE_SEARCH) { _, args ->
59+
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.SHOW_BARCODE_SEARCH) { _, _ ->
6060
navigate(BarcodeSearch.route)
6161
}
62-
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.SHOW_SCANNER) { _, args ->
62+
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.SHOW_SCANNER) { _, _ ->
6363
navigate(Scanner.route)
6464
}
65-
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.SHOW_SHOPPING_CART) { _, args ->
65+
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.SHOW_SHOPPING_CART) { _, _ ->
6666
navigate(Cart.route)
6767
}
6868
SnabbleUI.setUiAction(this@MainActivity, SnabbleUI.Event.GO_BACK) { _, _ ->
@@ -150,4 +150,4 @@ class MainActivity : AppCompatActivity() {
150150
}
151151
}
152152
}
153-
}
153+
}

kotlin-customization-sample/src/main/java/io/snabble/sdk/customization/LoadingActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class LoadingActivity : AppCompatActivity() {
4747
.show()
4848
}
4949
}
50+
null -> Unit
5051
}
5152
}
5253
}
53-
}
54+
}

kotlin-customization-sample/src/main/java/io/snabble/sdk/customization/MainActivity.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package io.snabble.sdk.customization
33
import android.Manifest
44
import android.content.Intent
55
import android.content.pm.PackageManager
6+
import android.os.Build
67
import android.os.Bundle
8+
import android.os.Parcelable
79
import android.widget.Toast
810
import androidx.activity.result.ActivityResultLauncher
911
import androidx.activity.result.contract.ActivityResultContracts
@@ -61,7 +63,7 @@ class MainActivity : AppCompatActivity() {
6163
println("Nav to ${resources.getResourceName(destination.id)}")
6264
// apply deeplink arguments to bundle
6365
if (arguments?.containsKey(NavController.KEY_DEEP_LINK_INTENT) == true) {
64-
(arguments.get(NavController.KEY_DEEP_LINK_INTENT) as? Intent)?.data?.let { deeplink ->
66+
arguments.parcelable<Intent>(NavController.KEY_DEEP_LINK_INTENT)?.data?.let { deeplink ->
6567
deeplink.queryParameterNames.forEach { key ->
6668
val value = deeplink.getQueryParameter(key)
6769
when {
@@ -158,4 +160,9 @@ class MainActivity : AppCompatActivity() {
158160
super.onPause()
159161
Snabble.checkInManager.stopUpdating()
160162
}
161-
}
163+
}
164+
165+
private inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? = when {
166+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelable(key, T::class.java)
167+
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
168+
}

kotlin-sample/src/main/java/io/snabble/sdk/sample/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import kotlinx.coroutines.launch
3232

3333
class MainActivity : AppCompatActivity(), PermissionSupport {
3434

35-
lateinit var locationPermission: ActivityResultLauncher<String>
35+
private lateinit var locationPermission: ActivityResultLauncher<String>
3636

3737
private lateinit var locationManager: CheckInLocationManager
3838

0 commit comments

Comments
 (0)