diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt index 00a3f82..9196876 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt @@ -151,6 +151,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte remoteCategories: JSONArray, localCategories: List ) { + for (localCategory in localCategories) { + var found = false + for (i in 0 until remoteCategories.length()) { + val remoteProduct = remoteCategories.getJSONObject(i) + if (remoteProduct["local_id"] == localCategory.id) { + found = true + break + } + } + if (!found) categoryDAO.eraseCategory(localCategory.id, this) + } for (i in 0 until remoteCategories.length()) { var categoryInRemoteDB: JSONObject? = null var categoryInLocalDB: Category? = null @@ -201,6 +212,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte remoteProducts: JSONArray, localProducts: List ) { + for (localProduct in localProducts) { + var found = false + for (i in 0 until remoteProducts.length()) { + val remoteProduct = remoteProducts.getJSONObject(i) + if (remoteProduct["local_id"] == localProduct.id) { + found = true + break + } + } + if (!found) productDAO.eraseProduct(localProduct.id) + } for (i in 0 until remoteProducts.length()) { var productInRemoteDB: JSONObject? = null var productInLocalDB: Product? = null @@ -259,6 +281,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte remoteAbstractProducts: JSONArray, localAbstractProducts: List ) { + for (localAbstractProduct in localAbstractProducts) { + var found = false + for (i in 0 until remoteAbstractProducts.length()) { + val remoteAbstractProduct = remoteAbstractProducts.getJSONObject(i) + if (remoteAbstractProduct["local_id"] == localAbstractProduct.id) { + found = true + break + } + } + if (!found) abstractProductDAO.eraseAbstractProduct(localAbstractProduct.id, this) + } for (i in 0 until remoteAbstractProducts.length()) { var abstractProductInRemoteDB: JSONObject? = null var abstractProductInLocalDB: AbstractProduct? = null