diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a44c5d1d3..deaa97c923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,24 @@ All notable changes to this project will be documented in this file. ## UNRELEASED ### Added ### Changed -* Replace items depositText w/ local i18n text ### Removed ### Fixed +## [0.75.7] +### Fixed +* Handle npe when loading the shopping cart data and restore from it + +## [0.75.6] +### Changed +* Replace items depositText w/ local i18n text +* Switch to only delete a pre auth if a card was successfully saved +### Fixed +* Fix SQLiteDatabaseLockedException + +## [0.75.5] +### Fixed +* Fix npe while calculating the modified price + ## [0.75.4] ### Added * Provide integration ready Fiserv composable diff --git a/core/src/main/java/io/snabble/sdk/shoppingcart/ShoppingCartStorage.kt b/core/src/main/java/io/snabble/sdk/shoppingcart/ShoppingCartStorage.kt index edb8ba1eab..2c13ffd4fd 100644 --- a/core/src/main/java/io/snabble/sdk/shoppingcart/ShoppingCartStorage.kt +++ b/core/src/main/java/io/snabble/sdk/shoppingcart/ShoppingCartStorage.kt @@ -2,7 +2,6 @@ package io.snabble.sdk.shoppingcart import android.os.Handler import android.os.Looper -import com.google.gson.JsonSyntaxException import io.snabble.sdk.Project import io.snabble.sdk.Snabble import io.snabble.sdk.shoppingcart.data.listener.SimpleShoppingCartListener @@ -15,6 +14,7 @@ import java.io.File import java.io.FileInputStream import java.io.FileOutputStream import java.io.IOException +import java.lang.RuntimeException import java.nio.charset.Charset import kotlin.time.Duration.Companion.seconds @@ -57,26 +57,37 @@ internal class ShoppingCartStorage(val project: Project) { val env = Snabble.environment?.name?.lowercase() ?: "unknown" Dispatch.mainThread { project.shops.forEach { - fileMap[it.id] = File(project.internalStorageDirectory, "cart/$env/${it.id}/shoppingCart.json") + fileMap[it.id] = + File(project.internalStorageDirectory, "cart/$env/${it.id}/shoppingCart.json") } } } + @Suppress("TooGenericExceptionCaught") private fun load() { try { if (currentFile?.exists() == true) { - val contents = IOUtils.toString(FileInputStream(currentFile), Charset.forName("UTF-8")) - val shoppingCartData = GsonHolder.get().fromJson(contents, ShoppingCartData::class.java) - project.shoppingCart.initWithData(shoppingCartData) + val contents: String? = + IOUtils.toString(FileInputStream(currentFile), Charset.forName("UTF-8")) + val shoppingCartData: ShoppingCartData? = + GsonHolder.get().fromJson(contents, ShoppingCartData::class.java) + if (shoppingCartData != null) { + project.shoppingCart.initWithData(shoppingCartData) + } else { + //shopping cart could not be read, create a new one. + project.shoppingCart.initWithData(ShoppingCartData()) + } } else { project.shoppingCart.initWithData(ShoppingCartData()) } } catch (e: IOException) { //shopping cart could not be read, create a new one. - Logger.e("Could not load shopping list from: " + currentFile?.absolutePath + ", creating a new one.") + Logger.e("Could not load shopping list from: ${currentFile?.absolutePath}, creating a new one.") + project.shoppingCart.initWithData(ShoppingCartData()) + } catch (e: RuntimeException) { + //shopping cart could not be read, create a new one. + Logger.e("Could not load shopping list from ${currentFile?.absolutePath}: ${e.message}") project.shoppingCart.initWithData(ShoppingCartData()) - } catch (e: JsonSyntaxException) { - Logger.e("Could not parse shopping list due to: ${e.message}") } }