diff --git a/app/src/androidTest/java/za/co/varsitycollege/st10204902/purrsonaltrainer/UserManagerTest.kt b/app/src/androidTest/java/za/co/varsitycollege/st10204902/purrsonaltrainer/UserManagerTest.kt index 3c0e28c..8c02673 100644 --- a/app/src/androidTest/java/za/co/varsitycollege/st10204902/purrsonaltrainer/UserManagerTest.kt +++ b/app/src/androidTest/java/za/co/varsitycollege/st10204902/purrsonaltrainer/UserManagerTest.kt @@ -48,7 +48,7 @@ class UserManagerTest { userWorkouts = emptyMap(), userExercises = emptyMap(), userAchievements = emptyMap(), - userBackgrounds = emptyMap(), + userBackgrounds = emptyList(), userInventory = emptyList() ) diff --git a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/AuthManager.kt b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/AuthManager.kt index c90f89a..7440f08 100644 --- a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/AuthManager.kt +++ b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/AuthManager.kt @@ -93,7 +93,7 @@ class AuthManager(val auth: FirebaseAuth = FirebaseAuth.getInstance()) { emptyMap(), emptyMap(), emptyMap(), - emptyMap(), + emptyList(), emptyList() ) diff --git a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/UserManager.kt b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/UserManager.kt index d6d6430..32324ae 100644 --- a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/UserManager.kt +++ b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/backend/UserManager.kt @@ -146,7 +146,7 @@ object UserManager { userExercises = emptyMap(), userAchievements = emptyMap(), userInventory = emptyList(), - userBackgrounds = emptyMap() + userBackgrounds = emptyList(), ) try { @@ -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) } } @@ -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 //-----------------------------------------------------------// diff --git a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/models/models.kt b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/models/models.kt index 1c342ab..c2cc5f5 100644 --- a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/models/models.kt +++ b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/models/models.kt @@ -56,7 +56,7 @@ data class User( val userWorkouts: Map = emptyMap(), val userExercises: Map = emptyMap(), val userAchievements: Map = emptyMap(), - val userBackgrounds: Map = emptyMap(), + val userBackgrounds: List = emptyList(), val userInventory: List = emptyList(), val customCategories: List = emptyList() ) @@ -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 = "" diff --git a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/shop/BackgroundShopActivity.kt b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/shop/BackgroundShopActivity.kt index db75612..9d849b8 100644 --- a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/shop/BackgroundShopActivity.kt +++ b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/shop/BackgroundShopActivity.kt @@ -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 } @@ -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 = "" @@ -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") diff --git a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/workout_activities/StartEmptyWorkoutActivity.kt b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/workout_activities/StartEmptyWorkoutActivity.kt index 40f41e8..d32cb8e 100644 --- a/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/workout_activities/StartEmptyWorkoutActivity.kt +++ b/app/src/main/java/za/co/varsitycollege/st10204902/purrsonaltrainer/screens/workout_activities/StartEmptyWorkoutActivity.kt @@ -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 @@ -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. */ diff --git a/app/src/main/res/drawable/shop_background_1.png b/app/src/main/res/drawable/shop_background_1.png index 469b4ab..d849a82 100644 Binary files a/app/src/main/res/drawable/shop_background_1.png and b/app/src/main/res/drawable/shop_background_1.png differ diff --git a/app/src/main/res/drawable/shop_background_2.png b/app/src/main/res/drawable/shop_background_2.png index bcf27b8..ed7b911 100644 Binary files a/app/src/main/res/drawable/shop_background_2.png and b/app/src/main/res/drawable/shop_background_2.png differ diff --git a/app/src/main/res/drawable/shop_background_3.png b/app/src/main/res/drawable/shop_background_3.png index 30702c5..9a8e055 100644 Binary files a/app/src/main/res/drawable/shop_background_3.png and b/app/src/main/res/drawable/shop_background_3.png differ diff --git a/app/src/main/res/drawable/shop_background_4.png b/app/src/main/res/drawable/shop_background_4.png index dc6bbe5..6d14a83 100644 Binary files a/app/src/main/res/drawable/shop_background_4.png and b/app/src/main/res/drawable/shop_background_4.png differ