diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java index 9c799ad..6fc980b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java @@ -22,6 +22,11 @@ import java.util.ArrayList; */ public class GroupsHelper extends BaseHelper { + /** + * Groups information cache + */ + private static ArrayMap mInfoCache = new ArrayMap<>(); + /** * Groups constructor * @@ -40,7 +45,31 @@ public class GroupsHelper extends BaseHelper { */ @Nullable public ArrayMap getInfoMultiple(ArrayList IDs){ - return downloadMultiple(IDs); + + //Process each group to check if its information are available in the cache or not + ArrayList toGet = new ArrayList<>(); + + for(int id : IDs){ + if(!mInfoCache.containsKey(id)) + toGet.add(id); + } + + if(toGet.size() > 0){ + + ArrayMap downloaded = downloadMultiple(toGet); + + if(downloaded == null) + return null; // Can not get information about all the groups + + for(int id : toGet) + mInfoCache.put(id, downloaded.get(id)); + } + + //Extract groups information from cache + ArrayMap list = new ArrayMap<>(); + for(int id : IDs) + list.put(id, mInfoCache.get(id)); + return list; } /**