示例#1
0
 /**
  * Remove a predefined goal from a {@link com.dsh105.echopet.api.pet.Pet}'s AI
  *
  * @param pet {@link com.dsh105.echopet.api.pet.Pet} to remove the goal from
  * @param goalType type of goal
  */
 public void removeGoal(IPet pet, GoalType goalType) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to remove PetGoal from Pet AI through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   pet.getEntityPet().getPetGoalSelector().removeGoal(goalType.getGoalString());
 }
示例#2
0
 public List<Goal> getGoals(GoalType type) {
   List<Goal> result = new ArrayList<Goal>();
   Iterator<Goal> git = getGoals().iterator();
   while (git.hasNext()) {
     Goal next = git.next();
     if (type.equals(next.getGoalType())) result.add(next);
   }
   return result;
 }
  public ArrayList<WorkoutGoal> getProfileGoals(Context context, WorkoutProfile workoutProfile) {
    // Instantiate list of workoutGoals
    ArrayList<WorkoutGoal> workoutGoals = new ArrayList<>();
    WorkoutGoal workoutGoal;

    // Get database as readable
    final WorkoutDbHelper dbHelper = new WorkoutDbHelper(context);
    SQLiteDatabase db = dbHelper.getReadableDatabase();

    // ======================= Get Goals ========================
    // Columns to get
    String[] projection = {
      DbContract.GoalEntry.COLUMN_NAME_ID,
      DbContract.GoalEntry.COLUMN_NAME_PROFILE,
      DbContract.GoalEntry.COLUMN_NAME_GOAL_TYPE,
      DbContract.GoalEntry.COLUMN_NAME_LIFT_TYPE,
      DbContract.GoalEntry.COLUMN_NAME_LIFT_REPS,
      DbContract.GoalEntry.COLUMN_NAME_START_DATE,
      DbContract.GoalEntry.COLUMN_NAME_END_DATE,
      DbContract.GoalEntry.COLUMN_NAME_START_VALUE,
      DbContract.GoalEntry.COLUMN_NAME_CURRENT_VALUE,
      DbContract.GoalEntry.COLUMN_NAME_TARGET_VALUE
    };

    // Column in WHERE clause
    String selection = DbContract.GoalEntry.COLUMN_NAME_PROFILE + "=?";

    // Value in WHERE clause
    String[] selectionArgs = {workoutProfile.getId().toString()};

    // Sorting criteria
    String sortOrder = DbContract.GoalEntry.COLUMN_NAME_START_DATE + " DESC";

    // Create Cursor from database query
    Cursor cursor =
        db.query(
            DbContract.GoalEntry.TABLE_NAME,
            projection,
            selection,
            selectionArgs,
            null,
            null,
            sortOrder);

    // Move cursor to first (only) Goal result
    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
      // Instantiate goal from database information and add to list
      int goalTypeInt =
          cursor.getInt(cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_GOAL_TYPE));
      GoalType goalType = GoalType.values()[goalTypeInt];

      int liftTypeInt =
          cursor.getInt(cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_LIFT_TYPE));
      LiftType liftType = LiftType.values()[liftTypeInt];

      int id = cursor.getInt(cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_ID));
      int liftReps =
          cursor.getInt(cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_LIFT_REPS));
      int startVal =
          cursor.getInt(cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_START_VALUE));
      int currentVal =
          cursor.getInt(
              cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_CURRENT_VALUE));
      int targetVal =
          cursor.getInt(
              cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_TARGET_VALUE));
      DateTime startDate =
          DateTimeFormatHelper.stringToDateTime(
              cursor.getString(
                  cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_START_DATE)));
      DateTime endDate =
          DateTimeFormatHelper.stringToDateTime(
              cursor.getString(
                  cursor.getColumnIndexOrThrow(DbContract.GoalEntry.COLUMN_NAME_END_DATE)));

      WorkoutGoal.Factory workoutGoalFactory = new WorkoutGoal.Factory();
      workoutGoalFactory
          .setId(id)
          .setCurrent(currentVal)
          .setTarget(targetVal)
          .setStart(startVal)
          .setEndDate(endDate)
          .setStartDate(startDate)
          .setGoalType(goalType)
          .setLiftType(liftType)
          .setLiftReps(liftReps)
          .setProfile(workoutProfile);
      workoutGoal = new WorkoutGoal(workoutGoalFactory);
      workoutGoals.add(workoutGoal);
    }

    return workoutGoals;
  }