Skip to content

Commit

Permalink
fix: Fixes list removal (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikaysharma01 committed Feb 10, 2021
1 parent 0ca46bd commit 01d0979
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import openfoodfacts.github.scrachx.openfood.R
import openfoodfacts.github.scrachx.openfood.app.OFFApplication
import openfoodfacts.github.scrachx.openfood.databinding.ActivityProductListsBinding
import openfoodfacts.github.scrachx.openfood.features.listeners.CommonBottomListenerInstaller.installBottomNavigation
import openfoodfacts.github.scrachx.openfood.features.listeners.CommonBottomListenerInstaller.selectNavigationItem
Expand All @@ -49,6 +50,7 @@ import openfoodfacts.github.scrachx.openfood.models.Product
import openfoodfacts.github.scrachx.openfood.models.entities.ProductLists
import openfoodfacts.github.scrachx.openfood.models.entities.ProductListsDao
import openfoodfacts.github.scrachx.openfood.models.entities.YourListedProduct
import openfoodfacts.github.scrachx.openfood.models.entities.YourListedProductDao
import openfoodfacts.github.scrachx.openfood.utils.SwipeController
import openfoodfacts.github.scrachx.openfood.utils.Utils
import org.apache.commons.csv.CSVFormat
Expand Down Expand Up @@ -179,6 +181,13 @@ class ProductListsActivity : BaseActivity(), SwipeController.Actions {
override fun onRightClicked(position: Int) {
if (!adapter.lists.isNullOrEmpty()) {
val productToRemove = adapter.lists[position]

// delete the product from YOUR_LISTED_PRODUCT_TABLE
val deleteQuery = OFFApplication.daoSession.yourListedProductDao.queryBuilder()
.where(YourListedProductDao.Properties.ListId.eq(productToRemove.id)).buildDelete()
deleteQuery.executeDeleteWithoutDetachingEntities()
OFFApplication.daoSession.clear()

productListsDao.delete(productToRemove)
adapter.remove(productToRemove)
adapter.notifyItemRemoved(position)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_product_lists.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
android:contentDescription="@string/add_a_list"
android:text="@string/add_a_list"
app:elevation="10dp"
app:layout_constraintBottom_toTopOf="@id/product_lists_recycler_view"
app:layout_constraintBottom_toTopOf="@id/tipBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down

0 comments on commit 01d0979

Please sign in to comment.