Class ChallengeAttemptRepository


  • public class ChallengeAttemptRepository
    extends Object
    ChallengeAttemptRepository contains methods that provide a layer of abstraction above the ChallengeAttemptDao, and allows for creation, reading, updating, and deleting of attempts.
    • Constructor Detail

      • ChallengeAttemptRepository

        public ChallengeAttemptRepository​(Context context)
        The constructor initializes the context, the database, and the dao.
        Parameters:
        context - The application context.
    • Method Detail

      • save

        public Completable save​(ChallengeAttempt attempt)
        Creates or updates a attempt record in the database.
        Parameters:
        attempt - The ChallengeAttempt.
        Returns:
        A Completable indicating the success or failure of the creation/update.
      • delete

        public Completable delete​(ChallengeAttempt attempt)
        Deletes a attempt record in the database.
        Parameters:
        attempt - The ChallengeAttempt.
        Returns:
        A Completable indicating the success or failure of the deletion.
      • get

        public LiveData<ChallengeAttempt> get​(long id)
        Returns LiveData of a challenge attempt, given its id.
        Parameters:
        id - The id of the attempt.
        Returns:
        LiveData of a ChallengeAttempt.
      • getAll

        public LiveData<List<ChallengeAttempt>> getAll()
        Returns LiveData of all challenge attempts.
        Returns:
        LiveData of a List of ChallengeAttempt.
      • getByPlayer

        public LiveData<List<ChallengeAttempt>> getByPlayer​(long id)
        Returns LiveData of all challenge attempts made by a specific player.
        Parameters:
        id - The player's id.
        Returns:
        LiveData of a List of ChallengeAttempt.
      • getHighScores

        public LiveData<List<ChallengeAttemptWithPlayer>> getHighScores​(int numScores)
        Returns LiveData of the challenge attempts with the highest scores.
        Parameters:
        numScores - The number of scores to return.
        Returns:
        LiveData of a List of ChallengeAttemptWithPlayer.
      • getHighScoresByPlayer

        public LiveData<List<ChallengeAttempt>> getHighScoresByPlayer​(long id,
                                                                      int numScores)
        Returns LiveData of the challenge attempts with the highest scores made by a particular player.
        Parameters:
        id - The player's id.
        numScores - The number of scores to return.
        Returns:
        LiveData of a List of ChallengeAttempt.