This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
368 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ enum class ReboundKeyboardType { | |
REPS, | ||
DISTANCE, | ||
TIME, | ||
WARMUP_SET; | ||
WARMUP_SET, | ||
RPE; | ||
} |
60 changes: 60 additions & 0 deletions
60
...les/ui-keyboard/src/main/java/com/ankitsuda/rebound/ui/keyboard/rpe/RpePickerComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.ui.keyboard.rpe | ||
|
||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.ankitsuda.base.util.toReadableString | ||
|
||
@Composable | ||
internal fun RpePickerComponent( | ||
modifier: Modifier, | ||
onSetText: (String) -> Unit, | ||
text: String?, | ||
refreshKey: Any?, | ||
) { | ||
var rpe: Float? by remember(text) { | ||
mutableStateOf(text?.toFloatOrNull().takeIf { allRPEs.any { r -> r == it } }) | ||
} | ||
|
||
Box( | ||
modifier = modifier, | ||
contentAlignment = Alignment.Center | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(16.dp), | ||
verticalArrangement = Arrangement.spacedBy(16.dp) | ||
) { | ||
SelectedRpeOverview( | ||
modifier = Modifier.fillMaxWidth(), | ||
rpe = rpe, | ||
) | ||
RpeSlider( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = rpe, | ||
refreshKey = refreshKey, | ||
onValueChange = { | ||
rpe = it | ||
onSetText(rpe?.toReadableString()?:"") | ||
} | ||
) | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
modules/ui-keyboard/src/main/java/com/ankitsuda/rebound/ui/keyboard/rpe/RpeSlider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.ui.keyboard.rpe | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Slider | ||
import androidx.compose.material.SliderDefaults | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.nativeCanvas | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.dp | ||
import com.ankitsuda.base.util.toLegacyInt | ||
import com.ankitsuda.base.util.toReadableString | ||
import com.ankitsuda.rebound.ui.theme.ReboundTheme | ||
import kotlin.math.roundToInt | ||
|
||
internal val allRPEs = listOf(null, 6f, 7f, 7.5f, 8f, 8.5f, 9f, 9.5f, 10f) | ||
|
||
@Composable | ||
internal fun RpeSlider( | ||
modifier: Modifier, | ||
value: Float?, | ||
refreshKey: Any?, | ||
onValueChange: (Float?) -> Unit, | ||
) { | ||
var mValue by remember(refreshKey) { | ||
mutableStateOf(with(allRPEs.indexOf(value)) { | ||
if (this == -1) 0f else this.toFloat() | ||
}) | ||
} | ||
|
||
val drawPadding = with(LocalDensity.current) { 10.dp.toPx() } | ||
val textSize = with(LocalDensity.current) { 10.dp.toPx() } | ||
val lineHeightDp = 10.dp | ||
val lineHeightPx = with(LocalDensity.current) { lineHeightDp.toPx() } | ||
val canvasHeight = 50.dp | ||
val textPaint = android.graphics.Paint().apply { | ||
color = ReboundTheme.colors.onBackground.toLegacyInt() | ||
textAlign = android.graphics.Paint.Align.CENTER | ||
this.textSize = textSize | ||
} | ||
Box( | ||
modifier = modifier, | ||
contentAlignment = Alignment.Center | ||
) { | ||
Canvas( | ||
modifier = Modifier | ||
.height(canvasHeight) | ||
.fillMaxWidth() | ||
.padding( | ||
top = canvasHeight | ||
.div(2) | ||
.minus(lineHeightDp.div(2)) | ||
) | ||
) { | ||
val yStart = 0f | ||
val distance = (size.width.minus(2 * drawPadding)).div(allRPEs.size.minus(1)) | ||
allRPEs.forEachIndexed { index, rpe -> | ||
drawLine( | ||
color = Color.DarkGray, | ||
start = Offset(x = drawPadding + index.times(distance), y = yStart), | ||
end = Offset(x = drawPadding + index.times(distance), y = lineHeightPx) | ||
) | ||
// if (index.rem(2) == 1) { | ||
this.drawContext.canvas.nativeCanvas.drawText( | ||
rpe?.toReadableString() ?: "?", | ||
drawPadding + index.times(distance), | ||
size.height, | ||
textPaint | ||
) | ||
// } | ||
} | ||
} | ||
Slider( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = mValue, | ||
valueRange = 0f..(allRPEs.size - 1).toFloat(), | ||
steps = allRPEs.size - 2, | ||
colors = SliderDefaults.colors( | ||
activeTickColor = Color.Transparent, | ||
inactiveTickColor = Color.Transparent | ||
), | ||
onValueChange = { | ||
mValue = it | ||
onValueChange(allRPEs.getOrNull(it.roundToInt())) | ||
}) | ||
} | ||
} |
Oops, something went wrong.