public static List<AVUser> searchUser(String searchName, int skip) throws AVException { AVQuery<AVUser> q = AVUser.getQuery(AVUser.class); q.whereContains(User.USERNAME, searchName); q.limit(Constant.PAGE_SIZE); q.skip(skip); AVUser user = AVUser.getCurrentUser(); List<String> friendIds = new ArrayList<String>(CacheService.getFriendIds()); friendIds.add(user.getObjectId()); q.whereNotContainedIn(Constant.OBJECT_ID, friendIds); q.orderByDescending(Constant.UPDATED_AT); q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE); List<AVUser> users = q.find(); CacheService.registerUsers(users); return users; }
private void loadMoreFriend(int skip, final int limit, final boolean isRefresh) { AVQuery<LeanchatUser> q = LeanchatUser.getQuery(LeanchatUser.class); q.whereContains(LeanchatUser.USERNAME, searchName); q.limit(Constants.PAGE_SIZE); q.skip(skip); LeanchatUser user = LeanchatUser.getCurrentUser(); List<String> friendIds = new ArrayList<String>(FriendsManager.getFriendIds()); friendIds.add(user.getObjectId()); q.whereNotContainedIn(Constants.OBJECT_ID, friendIds); q.orderByDescending(Constants.UPDATED_AT); q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE); q.findInBackground( new FindCallback<LeanchatUser>() { @Override public void done(List<LeanchatUser> list, AVException e) { UserCacheUtils.cacheUsers(list); recyclerView.setLoadComplete(list.toArray(), false); } }); }