Class ChallengeAttemptRepository
- java.lang.Object
-
- edu.cnm.deepdive.scalescroller.service.ChallengeAttemptRepository
-
public class ChallengeAttemptRepository extends Object
ChallengeAttemptRepositorycontains methods that provide a layer of abstraction above theChallengeAttemptDao, and allows for creation, reading, updating, and deleting of attempts.
-
-
Constructor Summary
Constructors Constructor Description ChallengeAttemptRepository(Context context)The constructor initializes the context, the database, and the dao.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Completabledelete(ChallengeAttempt attempt)Deletes a attempt record in the database.LiveData<ChallengeAttempt>get(long id)Returns LiveData of a challenge attempt, given its id.LiveData<List<ChallengeAttempt>>getAll()Returns LiveData of all challenge attempts.LiveData<List<ChallengeAttempt>>getByPlayer(long id)Returns LiveData of all challenge attempts made by a specific player.LiveData<List<ChallengeAttemptWithPlayer>>getHighScores(int numScores)Returns LiveData of the challenge attempts with the highest scores.LiveData<List<ChallengeAttempt>>getHighScoresByPlayer(long id, int numScores)Returns LiveData of the challenge attempts with the highest scores made by a particular player.Completablesave(ChallengeAttempt attempt)Creates or updates a attempt record in the database.
-
-
-
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- TheChallengeAttempt.- Returns:
- A
Completableindicating the success or failure of the creation/update.
-
delete
public Completable delete(ChallengeAttempt attempt)
Deletes a attempt record in the database.- Parameters:
attempt- TheChallengeAttempt.- Returns:
- A
Completableindicating 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:
LiveDataof aChallengeAttempt.
-
getAll
public LiveData<List<ChallengeAttempt>> getAll()
Returns LiveData of all challenge attempts.- Returns:
LiveDataof aListofChallengeAttempt.
-
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:
LiveDataof aListofChallengeAttempt.
-
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:
LiveDataof aListofChallengeAttemptWithPlayer.
-
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:
LiveDataof aListofChallengeAttempt.
-
-