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

Commit

Permalink
i18nize exercise category
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 29, 2022
1 parent c0ca499 commit 81cc936
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun GenericListItemStyle1(
title: String?,
description: String? = null,
isSelected: Boolean = false,
layoutBelowDescription: (@Composable () -> Unit)? = null,
onClick: (() -> Unit)? = null
) {

Expand Down Expand Up @@ -70,6 +71,9 @@ fun GenericListItemStyle1(
color = ReboundTheme.colors.onBackground.copy(alpha = 0.75f)
)
}
layoutBelowDescription?.let {
it()
}
}

if (isSelected) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.common.compose

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.ankitsuda.base.utils.TimePeriod
import com.ankitsuda.rebound.domain.ExerciseCategory

@Composable
fun ExerciseCategory.toI18NString() = toI18NString(LocalContext.current)

@Composable
fun ExerciseCategory.toI18NStringExamples() = toI18NStringExamples(LocalContext.current)

fun ExerciseCategory.toI18NString(context: Context) = context.getString(
when (this) {
ExerciseCategory.AssistedBodyweight -> R.string.exercise_category_assisted_bodyweight_title
ExerciseCategory.BodyweightReps -> R.string.exercise_category_bodyweight_reps_title
ExerciseCategory.DistanceAndDuration -> R.string.exercise_category_distance_and_duration_title
ExerciseCategory.Duration -> R.string.exercise_category_duration_title
ExerciseCategory.WeightAndDistance -> R.string.exercise_category_weight_and_distance_title
ExerciseCategory.WeightAndDuration -> R.string.exercise_category_weight_and_duration_title
ExerciseCategory.WeightAndReps -> R.string.exercise_category_weight_and_reps_title
ExerciseCategory.WeightedBodyweight -> R.string.exercise_category_weighted_bodyweight_title
is ExerciseCategory.Unknown -> R.string.unknown
}
)

fun ExerciseCategory.toI18NStringExamples(context: Context) = context.getString(
when (this) {
ExerciseCategory.AssistedBodyweight -> R.string.exercise_category_assisted_bodyweight_examples
ExerciseCategory.BodyweightReps -> R.string.exercise_category_bodyweight_reps_examples
ExerciseCategory.DistanceAndDuration -> R.string.exercise_category_distance_and_duration_examples
ExerciseCategory.Duration -> R.string.exercise_category_duration_examples
ExerciseCategory.WeightAndDistance -> R.string.exercise_category_weight_and_distance_examples
ExerciseCategory.WeightAndDuration -> R.string.exercise_category_weight_and_duration_examples
ExerciseCategory.WeightAndReps -> R.string.exercise_category_weight_and_reps_examples
ExerciseCategory.WeightedBodyweight -> R.string.exercise_category_weighted_bodyweight_examples
is ExerciseCategory.Unknown -> R.string.unknown_examples
}
)
18 changes: 18 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 @@ -262,4 +262,22 @@
<string name="select_barbell">Select barbell</string>
<string name="select_muscle">Select muscle</string>
<string name="select_category">Select category</string>
<string name="unknown">Unknown</string>
<string name="exercise_category_weight_and_reps_title">Weight &amp; Reps</string>
<string name="exercise_category_bodyweight_reps_title">Bodyweight Reps</string>
<string name="exercise_category_weighted_bodyweight_title">Weighted Bodyweight</string>
<string name="exercise_category_assisted_bodyweight_title">Assisted Bodyweight</string>
<string name="exercise_category_duration_title">Duration</string>
<string name="exercise_category_distance_and_duration_title">Distance &amp; Duration</string>
<string name="exercise_category_weight_and_distance_title">Weight &amp; Distance</string>
<string name="exercise_category_weight_and_duration_title">Weight &amp; Duration</string>
<string name="exercise_category_weight_and_reps_examples">Example: Bench Press, Dumbbell Curls</string>
<string name="exercise_category_bodyweight_reps_examples">Example: Pull Ups, Sit Ups, Burpees</string>
<string name="exercise_category_weighted_bodyweight_examples">Example: Weighted Pull Ups, Weighted Dips</string>
<string name="exercise_category_assisted_bodyweight_examples">Example: Assisted Pull Ups, Assisted Dips</string>
<string name="exercise_category_duration_examples">Example: Planks, Yoga, Stretching</string>
<string name="exercise_category_distance_and_duration_examples">Example: Running, Cycling, Rowing</string>
<string name="exercise_category_weight_and_distance_examples">Example: Farmers Walk, Suitcase Carry</string>
<string name="exercise_category_weight_and_duration_examples">Example: Weighted Planks</string>
<string name="unknown_examples">Unknown examples</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class SetFieldValueType {

sealed class ExerciseCategory(open val tag: String, open val fields: List<SetFieldValueType>) {
object WeightAndReps : ExerciseCategory(
tag = "weights_and_reps",
tag = "weight_and_reps",
fields = listOf(SetFieldValueType.WEIGHT, SetFieldValueType.REPS, SetFieldValueType.RPE)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import androidx.compose.material.icons.outlined.Done
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.ankitsuda.common.compose.toI18NString
import com.ankitsuda.navigation.*
import com.ankitsuda.rebound.ui.components.AppTextField
import com.ankitsuda.rebound.ui.components.BottomSheetSurface
Expand Down Expand Up @@ -170,7 +172,7 @@ fun CreateExerciseScreen(

ValueSelectorCard(
name = stringResource(id = R.string.category),
value = selectedCategoryTag,
value = selectedCategory.toI18NString(),
onClick = {
navigator.navigate(
LeafScreen.ExerciseCategorySelector.createRoute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@

package com.ankitsuda.rebound.ui.exercisecategoryselector.components

import androidx.compose.material.Chip
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ankitsuda.common.compose.toI18NString
import com.ankitsuda.common.compose.toI18NStringExamples
import com.ankitsuda.rebound.domain.ExerciseCategory
import com.ankitsuda.rebound.ui.components.listitems.GenericListItemStyle1
import com.google.accompanist.flowlayout.FlowRow

@OptIn(ExperimentalMaterialApi::class)
@Composable
internal fun ExerciseCategorySelectorListItem(
modifier: Modifier = Modifier,
Expand All @@ -28,8 +36,11 @@ internal fun ExerciseCategorySelectorListItem(
) {
GenericListItemStyle1(
modifier = modifier,
title = exerciseCategory.tag,
title = exerciseCategory.toI18NString(),
description = exerciseCategory.toI18NStringExamples(),
isSelected = isSelected,
onClick = onClick
onClick = onClick,
layoutBelowDescription = {
}
)
}

0 comments on commit 81cc936

Please sign in to comment.