示例#1
0
  /**
   * Deletes a group from the database
   *
   * @param group The group to be deleted
   */
  public void deleteGroupFromDatabase(Group group) {

    String where = GroupColumns._ID + " = '" + group.getId() + "'";
    context.getContentResolver().delete(GroupProvider.CONTENT_URI, where, null);
    context.getContentResolver().delete(UserGroupProvider.CONTENT_URI, where, null);
    Log.i("USER GROUP MANAGER", "Group: " + group.toString() + " deleted from database");
  }
示例#2
0
  /**
   * Add a group to the database
   *
   * @param group The group to be added
   */
  public void addGroupToGroupDatabase(Group group) {
    ContentValues values = new ContentValues();

    values.put(GroupColumns._ID, group.getId());
    values.put(GroupColumns.GROUP_NAME, group.getName());

    context.getContentResolver().insert(GroupColumns.CONTENT_URI, values);

    Log.i("USER GROUP MANAGER", "Group: " + group.getName() + " added to the database");
  }
示例#3
0
  /**
   * Checks if a user already is in a group
   *
   * @param group The group to be checked
   * @param user The user to be checked
   * @return True if the user is in the group
   */
  private boolean userExistsInGroup(Group group, User user) {

    ArrayList<Group> userConnectedGroups = getAllGroupsConnectedToAUser(user);
    System.out.println("Number of connected Groups :" + userConnectedGroups.size());
    for (Group g : userConnectedGroups) {
      if (g.getId().equals(group)) {
        return true;
      }
    }

    return false;
  }
示例#4
0
  /**
   * Add a user to a group in the database
   *
   * @param group The group the user should be added to
   * @param user The user to be added
   */
  public void addUserToAGroupInTheDatabase(Group group, User user) {
    ContentValues values = new ContentValues();
    values.put(GroupColumns._ID, group.getId());
    values.put(UserColumns.USER_NAME, user.getUserName());

    System.out.println(userExistsInGroup(group, user));
    if (!userExistsInGroup(group, user)) {
      context.getContentResolver().insert(UserGroupProvider.CONTENT_URI, values);
    }
    Log.i(
        "USER GROUP MANAGER",
        "User: "******" added to group: " + group.getName());
  }
示例#5
0
  /**
   * Removes a user from a group in the database
   *
   * @param group The group the user should be removed from
   * @param user The user to be removed
   */
  public void removeUserFromAGroupInTheDatabase(Group group, User user) {

    String where =
        GroupColumns._ID
            + " = '"
            + group.getId()
            + "'"
            + " AND "
            + UserColumns.USER_NAME
            + " = '"
            + user.getUserName()
            + "'";
    context.getContentResolver().delete(UserGroupProvider.CONTENT_URI, where, null);

    Log.i(
        "USER GROUP MANAGER",
        "User: "******" removed from group: " + group.getName());
  }
示例#6
0
  public ArrayList<Experience> LoadAllSharedExperiencesOnGroupFromDatabase(Group group) {

    ArrayList<Experience> allExperiences = new ArrayList<Experience>();

    String[] experienceTableColumns =
        new String[] {
          ExperienceColumns._ID,
          ExperienceColumns.EXPERIENCE_NAME,
          ExperienceColumns.EXPERIENCE_SHARED,
          ExperienceColumns.EXPERIENCE_CREATOR,
          ExperienceColumns.EXPERIENCE_SHARED_WITH
        };

    whereStatement =
        ExperienceColumns.EXPERIENCE_SHARED
            + "='1' AND "
            + ExperienceColumns.EXPERIENCE_SHARED_WITH
            + "='"
            + group.getId()
            + "'";

    Cursor c =
        context
            .getContentResolver()
            .query(
                ExperienceColumns.CONTENT_URI, experienceTableColumns, whereStatement, null, null);

    if (c.moveToFirst()) {
      do {
        Experience experience =
            new Experience(
                c.getString(c.getColumnIndex(ExperienceColumns._ID)),
                c.getString(c.getColumnIndex(ExperienceColumns.EXPERIENCE_NAME)),
                (c.getInt((c.getColumnIndex(ExperienceColumns.EXPERIENCE_SHARED))) == 1)
                    ? true
                    : false,
                new Account(
                    c.getString(c.getColumnIndex(ExperienceColumns.EXPERIENCE_CREATOR)),
                    "com.google"));

        if (experience.isShared()) {
          experience.setSharingGroupObject(
              getGroupSharedWithExperience(
                  c.getString(c.getColumnIndex(ExperienceColumns.EXPERIENCE_SHARED_WITH))));
        }

        allExperiences.add(experience);
      } while (c.moveToNext());
    }
    c.close();

    Log.i("CONTENTLOADER - EXPERIENCES", allExperiences.size() + " experiences loaded");

    return allExperiences;
  }
示例#7
0
  /**
   * Gets a group from the database based on an ID
   *
   * @param groupID The ID checked against the database
   * @return The group with the given groupID
   */
  public Group getGroupFromDatabase(String groupID) {

    String[] groupsTableColumns = new String[] {GroupColumns._ID, GroupColumns.GROUP_NAME};
    Group group = null;
    String whereStatement = GroupColumns._ID + " = '" + groupID + "'";

    Cursor c =
        context
            .getContentResolver()
            .query(GroupProvider.CONTENT_URI, groupsTableColumns, whereStatement, null, null);
    if (c.moveToFirst()) {

      group =
          new Group(
              c.getString(c.getColumnIndex(GroupColumns._ID)),
              c.getString(c.getColumnIndex(GroupColumns.GROUP_NAME)));
      group.setMembers(getUsersConnectedToAGroup(group));
    }
    c.close();
    return group;
  }
示例#8
0
  /**
   * Gets all users in a group
   *
   * @param group The group to be checked
   * @return A list of all the users connected to the group
   */
  private ArrayList<User> getUsersConnectedToAGroup(Group group) {

    String[] userGroupsTableColumns = new String[] {GroupColumns._ID, UserColumns.USER_NAME};
    ArrayList<User> users = new ArrayList<User>();

    String where = GroupColumns._ID + " = '" + group.getId() + "'";

    Cursor c =
        context
            .getContentResolver()
            .query(UserGroupProvider.CONTENT_URI, userGroupsTableColumns, where, null, null);

    if (c.moveToFirst()) {
      do {
        users.add(new User(c.getString(c.getColumnIndex(UserColumns.USER_NAME))));
      } while (c.moveToNext());
    }
    c.close();
    return users;
  }