items are now fully synchronized

This commit is contained in:
leca 2024-11-11 03:11:52 +03:00
parent 7cc0467967
commit 617dcf2e7d
1 changed files with 33 additions and 0 deletions

View File

@ -151,6 +151,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
remoteCategories: JSONArray,
localCategories: List<Category>
) {
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<Product>
) {
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<AbstractProduct>
) {
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