From 617dcf2e7d00b3ad2ab8269aca2e21f1f2e35d14 Mon Sep 17 00:00:00 2001 From: leca Date: Mon, 11 Nov 2024 03:11:52 +0300 Subject: [PATCH] items are now fully synchronized --- .../activities/MainActivity.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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