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

Commit

Permalink
Add lbs plates
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 15, 2022
1 parent 7694e81 commit 3cb9956
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import com.ankitsuda.rebound.domain.WeightUnit

@Composable
fun Double?.kgToUserPrefStr(
weightUnit: WeightUnit = LocalAppSettings.current.weightUnit,
addUnitSuffix: Boolean = false,
spaceBeforeSuffix: Boolean = false
): String =
when (LocalAppSettings.current.weightUnit) {
when (weightUnit) {
WeightUnit.KG -> (this ?: 0.0).kgToReadable()
WeightUnit.LBS -> (this ?: 0.0).fromKgToLbsReadable()
} + if (addUnitSuffix) {
Expand All @@ -40,7 +41,10 @@ fun Double?.kgToUserPrefStr(
}

@Composable
fun userPrefWeightUnitStr(): String = when (LocalAppSettings.current.weightUnit) {
fun WeightUnit.localizedStr(): String = when (this) {
WeightUnit.KG -> stringResource(id = R.string.kg)
WeightUnit.LBS -> stringResource(id = R.string.lbs)
}
}

@Composable
fun userPrefWeightUnitStr(): String = LocalAppSettings.current.weightUnit.localizedStr()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "350de1bf4b2380512549238269600f10",
"identityHash": "78f1033c7025b8448214463c96e35563",
"entities": [
{
"tableName": "body_parts",
Expand Down Expand Up @@ -632,7 +632,7 @@
},
{
"tableName": "plates",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `weight` REAL, `weight_unit` TEXT, `is_active` INTEGER, `color` TEXT, `color_value_type` TEXT, `height` REAL, `width` REAL, `created_at` INTEGER, `update_at` INTEGER, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `weight` REAL, `for_weight_unit` TEXT, `is_active` INTEGER, `color` TEXT, `color_value_type` TEXT, `height` REAL, `width` REAL, `created_at` INTEGER, `update_at` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand All @@ -647,8 +647,8 @@
"notNull": false
},
{
"fieldPath": "weightUnit",
"columnName": "weight_unit",
"fieldPath": "forWeightUnit",
"columnName": "for_weight_unit",
"affinity": "TEXT",
"notNull": false
},
Expand Down Expand Up @@ -846,7 +846,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, '350de1bf4b2380512549238269600f10')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '78f1033c7025b8448214463c96e35563')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,15 @@ object Converters {
fun toListOfPersonalRecords(str: String?): List<PersonalRecord>? {
return if (str != null) PersonalRecord.fromCommaSpString(str) else null
}

@TypeConverter
fun toWeightUnit(value: String): WeightUnit {
return WeightUnit.fromValue(value)

}

@TypeConverter
fun fromWeightUnit(unit: WeightUnit?): String {
return (unit ?: WeightUnit.KG).value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.ankitsuda.rebound.data.db

import com.ankitsuda.base.utils.generateId
import com.ankitsuda.rebound.domain.WeightUnit
import com.ankitsuda.rebound.domain.entities.*

object DataGenerator {
Expand Down Expand Up @@ -191,9 +192,11 @@ object DataGenerator {


fun getPlates(): List<Plate> = listOf(
// KG
Plate(
id = generateId(),
weight = 25.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 1F,
width = 1F,
Expand All @@ -203,6 +206,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 20.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 1F,
width = 0.8500000238418579F,
Expand All @@ -212,6 +216,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 15.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 1F,
width = 0.699999988079071F,
Expand All @@ -221,6 +226,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 10.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 1F,
width = 0.550000011920929F,
Expand All @@ -230,6 +236,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 5.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 0.6000000238418579F,
width = 0.6000000238418579F,
Expand All @@ -239,6 +246,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 2.5,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 0.550000011920929F,
width = 0.5F,
Expand All @@ -248,6 +256,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 2.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 0.5F,
width = 0.5F,
Expand All @@ -257,6 +266,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 1.25,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 0.4000000059604645F,
width = 0.5F,
Expand All @@ -266,6 +276,7 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 1.0,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 0.30000001192092896F,
width = 0.5F,
Expand All @@ -275,13 +286,123 @@ object DataGenerator {
Plate(
id = generateId(),
weight = 0.5,
forWeightUnit = WeightUnit.KG,
isActive = true,
height = 0.20000000298023224F,
width = 0.5F,
color = "#ffffff",
colorValueType = "hex"
),
// LBS
Plate(
id = generateId(),
weight = 45.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 1F,
width = 1F,
color = "#db3236",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 35.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 1F,
width = 1F,
color = "#db3236",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 25.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 1F,
width = 0.8500000238418579F,
color = "#4885ed",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 15.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 1F,
width = 0.699999988079071F,
color = "#f4c20d",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 10.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 1F,
width = 0.550000011920929F,
color = "#3cba54",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 5.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 0.6000000238418579F,
width = 0.6000000238418579F,
color = "#ffffff",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 3.3,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 0.550000011920929F,
width = 0.5F,
color = "#db3236",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 2.5,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 0.5F,
width = 0.5F,
color = "#4885ed",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 1.25,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 0.4000000059604645F,
width = 0.5F,
color = "#f4c20d",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 1.0,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 0.30000001192092896F,
width = 0.5F,
color = "#3cba54",
colorValueType = "hex"
),
Plate(
id = generateId(),
weight = 0.5,
forWeightUnit = WeightUnit.LBS,
isActive = true,
height = 0.20000000298023224F,
width = 0.5F,
color = "#ffffff",
colorValueType = "hex"
),
)


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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.*

Expand All @@ -27,10 +28,13 @@ data class Plate(
@ColumnInfo(name = "id")
val id: String,

// weight column is stored in kg
@ColumnInfo(name = "weight")
var weight: Double? = null,
@ColumnInfo(name = "weight_unit")
var weightUnit: String? = null,

// forWeightUnit does not represent weight unit of weight column
@ColumnInfo(name = "for_weight_unit")
var forWeightUnit: WeightUnit? = null,

@ColumnInfo(name = "is_active")
var isActive: Boolean? = null,
Expand Down
Loading

0 comments on commit 3cb9956

Please sign in to comment.