Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Add more exercise types and some set field refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 29, 2022
1 parent 9fdebbe commit 34c8780
Show file tree
Hide file tree
Showing 16 changed files with 632 additions and 380 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,54 @@
package com.ankitsuda.rebound.ui.components.workouteditor.utils

import com.ankitsuda.rebound.domain.ExerciseCategory
import com.ankitsuda.rebound.domain.SetFieldValueType
import com.ankitsuda.rebound.domain.entities.ExerciseLogEntry

object WorkoutEditorUtils {
fun isValidSet(logEntry: ExerciseLogEntry, exerciseCategory: ExerciseCategory): Boolean =
with(logEntry) {
when (exerciseCategory) {
ExerciseCategory.WEIGHTS_AND_REPS, ExerciseCategory.WEIGHTED_BODYWEIGHT, ExerciseCategory.ASSISTED_BODYWEIGHT -> {
weight == null || reps == null
}
ExerciseCategory.BODYWEIGHT_REPS -> {
reps == null
}
ExerciseCategory.DURATION -> {
timeRecorded == null
}
ExerciseCategory.DISTANCE_AND_DURATION -> {
distance == null || timeRecorded == null
}
ExerciseCategory.WEIGHT_AND_DISTANCE -> {
weight == null || distance == null
}
ExerciseCategory.WEIGHT_AND_DURATION -> {
weight == null || timeRecorded == null
}
ExerciseCategory.UNKNOWN -> {
true
}
// fun isValidSet(logEntry: ExerciseLogEntry, exerciseCategory: ExerciseCategory): Boolean =
// with(logEntry) {
// when (exerciseCategory) {
// ExerciseCategory.WEIGHTS_AND_REPS, ExerciseCategory.WEIGHTED_BODYWEIGHT, ExerciseCategory.ASSISTED_BODYWEIGHT -> {
// weight == null || reps == null
// }
// ExerciseCategory.BODYWEIGHT_REPS -> {
// reps == null
// }
// ExerciseCategory.DURATION -> {
// timeRecorded == null
// }
// ExerciseCategory.DISTANCE_AND_DURATION -> {
// distance == null || timeRecorded == null
// }
// ExerciseCategory.WEIGHT_AND_DISTANCE -> {
// weight == null || distance == null
// }
// ExerciseCategory.WEIGHT_AND_DURATION -> {
// weight == null || timeRecorded == null
// }
// ExerciseCategory.UNKNOWN -> {
// true
// }
// }
// }

fun isValidSet(logEntry: ExerciseLogEntry, exerciseCategory: ExerciseCategory?): Boolean {
if (exerciseCategory == null) return true

val fields: List<Any?> = exerciseCategory.fields.map {
when (it) {
SetFieldValueType.WEIGHT,
SetFieldValueType.ADDITIONAL_WEIGHT,
SetFieldValueType.ASSISTED_WEIGHT -> logEntry.weight
SetFieldValueType.REPS -> logEntry.reps
SetFieldValueType.DISTANCE -> logEntry.distance
SetFieldValueType.DURATION -> logEntry.timeRecorded
SetFieldValueType.RPE -> true // RPE is allowed to be null
}
}

return !fields.any {
it == null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@

package com.ankitsuda.rebound.ui.components.workouteditor.warmupcalculator

import androidx.compose.foundation.layout.*
import androidx.compose.material.Icon
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Done
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.ankitsuda.rebound.domain.ExerciseCategory
import com.ankitsuda.rebound.ui.components.workouteditor.R
import com.ankitsuda.rebound.ui.theme.ReboundTheme

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ import com.ankitsuda.base.util.colorFromSupersetId
import com.ankitsuda.base.util.isDark
import com.ankitsuda.base.util.lighterOrDarkerColor
import com.ankitsuda.base.util.toReadableString
import com.ankitsuda.common.compose.kgToUserPrefStr
import com.ankitsuda.common.compose.kmToUserPrefStr
import com.ankitsuda.common.compose.userPrefDistanceUnitStr
import com.ankitsuda.common.compose.userPrefWeightUnitStr
import com.ankitsuda.rebound.domain.*
import com.ankitsuda.rebound.domain.entities.ExerciseLogEntry
import com.ankitsuda.rebound.domain.entities.ExerciseSetGroupNote
Expand All @@ -67,7 +63,7 @@ fun SessionExerciseCardItem(
title: String?,
subtitle: String? = null,
supersetId: Int? = null,
exerciseCategory: ExerciseCategory,
exerciseCategory: ExerciseCategory?,
entries: List<ExerciseLogEntry>,
notes: List<ExerciseSetGroupNote>? = null
) {
Expand Down Expand Up @@ -164,7 +160,7 @@ fun SessionExerciseCardItem(
@Composable
fun SessionExerciseSetItem(
entry: ExerciseLogEntry,
exerciseCategory: ExerciseCategory,
exerciseCategory: ExerciseCategory?,
revisedSetText: Pair<String, Color?>,
) {
Column(modifier = Modifier.fillMaxWidth()) {
Expand Down Expand Up @@ -192,10 +188,10 @@ fun SessionExerciseSetItem(
horizontalArrangement = Arrangement.spacedBy(20.dp)
) {
when (exerciseCategory) {
ExerciseCategory.WEIGHTS_AND_REPS -> SetColumnItem(
value = entry.weight.kgToUserPrefStr(),
title = userPrefWeightUnitStr()
)
// ExerciseCategory.WEIGHTS_AND_REPS -> SetColumnItem(
// value = entry.weight.kgToUserPrefStr(),
// title = userPrefWeightUnitStr()
// )
// TODO fix this
// ExerciseCategory.DISTANCE_AND_TIME -> SetColumnItem(
// value = entry.distance.kmToUserPrefStr(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<string name="reps_uppercase">REPS</string>
<string name="time">Time</string>
<string name="time_uppercase">TIME</string>
<string name="duration_uppercase">DURATION</string>
<string name="volume">Volume</string>
<string name="sets">Sets</string>
<string name="set_uppercase">SET</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "0df17bb8a8b397dd92836c9e2bad51c5",
"identityHash": "baa026f2e70b0fe57b0397861783db93",
"entities": [
{
"tableName": "body_parts",
Expand Down Expand Up @@ -198,7 +198,7 @@
},
{
"tableName": "exercises",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`exercise_id` TEXT NOT NULL, `name` TEXT, `notes` TEXT, `primary_muscle_tag` TEXT, `secondary_muscle_tag` TEXT, `category` TEXT NOT NULL, `created_at` INTEGER, `update_at` INTEGER, PRIMARY KEY(`exercise_id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`exercise_id` TEXT NOT NULL, `name` TEXT, `notes` TEXT, `primary_muscle_tag` TEXT, `secondary_muscle_tag` TEXT, `category` TEXT, `created_at` INTEGER, `update_at` INTEGER, PRIMARY KEY(`exercise_id`))",
"fields": [
{
"fieldPath": "exerciseId",
Expand Down Expand Up @@ -234,7 +234,7 @@
"fieldPath": "category",
"columnName": "category",
"affinity": "TEXT",
"notNull": true
"notNull": false
},
{
"fieldPath": "createdAt",
Expand Down Expand Up @@ -908,7 +908,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0df17bb8a8b397dd92836c9e2bad51c5')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'baa026f2e70b0fe57b0397861783db93')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
package com.ankitsuda.rebound.data.db

import androidx.room.TypeConverter
import com.ankitsuda.base.util.C
import com.ankitsuda.base.utils.toEpochMillis
import com.ankitsuda.base.utils.toLocalDateTime
import com.ankitsuda.rebound.domain.*
import com.ankitsuda.rebound.domain.entities.BodyPartUnitType
import java.text.DateFormat
import java.text.ParseException
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.util.*

Expand All @@ -31,14 +28,14 @@ object Converters {
@TypeConverter
@JvmStatic
fun toExerciseCategory(value: String): ExerciseCategory {
return value.parseToExerciseCategory()
return value.parseToExerciseCategory1()

}

@TypeConverter
@JvmStatic
fun fromExerciseCategory(category: ExerciseCategory?): String {
return category?.tag ?: ExerciseCategory.UNKNOWN.tag
fun fromExerciseCategory(category: ExerciseCategory?): String? {
return category?.tag
}

@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ExercisesRepository @Inject constructor(
notes: String? = null,
primaryMuscleTag: String? = null,
secondaryMuscleTag: String? = null,
category: ExerciseCategory = ExerciseCategory.UNKNOWN,
category: ExerciseCategory? = null,
) {
exercisesDao.insertExercise(
Exercise(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,88 @@

package com.ankitsuda.rebound.domain

import android.content.res.TypedArray

enum class ExerciseCategory(val tag: String) {
WEIGHTS_AND_REPS("weights_and_reps"),
BODYWEIGHT_REPS("bodyweight_reps"),
WEIGHTED_BODYWEIGHT("weighted_bodyweight"),
ASSISTED_BODYWEIGHT("assisted_bodyweight"),
DURATION("duration"),
DISTANCE_AND_DURATION("distance_and_duration"),
WEIGHT_AND_DISTANCE("weight_and_distance"),
WEIGHT_AND_DURATION("weight_and_duration"),
UNKNOWN("unknown");
enum class SetFieldValueType {
WEIGHT,
ADDITIONAL_WEIGHT,
ASSISTED_WEIGHT,
REPS,
RPE,
DISTANCE,
DURATION;
}

fun String?.parseToExerciseCategory(): ExerciseCategory {
return ExerciseCategory.values().find { it.tag == this } ?: ExerciseCategory.UNKNOWN
sealed class ExerciseCategory(open val tag: String, open val fields: List<SetFieldValueType>) {
object WeightAndReps : ExerciseCategory(
tag = "weights_and_reps",
fields = listOf(SetFieldValueType.WEIGHT, SetFieldValueType.REPS, SetFieldValueType.RPE)
)

object BodyweightReps : ExerciseCategory(
tag = "bodyweight_reps",
fields = listOf(SetFieldValueType.REPS, SetFieldValueType.RPE)
)

object WeightedBodyweight : ExerciseCategory(
tag = "weighted_bodyweight",
fields = listOf(
SetFieldValueType.ADDITIONAL_WEIGHT,
SetFieldValueType.REPS,
SetFieldValueType.RPE
)
)

object AssistedBodyweight : ExerciseCategory(
tag = "assisted_bodyweight",
fields = listOf(
SetFieldValueType.ASSISTED_WEIGHT,
SetFieldValueType.REPS,
SetFieldValueType.RPE
)
)

object Duration : ExerciseCategory(
tag = "duration",
fields = listOf(SetFieldValueType.DURATION)
)

object DistanceAndDuration : ExerciseCategory(
tag = "distance_and_duration",
fields = listOf(SetFieldValueType.DISTANCE, SetFieldValueType.DURATION)
)

object WeightAndDistance : ExerciseCategory(
tag = "weight_and_distance",
fields = listOf(SetFieldValueType.WEIGHT, SetFieldValueType.DISTANCE)
)

object WeightAndDuration : ExerciseCategory(
tag = "weight_and_duration",
fields = listOf(SetFieldValueType.WEIGHT, SetFieldValueType.DURATION)
)

data class Unknown(
override val tag: String,
override val fields: List<SetFieldValueType>
) : ExerciseCategory(
tag = tag,
fields = fields
)
}

val allExerciseCategories = listOf(
ExerciseCategory.WeightAndReps,
ExerciseCategory.BodyweightReps,
ExerciseCategory.WeightedBodyweight,
ExerciseCategory.AssistedBodyweight,
ExerciseCategory.Duration,
ExerciseCategory.DistanceAndDuration,
ExerciseCategory.WeightAndDistance,
ExerciseCategory.WeightAndDuration,
)

fun String?.parseToExerciseCategory1(): ExerciseCategory {
return allExerciseCategories.find { it.tag == this } ?: ExerciseCategory.Unknown(
tag = this ?: "",
fields = emptyList()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ package com.ankitsuda.rebound.domain.entities
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.ankitsuda.rebound.domain.ExerciseCategory
import com.ankitsuda.rebound.domain.WeightUnit
import java.time.LocalDateTime
import java.util.*

@Entity(tableName = "barbells")
data class Barbell(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.room.Entity
import androidx.room.PrimaryKey
import com.ankitsuda.rebound.domain.ExerciseCategory
import java.time.LocalDateTime
import java.util.*

@Entity(tableName = "exercises")
data class Exercise(
Expand All @@ -38,7 +37,7 @@ data class Exercise(
@ColumnInfo(name = "secondary_muscle_tag")
var secondaryMuscleTag: String? = null,
@ColumnInfo(name = "category")
var category: ExerciseCategory = ExerciseCategory.UNKNOWN,
var category: ExerciseCategory? = null,

@ColumnInfo(name = "created_at")
var createdAt: LocalDateTime? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ package com.ankitsuda.rebound.domain.entities
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.ankitsuda.rebound.domain.ExerciseCategory
import com.ankitsuda.rebound.domain.WeightUnit
import java.time.LocalDateTime
import java.util.*

@Entity(tableName = "plates")
data class Plate(
Expand Down
Loading

0 comments on commit 34c8780

Please sign in to comment.