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

Commit

Permalink
Add barbells
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 27, 2022
1 parent e8adf45 commit 1171aeb
Show file tree
Hide file tree
Showing 24 changed files with 1,057 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dependencies {
implementation project(":modules:ui-customize-plates")
implementation project(":modules:common-ui-components-workout-editor")
implementation project(":modules:stopwatch")
implementation project(":modules:ui-customize-barbells")

implementation Deps.Kotlin.coroutinesAndroid
kapt Deps.Android.Lifecycle.compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.ankitsuda.navigation.*
import com.ankitsuda.rebound.ui.calendar.CalendarScreen
import com.ankitsuda.rebound.ui.components.workouteditor.supersetselector.SupersetSelectorBottomSheet
import com.ankitsuda.rebound.ui.create_exercise.CreateExerciseScreen
import com.ankitsuda.rebound.ui.customizebarbells.CustomizeBarbellsScreen
import com.ankitsuda.rebound.ui.customizebarbells.edit.BarbellEditBottomSheet
import com.ankitsuda.rebound.ui.customizeplates.CustomizePlatesScreen
import com.ankitsuda.rebound.ui.customizeplates.edit.PlateEditBottomSheet
import com.ankitsuda.rebound.ui.exercise_details.ExerciseDetailScreen
Expand Down Expand Up @@ -61,9 +63,7 @@ import com.google.accompanist.navigation.material.ExperimentalMaterialNavigation
import kotlinx.coroutines.InternalCoroutinesApi

@OptIn(
InternalCoroutinesApi::class,
ExperimentalMaterialNavigationApi::class,
androidx.compose.animation.ExperimentalAnimationApi::class
ExperimentalAnimationApi::class
)
@Composable
internal fun AppNavigation(
Expand Down Expand Up @@ -190,6 +190,7 @@ private fun NavGraphBuilder.addMoreRoot(navController: NavController) {
addPartMeasurementsScreen(navController)
addSettingsScreen(navController)
addCustomizePlatesScreen(navController)
addCustomizeBarbellsScreen(navController)
addPersonalizationScreen(navController)
addMainColorsPersonalizationScreen(navController)
addShapesPersonalizationScreen(navController)
Expand All @@ -204,6 +205,7 @@ private fun NavGraphBuilder.addMoreRoot(navController: NavController) {

addAddPartMeasurementBottomSheet(navController)
addPlateEditBottomSheet(navController)
addBarbellEditBottomSheet(navController)
}
}

Expand Down Expand Up @@ -293,6 +295,12 @@ private fun NavGraphBuilder.addCustomizePlatesScreen(navController: NavControlle
}
}

private fun NavGraphBuilder.addCustomizeBarbellsScreen(navController: NavController) {
composableScreen(LeafScreen.Barbells()) {
CustomizeBarbellsScreen()
}
}

private fun NavGraphBuilder.addPersonalizationScreen(navController: NavController) {
composableScreen(LeafScreen.Personalization()) {
PersonalizationScreen(navController)
Expand Down Expand Up @@ -383,6 +391,12 @@ private fun NavGraphBuilder.addPlateEditBottomSheet(navController: NavController
}
}

private fun NavGraphBuilder.addBarbellEditBottomSheet(navController: NavController) {
bottomSheetScreen(LeafScreen.BarbellEdit()) {
BarbellEditBottomSheet()
}
}

private fun NavGraphBuilder.addTemplatesFolderEditBottomSheet(navController: NavController) {
bottomSheetScreen(LeafScreen.TemplatesFolderEdit()) {
TemplatesFolderEditBottomSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fun Double.fromKmToMiles() = this * MILES_IN_KM

fun Double.fromKgToLbsReadable() = DecimalFormat("#.##").format(fromKgToLbs())
fun Double.kgToReadable() = DecimalFormat("#.##").format(this)
fun Double.lbsToReadable() = kgToReadable()

fun Double.fromKmToMilesReadable(): String = DecimalFormat("#.###").format(fromKmToMiles())
fun Double.kmToReadable(): String = DecimalFormat("#.###").format(this)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun Double?.kgToUserPrefStr(
" "
} else {
""
} + userPrefWeightUnitStr()
} + userPrefWeightUnitStr(weightUnit = weightUnit)
} else {
""
}
Expand Down Expand Up @@ -64,7 +64,10 @@ fun WeightUnit.localizedStr(case: Int = 2): String = when (this) {
* @param case 0=Pascal Case, 1=Upper Case, 2=Lower Case
*/
@Composable
fun userPrefWeightUnitStr(case: Int = 2): String = LocalAppSettings.current.weightUnit.localizedStr(case = case)
fun userPrefWeightUnitStr(
case: Int = 2,
weightUnit: WeightUnit = LocalAppSettings.current.weightUnit
): String = weightUnit.localizedStr(case = case)

@Composable
fun Double?.kmToUserPrefStr(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.ankitsuda.rebound.ui.icons

import androidx.compose.material.icons.Icons
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.PathFillType.Companion.NonZero
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeCap.Companion.Butt
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.StrokeJoin.Companion.Miter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.ImageVector.Builder
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

public val Icons.Filled.Barbell: ImageVector
get() {
if (_barbell != null) {
return _barbell!!
}
_barbell = Builder(name = "Barbell", defaultWidth = 24.0.dp, defaultHeight = 24.0.dp,
viewportWidth = 24.0f, viewportHeight = 24.0f).apply {
path(fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f,
pathFillType = NonZero) {
moveTo(4.052f, 2.6378f)
lineToRelative(17.3101f, 17.3101f)
lineToRelative(-1.4142f, 1.4142f)
lineToRelative(-17.3101f, -17.3101f)
close()
}
path(fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f,
pathFillType = NonZero) {
moveTo(8.0628f, 3.8201f)
lineToRelative(1.731f, 1.731f)
lineToRelative(-4.2426f, 4.2426f)
lineToRelative(-1.731f, -1.731f)
close()
}
path(fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f,
pathFillType = NonZero) {
moveTo(18.4488f, 14.2062f)
lineToRelative(1.731f, 1.731f)
lineToRelative(-4.2426f, 4.2426f)
lineToRelative(-1.731f, -1.731f)
close()
}
}
.build()
return _barbell!!
}

private var _barbell: ImageVector? = null
6 changes: 6 additions & 0 deletions modules/common-ui-resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<string name="perform_again">Perform Again</string>
<string name="edit_session">Edit session</string>
<string name="customize_barbell_plates">Customize barbell plates</string>
<string name="customize_barbells">Customize barbells</string>
<string name="defaults">Defaults</string>
<string name="weight_unit">Weight Unit</string>
<string name="metric_kg">Metric (kg)</string>
Expand Down Expand Up @@ -212,6 +213,8 @@
<string name="set_keyboard_demo">Set Keyboard Demo</string>
<string name="plate">Plate</string>
<string name="weight">Weight</string>
<string name="weight_kg">Weight (kg)</string>
<string name="weight_lbs">Weight (lbs)</string>
<string name="color">Color</string>
<string name="height_multiplier">Height multiplier</string>
<string name="width_multiplier">Width multiplier</string>
Expand Down Expand Up @@ -252,4 +255,7 @@
<string name="start_time">Start time</string>
<string name="end_time">End time</string>
<string name="duration_error_start_longer_than_end">Start time is longer than end time</string>
<string name="barbells">Barbells</string>
<string name="barbell">Barbell</string>
<string name="add_barbell">Add barbell</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "78f1033c7025b8448214463c96e35563",
"identityHash": "68617553ff75764b3f0264b855b8cd96",
"entities": [
{
"tableName": "body_parts",
Expand Down Expand Up @@ -841,12 +841,68 @@
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "barbells",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT, `weight_kg` REAL, `weight_lbs` REAL, `is_active` INTEGER, `created_at` INTEGER, `update_at` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "weightKg",
"columnName": "weight_kg",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "weightLbs",
"columnName": "weight_lbs",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "isActive",
"columnName": "is_active",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "createdAt",
"columnName": "created_at",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "updatedAt",
"columnName": "update_at",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"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, '78f1033c7025b8448214463c96e35563')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '68617553ff75764b3f0264b855b8cd96')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import kotlinx.coroutines.launch
ThemePreset::class,
ExerciseSetGroupNote::class,
WorkoutTemplatesFolder::class,
Barbell::class
],
version = 1,
exportSchema = true
Expand All @@ -54,6 +55,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun platesDao(): PlatesDao
abstract fun themePresetsDao(): ThemePresetsDao
abstract fun workoutFoldersFoldersDao(): WorkoutFoldersFoldersDao
abstract fun barbellsDao(): BarbellsDao

companion object {
@Volatile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ class DatabaseModule {
@Provides
fun provideWorkoutFoldersFoldersDao(db: AppDatabase) = db.workoutFoldersFoldersDao()

@Provides
fun provideBarbellsDao(db: AppDatabase) = db.barbellsDao()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2022 Ankit Suda.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/

package com.ankitsuda.rebound.data.db.daos

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.ankitsuda.rebound.domain.WeightUnit
import com.ankitsuda.rebound.domain.entities.Muscle
import com.ankitsuda.rebound.domain.entities.Barbell
import kotlinx.coroutines.flow.Flow

@Dao
interface BarbellsDao {

@Query("SELECT * FROM barbells WHERE id = :id")
fun getBarbell(id: String): Flow<Barbell>

@Query("SELECT * FROM barbells ORDER BY name")
fun getBarbells(): Flow<List<Barbell>>

@Query("SELECT * FROM barbells WHERE is_active = 1 ORDER BY name")
fun getActiveBarbells(): Flow<List<Barbell>>

@Query("UPDATE barbells SET is_active = :isActive WHERE id = :barbellId")
suspend fun updateIsActive(barbellId: String, isActive: Boolean)

@Insert
suspend fun insertBarbells(barbells: List<Barbell>)

@Query("DELETE FROM barbells WHERE id = :barbellId")
suspend fun deleteBarbell(barbellId: String)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertBarbell(barbell: Barbell)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 Ankit Suda.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/

package com.ankitsuda.rebound.data.repositories

import com.ankitsuda.rebound.data.db.daos.BarbellsDao
import com.ankitsuda.rebound.domain.WeightUnit
import com.ankitsuda.rebound.domain.entities.Barbell
import javax.inject.Inject

class BarbellsRepository @Inject constructor(private val barbellsDao: BarbellsDao) {

fun getBarbells() = barbellsDao.getBarbells()

fun getActiveBarbells() = barbellsDao.getActiveBarbells()

fun getBarbell(barbellId: String) = barbellsDao.getBarbell(barbellId)

suspend fun upsertBarbell(barbell: Barbell) = barbellsDao.insertBarbell(barbell)

suspend fun updateIsActive(barbellId: String, isActive: Boolean) {
barbellsDao.updateIsActive(barbellId, isActive)
}

suspend fun deleteBarbell(barbellId: String) {
barbellsDao.deleteBarbell(barbellId)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ class RepositoriesModule {
presetsDao: ThemePresetsDao
) =
ThemePresetsRepository(presetsDao)

@Singleton
@Provides
fun provideBarbellsRepository(
barbellsDao: BarbellsDao
) =
BarbellsRepository(barbellsDao)
}
Loading

0 comments on commit 1171aeb

Please sign in to comment.