Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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}")
}
}

Expand Down