diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 00000000..8ef35a5a
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/markdown-navigator-enh.xml b/.idea/markdown-navigator-enh.xml
new file mode 100644
index 00000000..a8fcc84d
--- /dev/null
+++ b/.idea/markdown-navigator-enh.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 987f5ef5..8541e25e 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,7 +5,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index cbca316b..01c42910 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,11 +2,8 @@
-
-
+
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7f..35eb1ddf 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/java/org/piwigo/data/model/ImageVariant.java b/app/src/main/java/org/piwigo/data/model/ImageVariant.java
index fa21e570..e6e45d3e 100644
--- a/app/src/main/java/org/piwigo/data/model/ImageVariant.java
+++ b/app/src/main/java/org/piwigo/data/model/ImageVariant.java
@@ -26,6 +26,7 @@
import androidx.room.Relation;
import java.io.Serializable;
+import java.util.Objects;
import static androidx.room.ForeignKey.CASCADE;
@@ -61,5 +62,24 @@ public ImageVariant(int imageId, int width, int height, String storageLocation,
public String storageLocation;
public String lastModified;
public String url;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ImageVariant that = (ImageVariant) o;
+ return id == that.id &&
+ imageId == that.imageId &&
+ height == that.height &&
+ width == that.width &&
+ Objects.equals(storageLocation, that.storageLocation) &&
+ Objects.equals(lastModified, that.lastModified) &&
+ Objects.equals(url, that.url);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, imageId, height, width, storageLocation, lastModified, url);
+ }
}
diff --git a/app/src/main/java/org/piwigo/data/model/PositionedItem.java b/app/src/main/java/org/piwigo/data/model/PositionedItem.java
index af88c1a7..05d28015 100644
--- a/app/src/main/java/org/piwigo/data/model/PositionedItem.java
+++ b/app/src/main/java/org/piwigo/data/model/PositionedItem.java
@@ -19,6 +19,7 @@
package org.piwigo.data.model;
import java.io.Serializable;
+import java.util.Objects;
/**
* represents an item (photo, album, video, ...) in the gallery, at a defined position in the current result
@@ -45,4 +46,19 @@ public T getItem() {
public boolean isUpdateNeeded(){
return updateNeeded;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ PositionedItem> that = (PositionedItem>) o;
+ return position == that.position &&
+ updateNeeded == that.updateNeeded &&
+ Objects.equals(item, that.item);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(position, item, updateNeeded);
+ }
}
diff --git a/app/src/main/java/org/piwigo/data/model/VariantWithImage.java b/app/src/main/java/org/piwigo/data/model/VariantWithImage.java
index 868943d4..5d829b9e 100644
--- a/app/src/main/java/org/piwigo/data/model/VariantWithImage.java
+++ b/app/src/main/java/org/piwigo/data/model/VariantWithImage.java
@@ -22,6 +22,7 @@
import androidx.room.Relation;
import java.io.Serializable;
+import java.util.Objects;
public class VariantWithImage implements Serializable {
@Embedded
@@ -31,4 +32,18 @@ public class VariantWithImage implements Serializable {
entityColumn = "id"
)
public Image image;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ VariantWithImage that = (VariantWithImage) o;
+ return Objects.equals(variant, that.variant) &&
+ Objects.equals(image, that.image);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(variant, image);
+ }
}
diff --git a/app/src/main/java/org/piwigo/data/repository/CategoriesRepository.java b/app/src/main/java/org/piwigo/data/repository/CategoriesRepository.java
index 0e370462..1c211096 100644
--- a/app/src/main/java/org/piwigo/data/repository/CategoriesRepository.java
+++ b/app/src/main/java/org/piwigo/data/repository/CategoriesRepository.java
@@ -80,52 +80,64 @@ public Observable> getCategories(@Nullable Integer cate
db = mCache; // this will keep the database if the account is switched. As the old DB will be closed this thread will be reporting an exception but we accept that for now
}
-// Flowable> remotes = mRestCategoryRepo.getCategories(
-// categoryId,
-// mPreferences.getString(PreferencesRepository.KEY_PREF_DOWNLOAD_SIZE))
-// .subscribeOn(ioScheduler)
-// .observeOn(ioScheduler)
-// .toFlowable(BackpressureStrategy.BUFFER)
-//
-// .zipWith(Flowable.range(0, Integer.MAX_VALUE), (restCat, counter) -> {
-//
-// Category c = new Category();
-// c.name = restCat.name;
-// c.id = restCat.id;
-// if (restCat.idUppercat != 0) {
-// c.parentCatId = restCat.idUppercat;
-// }
-// c.nbImages = restCat.nbImages;
-// c.thumbnailUrl = restCat.thumbnailUrl;
-// c.globalRank = restCat.globalRank;
-// c.comment = restCat.comment;
-// c.nbCategories = restCat.nbCategories;
-// c.representativePictureId = restCat.representativePictureId;
-// c.totalNbImages = restCat.totalNbImages;
-//// db.categoryDao().upsert(c);
-//
-// return new PositionedItem(counter, c, true);
-// })
-// // TODO: delete categories in database after they have been deleted on the server
-// // TODO: #90 generalize sorting
-// .sorted((categoryItem1, categoryItem2) -> NaturalOrderComparator.compare(categoryItem1.getItem().globalRank, categoryItem2.getItem().globalRank));
-//
-// if(db == null){
-// return remotes.toObservable();
-// }else {
+ Flowable remoteIDs = mRestCategoryRepo.getCategories(
+ categoryId,
+ mPreferences.getString(PreferencesRepository.KEY_PREF_DOWNLOAD_SIZE))
+ .subscribeOn(ioScheduler)
+ .observeOn(ioScheduler)
+ .toFlowable(BackpressureStrategy.BUFFER)
+ .zipWith(Flowable.range(0, Integer.MAX_VALUE), (restCat, counter) -> restCat.id);
+
+ Flowable> remotes = mRestCategoryRepo.getCategories(
+ categoryId,
+ mPreferences.getString(PreferencesRepository.KEY_PREF_DOWNLOAD_SIZE))
+ .subscribeOn(ioScheduler)
+ .observeOn(ioScheduler)
+ .toFlowable(BackpressureStrategy.BUFFER)
+ .zipWith(Flowable.range(0, Integer.MAX_VALUE), (restCat, counter) -> {
+
+ Category c = new Category();
+ c.name = restCat.name;
+ c.id = restCat.id;
+ if (restCat.idUppercat != 0) {
+ c.parentCatId = restCat.idUppercat;
+ }
+ c.nbImages = restCat.nbImages;
+ c.thumbnailUrl = restCat.thumbnailUrl;
+ c.globalRank = restCat.globalRank;
+ c.comment = restCat.comment;
+ c.nbCategories = restCat.nbCategories;
+ c.representativePictureId = restCat.representativePictureId;
+ c.totalNbImages = restCat.totalNbImages;
+ db.categoryDao().upsert(c);
+
+ return new PositionedItem(counter, c, true);
+ })
+ // TODO: #90 generalize sorting
+ .sorted((categoryItem1, categoryItem2) -> NaturalOrderComparator.compare(categoryItem1.getItem().globalRank, categoryItem2.getItem().globalRank));
+
+// remotes.subscribe();
+ if(db == null){
+ return remotes.toObservable();
+ }else {
return db.categoryDao().getCategoriesIn(categoryId)
- .subscribeOn(ioScheduler)
- .observeOn(ioScheduler)
- .flattenAsFlowable(s -> s)
- .zipWith(Flowable.range(0, Integer.MAX_VALUE),
- (item, counter) -> {
- Log.d("m_cache_sync","Read "+item.name);
- return new PositionedItem(counter, item, true);
+ .subscribeOn(ioScheduler)
+ .observeOn(ioScheduler)
+ .flattenAsFlowable(s -> s)
+/* .filter(category -> {
+ Log.d("m_cache_sync_cat","Read "+category.name);
+ if(!remoteIDs.contains(category.id).blockingGet()) {
+ Log.d("m_cache_sync_cat","Deleted "+category.name);
+ return false;
}
- )
-// .concatWith(remotes)
- .toObservable();
-// }
+ return true;
+ })*/
+ .zipWith(Flowable.range(0, Integer.MAX_VALUE), (item, counter) -> {
+ return new PositionedItem(counter, item, true);
+ })
+ .concatWith(remotes)
+ .toObservable();
+ }
}
/**
* Called when the account is changed.
@@ -139,56 +151,35 @@ public void onChanged(Account account) {
}
}
- public void updateCategories(Integer categoryId) {
- Log.d("CategoriesRepository", "getCategories");
+ public void updateCategoryCache(@Nullable Integer categoryId) {
CacheDatabase db;
synchronized (dbAccountLock) {
db = mCache; // this will keep the database if the account is switched. As the old DB will be closed this thread will be reporting an exception but we accept that for now
}
- Flowable restCategories = mRestCategoryRepo.getCategories(
+ Flowable remoteIDs = mRestCategoryRepo.getCategories(
categoryId,
mPreferences.getString(PreferencesRepository.KEY_PREF_DOWNLOAD_SIZE))
.subscribeOn(ioScheduler)
.observeOn(ioScheduler)
.toFlowable(BackpressureStrategy.BUFFER)
+ .zipWith(Flowable.range(0, Integer.MAX_VALUE), (restCat, counter) -> restCat.id);
- .zipWith(Flowable.range(0, Integer.MAX_VALUE), (restCat, counter) -> {
- Log.d("m_cache_sync","Found "+restCat.name);
- Category c = new Category();
- c.name = restCat.name;
- c.id = restCat.id;
- if (restCat.idUppercat != 0) {
- c.parentCatId = restCat.idUppercat;
- }
- c.nbImages = restCat.nbImages;
- c.thumbnailUrl = restCat.thumbnailUrl;
- c.globalRank = restCat.globalRank;
- c.comment = restCat.comment;
- c.nbCategories = restCat.nbCategories;
- c.representativePictureId = restCat.representativePictureId;
- c.totalNbImages = restCat.totalNbImages;
- db.categoryDao().upsert(c);
-
- return c;
- });
- restCategories.subscribe();
-
- Flowable dbCategories = db.categoryDao().getCategoriesIn(categoryId)
- .observeOn(ioScheduler)
- .subscribeOn(ioScheduler)
- .flattenAsFlowable(s -> s)
- .zipWith(Flowable.range(0, Integer.MAX_VALUE),
- (item, counter) -> {
- if(!restCategories.contains(item).blockingGet()) {
- Log.d("m_cache_sync","Deleted "+item.name);
- db.imageCategoryMapDao().deleteFromCategory(item.id);
- db.categoryDao().delete(item);
- }
- return item;
+ if(db != null) {
+ db.categoryDao().getCategoriesIn(categoryId)
+ .subscribeOn(ioScheduler)
+ .observeOn(ioScheduler)
+ .flattenAsFlowable(s -> s)
+ .zipWith(Flowable.range(0, Integer.MAX_VALUE), (item, counter) -> {
+ if(!remoteIDs.contains(item.id).blockingGet()) {
+ Log.d("m_cache_sync_cat","Deleted "+item.name);
+ db.imageCategoryMapDao().deleteFromCategory(item.id);
+ db.categoryDao().delete(item);
}
- );
-
- dbCategories.subscribe();
+ return new PositionedItem(counter, item, true);
+ })
+ .toObservable()
+ .subscribe();
+ }
}
}
diff --git a/app/src/main/java/org/piwigo/data/repository/ImageRepository.java b/app/src/main/java/org/piwigo/data/repository/ImageRepository.java
index 8fbe5212..c9d8b635 100644
--- a/app/src/main/java/org/piwigo/data/repository/ImageRepository.java
+++ b/app/src/main/java/org/piwigo/data/repository/ImageRepository.java
@@ -105,168 +105,136 @@ public Observable> getImages(@Nullable Integer
synchronized (dbAccountLock) {
db = mCache; // this will keep the database if the account is switched. As the old DB will be closed this thread will be reporting an exception but we accept that for now
}
-// Single> variants = db.variantDao().variantsInCategory(categoryId).subscribeOn(ioScheduler);
-// AtomicReference