Skip to content
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

hot fix #195

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UserManagerTest {
userWorkouts = emptyMap(),
userExercises = emptyMap(),
userAchievements = emptyMap(),
userBackgrounds = emptyMap(),
userBackgrounds = emptyList(),
userInventory = emptyList()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AuthManager(val auth: FirebaseAuth = FirebaseAuth.getInstance()) {
emptyMap(),
emptyMap(),
emptyMap(),
emptyMap(),
emptyList(),
emptyList()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ object UserManager {
userExercises = emptyMap(),
userAchievements = emptyMap(),
userInventory = emptyList(),
userBackgrounds = emptyMap()
userBackgrounds = emptyList(),
)

try {
Expand Down Expand Up @@ -776,8 +776,8 @@ object UserManager {
if (userIsLoggedIn()) {
_userFlow.update { user ->
user?.let {
val updatedBackgrounds =
user.userBackgrounds + (newBackground.backgroundID to newBackground)
var updatedBackgrounds = user.userBackgrounds.toMutableList()
updatedBackgrounds.add(newBackground)
it.copy(userBackgrounds = updatedBackgrounds)
}
}
Expand All @@ -786,46 +786,6 @@ object UserManager {
}
}

/**
* Removes a background from the user
* @param backgroundID The ID of the background to remove
*/
fun removeUserBackground(backgroundID: String) {
if (userIsLoggedIn()) {
_userFlow.update { user ->
val backgrounds = user?.userBackgrounds
if (backgrounds.isNullOrEmpty() || !backgrounds.containsKey(backgroundID)) {
Log.w(
"UserManager",
"User Backgrounds are empty or the background doesn't exist"
)
return@update user // Return the user unchanged
}
user.let {
val updatedBackgrounds = user.userBackgrounds - (backgroundID)
it.copy(userBackgrounds = updatedBackgrounds)
}
}
} else {
Log.e("UserManager.removeUserBackground", "User is not logged in")
}
}

/**
* Updates a background in the user
* @param backgroundID The ID of the background to update
* @param updatedBackground The updated background to replace the old one
*/
fun updateUserBackground(backgroundID: String, updatedBackground: UserBackground) {
if (userIsLoggedIn()) {
val newBackground = updatedBackground.copy(backgroundID = backgroundID)
removeUserBackground(backgroundID)
addUserBackground(newBackground)
} else {
Log.e("UserManager.updateUserBackground", "User is not logged in")
}
}

//-----------------------------------------------------------//
// CustomCategories Management
//-----------------------------------------------------------//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ data class User(
val userWorkouts: Map<String, UserWorkout> = emptyMap(),
val userExercises: Map<String, Exercise> = emptyMap(),
val userAchievements: Map<String, UserAchievement> = emptyMap(),
val userBackgrounds: Map<String, UserBackground> = emptyMap(),
val userBackgrounds: List <UserBackground> = emptyList(),
val userInventory: List<Item> = emptyList(),
val customCategories: List<String> = emptyList()
)
Expand Down Expand Up @@ -133,7 +133,7 @@ data class Exercise(
*/
@IgnoreExtraProperties
data class UserBackground(
val backgroundID: String = CreateID.GenerateID(),
val backgroundID: String = "",
val name: String = "",
val cost: Int = 0,
val backgroundURI: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BackgroundShopActivity : AppCompatActivity() {

val user = currentUser
if (user != null) {
if (user.userBackgrounds.containsKey(it.backgroundID)) {
if (user.userBackgrounds.contains(it)) {
milkcoinsComponent.milkcoinsAmount.text = ""
milkcoinsComponent.milkcoinsImage.isVisible = false
}
Expand Down Expand Up @@ -122,7 +122,7 @@ class BackgroundShopActivity : AppCompatActivity() {
tvPrice.text = background.cost.toString()
val user = currentUser
if (user != null) {
if (user.userBackgrounds.containsKey(background.backgroundID)) {
if (user.userBackgrounds.contains(background)) {
btnPurchase.text = getString(R.string.owned)
ivCoin.isVisible = false
tvPrice.text = ""
Expand Down Expand Up @@ -159,7 +159,7 @@ class BackgroundShopActivity : AppCompatActivity() {
Log.d(TAG, "onPurchaseBackground: Attempting to purchase/equip background ${background.name}")
val user = currentUser
if (user != null) {
if (user.userBackgrounds.containsKey(background.backgroundID)) {
if (user.userBackgrounds.contains(background)) {
UserManager.updateBackgroundURI(background.backgroundURI)
btnPurchase.text = getString(R.string.equipped)
Log.d(TAG, "onPurchaseBackground: Background ${background.name} equipped")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class StartEmptyWorkoutActivity : AppCompatActivity(), ExerciseAddedListener, On
val equippedItem = if (index != "") ItemsStore.globalItems[UserManager.user!!.equippedItem.toInt()] else null

calculator.updateUserStatsAfterWorkout(currentUser,workout, equippedItem)
resetRoutineCompleted(workout)
UserManager.resetWorkoutInProgress()

}
//TODO: change equippedItem in the database an model to be a int

Expand Down Expand Up @@ -166,6 +168,19 @@ class StartEmptyWorkoutActivity : AppCompatActivity(), ExerciseAddedListener, On
return boundWorkout!!.durationSeconds
}

/**
* Resets the completed status of the routine.
* @param workout The workout to reset.
*/
private fun resetRoutineCompleted(workout: UserWorkout) {
val completedRoutine = UserManager.user!!.userRoutines.values.firstOrNull { it.name == workout.name }
completedRoutine?.exercises?.values?.forEach { exercise ->
exercise.sets.values.forEach { set ->
set.completed = false
}
}
}

/**
* Sets up the add exercise button to show a popup for choosing a category.
*/
Expand Down
Binary file modified app/src/main/res/drawable/shop_background_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable/shop_background_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable/shop_background_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable/shop_background_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading