private void putFriendEntries(long userId, FriendEntries fes) { fes.trimFriends(); fes = fes.copy(); if (CollectionUtils.isNotEmpty(fes.circles)) { for (int i = fes.circles.size() - 1; i >= 0; i--) { Circle c = fes.circles.get(i); if (ArrayUtils.contains(Circle.BUILTIN_ACTUAL_CIRCLES, c.getCircleId())) fes.circles.remove(i); } } friends.put(userId, fes.copy()); }
@Override protected FriendEntries getFriendEntries(Context ctx, long userId) { FriendEntries fes = friends.get(userId); if (fes == null) { fes = new FriendEntries(); } else { fes = fes.copy(); } Circles circles = new Circles(); if (CollectionUtils.isNotEmpty(fes.circles)) { for (Circle c : fes.circles) circles.add(c.copy()); } for (int circleId : Circle.BUILTIN_ACTUAL_CIRCLES) { circles.add(new Circle(circleId, Circle.getBuiltinCircleName(circleId, ""), 0)); } fes.circles = circles; return fes; }
@Override public boolean updateCustomCircleName(Context ctx, int circleId, String circleName) { ParamChecker.notNull("ctx", ctx); ParamChecker.notEmpty("circleName", circleName); long viewerId = ctx.getViewer(); AccountHelper.checkUser(account, ctx, viewerId); if (!Circle.isCustomCircleId(circleId)) return false; FriendEntries fes = getFriendEntries(ctx, viewerId); if (fes != null) { fes.updateCircleName(circleId, circleName); putFriendEntries(viewerId, fes); return true; } else { return false; } }