Skip to content

Commit

Permalink
fix: add product to history correctly
Browse files Browse the repository at this point in the history
Fixes #3957
  • Loading branch information
VaiTon committed May 9, 2021
1 parent b2391f0 commit 354adbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Expand Up @@ -244,31 +244,33 @@ class ContinuousScanActivity : BaseActivity() {
binding.quickViewTags.adapter = null
binding.quickViewProgress.visibility = View.GONE
binding.quickViewProgressText.visibility = View.GONE

if (productState.status == 0L) {
tryDisplayOffline(offlineSavedProduct, barcode, R.string.product_not_found)
} else {
val product = productState.product!!
this.product = product

// Add product to scan history
productDisp = client.addToHistory(product).subscribeOn(Schedulers.io()).subscribe()

// If we're here from comparison -> add product, return to comparison activity
if (intent.getBooleanExtra(ProductCompareActivity.KEY_COMPARE_PRODUCT, false)) {
startActivity(Intent(this@ContinuousScanActivity, ProductCompareActivity::class.java).apply {
putExtra(ProductCompareActivity.KEY_PRODUCT_FOUND, true)

val productsToCompare = intent.extras!!.getSerializable(ProductCompareActivity.KEY_PRODUCTS_TO_COMPARE) as ArrayList<Product>
if (productsToCompare.contains(product)) {
if (product in productsToCompare) {
putExtra(ProductCompareActivity.KEY_PRODUCT_ALREADY_EXISTS, true)
} else {
productsToCompare.add(product)
productsToCompare += product
matomoAnalytics.trackEvent(AnalyticsEvent.AddProductToComparison(product.code))
}
putExtra(ProductCompareActivity.KEY_PRODUCTS_TO_COMPARE, productsToCompare)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
})
}

// Add product to scan history
productDisp = client.addToHistory(product).subscribeOn(Schedulers.io()).subscribe()
showAllViews()
binding.txtProductCallToAction.let {
it.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
Expand Down
Expand Up @@ -441,17 +441,17 @@ class OpenFoodAPIClient @Inject constructor(
* Add a product to ScanHistory synchronously
*/
fun HistoryProductDao.addToHistorySync(product: Product, language: String) {
val historyProducts = queryBuilder()
.where(HistoryProductDao.Properties.Barcode.eq(product.code))
.uniqueOrThrow()
val historyProducts: HistoryProduct? = queryBuilder()
.where(HistoryProductDao.Properties.Barcode.eq(product.code))
.unique()
val hp = HistoryProduct(
product.productName,
product.brands,
product.getImageSmallUrl(language),
product.code,
product.quantity,
product.nutritionGradeFr,
product.ecoscore,
product.productName,
product.brands,
product.getImageSmallUrl(language),
product.code,
product.quantity,
product.nutritionGradeFr,
product.ecoscore,
product.novaGroups
)
if (historyProducts != null) hp.id = historyProducts.id
Expand Down

0 comments on commit 354adbf

Please sign in to comment.