mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Added groups information caching.
This commit is contained in:
parent
9901337f86
commit
b094b196f0
@ -22,6 +22,11 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class GroupsHelper extends BaseHelper {
|
public class GroupsHelper extends BaseHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups information cache
|
||||||
|
*/
|
||||||
|
private static ArrayMap<Integer, GroupInfo> mInfoCache = new ArrayMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Groups constructor
|
* Groups constructor
|
||||||
*
|
*
|
||||||
@ -40,7 +45,31 @@ public class GroupsHelper extends BaseHelper {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ArrayMap<Integer, GroupInfo> getInfoMultiple(ArrayList<Integer> IDs){
|
public ArrayMap<Integer, GroupInfo> getInfoMultiple(ArrayList<Integer> IDs){
|
||||||
return downloadMultiple(IDs);
|
|
||||||
|
//Process each group to check if its information are available in the cache or not
|
||||||
|
ArrayList<Integer> toGet = new ArrayList<>();
|
||||||
|
|
||||||
|
for(int id : IDs){
|
||||||
|
if(!mInfoCache.containsKey(id))
|
||||||
|
toGet.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(toGet.size() > 0){
|
||||||
|
|
||||||
|
ArrayMap<Integer, GroupInfo> 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<Integer, GroupInfo> list = new ArrayMap<>();
|
||||||
|
for(int id : IDs)
|
||||||
|
list.put(id, mInfoCache.get(id));
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user