-
Notifications
You must be signed in to change notification settings - Fork 3
feature/handle-remaining-logic #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2a53c8d
feat:add user data source
gehadepada 23c81f5
feat:add user repo interface
gehadepada 92c5c30
feat:add user repo impl
gehadepada 6a2c430
feat:update data at home
gehadepada 29d6be8
feat:handle di for user
gehadepada c1f9dbe
feat:update data home after buying
gehadepada 90de6ca
feat:update data home after buy character
gehadepada 68b9718
feat:add CharacterDialogNavigator.kt
gehadepada a447a62
feat:make home points updated after buying character
gehadepada 1a73a37
fix:fix race condition issue
gehadepada 8fcb5a6
Merge remote-tracking branch 'origin/develop' into feature/handle-rem…
gehadepada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/thechance/qurio/data/local/UserDataSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.thechance.qurio.data.local | ||
| import android.content.Context | ||
| import com.thechance.qurio.R | ||
| import com.thechance.qurio.domain.entity.Character | ||
|
|
||
|
|
||
| object UserDataSource{ | ||
|
|
||
| private var currentCharacter: Character?=null | ||
|
|
||
| private var lives: Int = 4 | ||
| private var points: Int = 700 | ||
| private var awards: Int = 0 | ||
| private var currentStreak: Int = 0 | ||
|
|
||
| fun getUserCharacter() = currentCharacter | ||
| fun updateUserCharacter(newCharacter: Character) { currentCharacter = newCharacter } | ||
|
|
||
| fun getUserStatistics(): Triple<Int, Int, Int> = Triple(lives, points, awards) | ||
| fun updateLives(newLives: Int) { lives = newLives } | ||
|
|
||
| fun updatePoints(newPoints: Int) { points = newPoints } | ||
| fun addPoints(pointsToAdd: Int) { points += pointsToAdd } | ||
| fun updateAwards(newAwards: Int) { awards = newAwards } | ||
| fun incrementAwards() { awards++ } | ||
|
|
||
| fun getUserStreak() = currentStreak | ||
| fun updateStreak(newStreak: Int) { currentStreak = newStreak } | ||
| fun incrementStreak() { currentStreak++ } | ||
| fun resetStreak() { currentStreak = 0 } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/thechance/qurio/data/repository/UserRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.thechance.qurio.data.repository | ||
|
|
||
| import android.content.Context | ||
| import com.thechance.qurio.data.local.CharactersDataSource | ||
| import com.thechance.qurio.data.local.UserDataSource | ||
| import com.thechance.qurio.domain.entity.Character | ||
| import com.thechance.qurio.domain.repository.user.UserRepository | ||
| import javax.inject.Inject | ||
|
|
||
| class UserRepositoryImpl @Inject constructor( | ||
| private val context: Context, | ||
| ) : UserRepository { | ||
|
|
||
|
|
||
| override suspend fun getUserCharacter(): Character { | ||
| return UserDataSource?.getUserCharacter() ?: CharactersDataSource.getAllCharacters(context=context)[0] | ||
| } | ||
|
|
||
| override suspend fun updateUserCharacter(character: Character) { | ||
| UserDataSource.updateUserCharacter(character) | ||
| } | ||
|
|
||
| override suspend fun getUserStatistics(): Triple<Int, Int, Int> { | ||
| return UserDataSource.getUserStatistics() | ||
| } | ||
|
|
||
| override suspend fun getUserStreak(): Int { | ||
| return UserDataSource.getUserStreak() | ||
| } | ||
|
|
||
| override suspend fun updateStreak(streak: Int) { | ||
| UserDataSource.updateStreak(streak) | ||
| } | ||
|
|
||
| override suspend fun incrementStreak() { | ||
| UserDataSource.incrementStreak() | ||
| } | ||
|
|
||
| override suspend fun addPoints(points: Int) { | ||
| UserDataSource.addPoints(points) | ||
| } | ||
|
|
||
| override suspend fun updateLives(lives: Int) { | ||
| UserDataSource.updateLives(lives) | ||
| } | ||
|
|
||
| override suspend fun updatePoints(points: Int) { | ||
| UserDataSource.updatePoints(points) | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/thechance/qurio/domain/entity/UserStatistics.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.thechance.qurio.domain.entity | ||
|
|
||
| data class UserStatistics( | ||
| val lives: Int, | ||
| val points: Int, | ||
| val awards: Int | ||
| ) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/thechance/qurio/domain/repository/UserRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.thechance.qurio.domain.repository.user | ||
|
|
||
| import com.thechance.qurio.domain.entity.Character | ||
|
|
||
| interface UserRepository { | ||
| suspend fun getUserCharacter(): Character | ||
| suspend fun updateUserCharacter(character: Character) | ||
| suspend fun getUserStatistics(): Triple<Int, Int, Int> | ||
| suspend fun getUserStreak(): Int | ||
| suspend fun updateStreak(streak: Int) | ||
| suspend fun incrementStreak() | ||
| suspend fun addPoints(points: Int) | ||
| suspend fun updateLives(lives: Int) | ||
| suspend fun updatePoints(points: Int) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 54 additions & 5 deletions
59
app/src/main/java/com/thechance/qurio/presentation/screen/buylife/BuyLifePresenter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,73 @@ | ||
| package com.thechance.qurio.presentation.screen.buylife | ||
|
|
||
| import com.thechance.qurio.domain.repository.user.UserRepository | ||
| import com.thechance.qurio.presentation.base.BasePresenter | ||
| import javax.inject.Inject | ||
|
|
||
| class BuyLifePresenter @Inject constructor() : BasePresenter<BuyLifeView>() { | ||
| class BuyLifePresenter @Inject constructor( | ||
| private val userRepository: UserRepository | ||
| ) : BasePresenter<BuyLifeView>() { | ||
|
|
||
| private var lifeCount: Int = 1 | ||
| private var price: Int = 200 | ||
| private var userPoints: Int = 0 | ||
|
|
||
| fun loadLifeInfo() { | ||
| tryToExecute( | ||
| callee = { userRepository.getUserStatistics() }, | ||
| onSuccess = ::onLoadLifeInfoSuccess, | ||
| onError = ::onError | ||
| ) | ||
| } | ||
|
|
||
| private fun onLoadLifeInfoSuccess(statistics: Triple<Int, Int, Int>) { | ||
| val (_, points, _) = statistics | ||
| userPoints = points | ||
|
|
||
| view.showLifeCount(lifeCount) | ||
| view.showPrice(price) | ||
|
|
||
| if (userPoints < price) { | ||
| view.showError("Not enough points to buy a life!") | ||
| view.disableBuyButton() | ||
| } else { | ||
| view.enableBuyButton() | ||
| } | ||
| } | ||
|
|
||
| fun buyLife() { | ||
| view.showLoading() | ||
| // TODO: Add the business logic | ||
|
|
||
| // Simulate success | ||
| tryToExecute( | ||
| callee = { userRepository.getUserStatistics() }, | ||
| onSuccess = ::onBuyLifeSuccess, | ||
| onError = ::onBuyLifeError | ||
| ) | ||
| } | ||
|
|
||
| private suspend fun onBuyLifeSuccess(statistics: Triple<Int, Int, Int>) { | ||
| val (lives, points, _) = statistics | ||
|
|
||
| if (points >= price) { | ||
| userRepository.updateLives(lives + 1) | ||
| userRepository.updatePoints(points - price) | ||
| view.hideLoading() | ||
| view.onLifeBoughtSuccessfully() | ||
| } else { | ||
| view.hideLoading() | ||
| view.showError("Not enough points to buy a life!") | ||
| view.disableBuyButton() | ||
| view.onLifeBought(false) | ||
| } | ||
| } | ||
|
|
||
| private fun onBuyLifeError(throwable: Throwable) { | ||
| view.hideLoading() | ||
| view.onLifeBought(true) | ||
| view.showError(throwable.message ?: "Failed to buy life") | ||
| view.onLifeBought(false) | ||
| } | ||
| } | ||
|
|
||
| private fun onError(throwable: Throwable) { | ||
| view.showError(throwable.message ?: "Failed to load life info") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u add also current heart live , or get live heart ?cuz i want it in game screen so i can make a check when i lose and remove heart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I saw it, but sorry for overthinking, my way of thinking is I'm here i wanna implement in game screen so the name i think will express it is get live heart or smth like that, so when i lose a game i easily can use update live and make sure it's updated in home screen, I think we can put the name is get live heart so we can update &get in same time