Fetch suggested users along with regular users

pull/14/head
Sam Bosley 12 years ago
parent 81b3e15912
commit b948fb2f52

@ -867,22 +867,31 @@ public final class ActFmSyncService {
return result.optInt("time", 0);
}
private void saveUsers(JSONArray users, HashSet<Long> ids) throws JSONException {
for (int i = 0; i < users.length(); i++) {
JSONObject userObject = users.getJSONObject(i);
ids.add(userObject.optLong("id"));
actFmDataService.saveUserData(userObject); }
}
public int fetchUsers() throws JSONException, IOException {
if (!checkForToken())
return 0;
JSONObject result = actFmInvoker.invoke("user_list",
"token", token);
JSONObject suggestedResult = actFmInvoker.invoke("suggested_user_list",
"token", token);
JSONArray users = result.getJSONArray("list");
JSONArray suggestedUsers = suggestedResult.getJSONArray("list");
HashSet<Long> ids = new HashSet<Long>();
if (users.length() > 0)
if (users.length() > 0 || suggestedUsers.length() > 0)
Preferences.setBoolean(R.string.p_show_friends_view, true);
for (int i = 0; i < users.length(); i++) {
JSONObject userObject = users.getJSONObject(i);
ids.add(userObject.optLong("id"));
actFmDataService.saveUserData(userObject);
}
saveUsers(users, ids);
saveUsers(suggestedUsers, ids);
Long[] idsArray = ids.toArray(new Long[ids.size()]);
actFmDataService.userDao.deleteWhere(Criterion.not(User.REMOTE_ID.in(idsArray)));

Loading…
Cancel
Save