adds velocity in mph / km/h to track statistics sheet (see #69)
This commit is contained in:
parent
e0e47ea279
commit
befdeff428
5 changed files with 73 additions and 27 deletions
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.y20k.trackbook.helpers
|
package org.y20k.trackbook.helpers
|
||||||
|
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.math.RoundingMode
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -27,13 +29,13 @@ import java.util.*
|
||||||
object LengthUnitHelper {
|
object LengthUnitHelper {
|
||||||
|
|
||||||
|
|
||||||
/* Converts for the given uni System a distance value to a readable string */
|
/* Converts for the given unit system a distance value to a readable string */
|
||||||
fun convertDistanceToString(distance: Float, useImperial: Boolean = false): String {
|
fun convertDistanceToString(distance: Float, useImperial: Boolean = false): String {
|
||||||
return convertDistanceToString(distance.toDouble(), useImperial)
|
return convertDistanceToString(distance.toDouble(), useImperial)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Converts for the given uni System a distance value to a readable string */
|
/* Converts for the given unit system a distance value to a readable string */
|
||||||
fun convertDistanceToString(distance: Double, useImperial: Boolean = false): String {
|
fun convertDistanceToString(distance: Double, useImperial: Boolean = false): String {
|
||||||
val readableDistance: Double
|
val readableDistance: Double
|
||||||
val unit: String
|
val unit: String
|
||||||
|
@ -93,6 +95,22 @@ object LengthUnitHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Converts for the given unit System distance and duration values to a readable velocity string */
|
||||||
|
fun convertToVelocityString(trackDuration: Long, trackRecordingPause: Long, trackLength: Float, useImperialUnits: Boolean = false) : String {
|
||||||
|
// duration minus pause in seconds
|
||||||
|
val duration: Long = (trackDuration - trackRecordingPause) / 1000L
|
||||||
|
// speed in km/h / mph
|
||||||
|
val velocity: Double = convertMetersPerSecond((trackLength / duration), useImperialUnits)
|
||||||
|
// create readable speed string
|
||||||
|
var bd: BigDecimal = BigDecimal.valueOf(velocity)
|
||||||
|
bd = bd.setScale(1, RoundingMode.HALF_UP)
|
||||||
|
when (useImperialUnits) {
|
||||||
|
true -> return "${bd.toPlainString()} mph"
|
||||||
|
false -> return "${bd.toPlainString()} km/h"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Coverts meters per second to either km/h or mph */
|
/* Coverts meters per second to either km/h or mph */
|
||||||
fun convertMetersPerSecond(metersPerSecond: Float, useImperial: Boolean = false): Double {
|
fun convertMetersPerSecond(metersPerSecond: Float, useImperial: Boolean = false): Double {
|
||||||
if (useImperial) {
|
if (useImperial) {
|
||||||
|
|
|
@ -73,6 +73,7 @@ data class TrackFragmentLayoutHolder(var context: Context, var inflater: LayoutI
|
||||||
private val stepsView: MaterialTextView
|
private val stepsView: MaterialTextView
|
||||||
private val waypointsView: MaterialTextView
|
private val waypointsView: MaterialTextView
|
||||||
private val durationView: MaterialTextView
|
private val durationView: MaterialTextView
|
||||||
|
private val velocityView: MaterialTextView
|
||||||
private val recordingStartView: MaterialTextView
|
private val recordingStartView: MaterialTextView
|
||||||
private val recordingStopView: MaterialTextView
|
private val recordingStopView: MaterialTextView
|
||||||
private val recordingPausedView: MaterialTextView
|
private val recordingPausedView: MaterialTextView
|
||||||
|
@ -112,6 +113,7 @@ data class TrackFragmentLayoutHolder(var context: Context, var inflater: LayoutI
|
||||||
stepsView = rootView.findViewById(R.id.statistics_data_steps)
|
stepsView = rootView.findViewById(R.id.statistics_data_steps)
|
||||||
waypointsView = rootView.findViewById(R.id.statistics_data_waypoints)
|
waypointsView = rootView.findViewById(R.id.statistics_data_waypoints)
|
||||||
durationView = rootView.findViewById(R.id.statistics_data_duration)
|
durationView = rootView.findViewById(R.id.statistics_data_duration)
|
||||||
|
velocityView = rootView.findViewById(R.id.statistics_data_velocity)
|
||||||
recordingStartView = rootView.findViewById(R.id.statistics_data_recording_start)
|
recordingStartView = rootView.findViewById(R.id.statistics_data_recording_start)
|
||||||
recordingStopView = rootView.findViewById(R.id.statistics_data_recording_stop)
|
recordingStopView = rootView.findViewById(R.id.statistics_data_recording_stop)
|
||||||
recordingPausedLabelView = rootView.findViewById(R.id.statistics_p_recording_paused)
|
recordingPausedLabelView = rootView.findViewById(R.id.statistics_p_recording_paused)
|
||||||
|
@ -185,6 +187,7 @@ data class TrackFragmentLayoutHolder(var context: Context, var inflater: LayoutI
|
||||||
stepsView.text = steps
|
stepsView.text = steps
|
||||||
waypointsView.text = track.wayPoints.size.toString()
|
waypointsView.text = track.wayPoints.size.toString()
|
||||||
durationView.text = DateTimeHelper.convertToReadableTime(context, track.duration)
|
durationView.text = DateTimeHelper.convertToReadableTime(context, track.duration)
|
||||||
|
velocityView.text = LengthUnitHelper.convertToVelocityString(track.duration, track.recordingPaused, track.length, useImperialUnits)
|
||||||
recordingStartView.text = DateTimeHelper.convertToReadableDateAndTime(track.recordingStart)
|
recordingStartView.text = DateTimeHelper.convertToReadableDateAndTime(track.recordingStart)
|
||||||
recordingStopView.text = DateTimeHelper.convertToReadableDateAndTime(track.recordingStart)
|
recordingStopView.text = DateTimeHelper.convertToReadableDateAndTime(track.recordingStart)
|
||||||
maxAltitudeView.text = LengthUnitHelper.convertDistanceToString(track.maxAltitude, useImperialUnits)
|
maxAltitudeView.text = LengthUnitHelper.convertDistanceToString(track.maxAltitude, useImperialUnits)
|
||||||
|
|
|
@ -166,6 +166,52 @@
|
||||||
app:layout_constraintTop_toTopOf="@+id/statistics_p_duration"
|
app:layout_constraintTop_toTopOf="@+id/statistics_p_duration"
|
||||||
tools:text="@string/sample_text_default_data" />
|
tools:text="@string/sample_text_default_data" />
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/statistics_p_recording_paused"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/statistics_sheet_p_recording_paused"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
||||||
|
android:textColor="@color/text_lightweight"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/statistics_p_duration"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/statistics_p_duration" />
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/statistics_data_recording_paused"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
|
||||||
|
android:textColor="@color/text_default"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_recording_paused"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/statistics_p_recording_paused"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/statistics_p_recording_paused"
|
||||||
|
tools:text="@string/sample_text_default_data" />
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/statistics_p_velocity"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/statistics_sheet_p_velocity"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
||||||
|
android:textColor="@color/text_lightweight"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/statistics_p_recording_paused"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/statistics_p_recording_paused" />
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/statistics_data_velocity"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
|
||||||
|
android:textColor="@color/text_default"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_velocity"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/statistics_p_velocity"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/statistics_p_velocity"
|
||||||
|
tools:text="@string/sample_text_default_data" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/statistics_p_recording_start"
|
android:id="@+id/statistics_p_recording_start"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -174,8 +220,8 @@
|
||||||
android:text="@string/statistics_sheet_p_recording_start"
|
android:text="@string/statistics_sheet_p_recording_start"
|
||||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
||||||
android:textColor="@color/text_lightweight"
|
android:textColor="@color/text_lightweight"
|
||||||
app:layout_constraintStart_toStartOf="@+id/statistics_p_recording_paused"
|
app:layout_constraintStart_toStartOf="@+id/statistics_p_velocity"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/statistics_p_recording_paused" />
|
app:layout_constraintTop_toBottomOf="@+id/statistics_p_velocity" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/statistics_data_recording_start"
|
android:id="@+id/statistics_data_recording_start"
|
||||||
|
@ -212,29 +258,6 @@
|
||||||
app:layout_constraintTop_toTopOf="@+id/statistics_p_recording_stop"
|
app:layout_constraintTop_toTopOf="@+id/statistics_p_recording_stop"
|
||||||
tools:text="@string/sample_text_default_data" />
|
tools:text="@string/sample_text_default_data" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
|
||||||
android:id="@+id/statistics_data_recording_paused"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
|
|
||||||
android:textColor="@color/text_default"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_recording_paused"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/statistics_p_recording_paused"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/statistics_p_recording_paused"
|
|
||||||
tools:text="@string/sample_text_default_data" />
|
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
|
||||||
android:id="@+id/statistics_p_recording_paused"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="@string/statistics_sheet_p_recording_paused"
|
|
||||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
|
||||||
android:textColor="@color/text_lightweight"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/statistics_p_duration"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/statistics_p_duration" />
|
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/statistics_p_positive_elevation"
|
android:id="@+id/statistics_p_positive_elevation"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
<string name="statistics_sheet_p_min_altitude">Tiefster Wegpunkt:</string>
|
<string name="statistics_sheet_p_min_altitude">Tiefster Wegpunkt:</string>
|
||||||
<string name="statistics_sheet_p_positive_elevation">Höhenmeter (bergauf):</string>
|
<string name="statistics_sheet_p_positive_elevation">Höhenmeter (bergauf):</string>
|
||||||
<string name="statistics_sheet_p_negative_elevation">Höhenmeter (bergab):</string>
|
<string name="statistics_sheet_p_negative_elevation">Höhenmeter (bergab):</string>
|
||||||
|
<string name="statistics_sheet_p_velocity">Durchschnittliche Geschwindigkeit:</string>
|
||||||
<!-- onboarding layout -->
|
<!-- onboarding layout -->
|
||||||
<string name="layout_onboarding_description_app_icon">Trackbook App-Symbol</string>
|
<string name="layout_onboarding_description_app_icon">Trackbook App-Symbol</string>
|
||||||
<!-- track tab onboarding -->
|
<!-- track tab onboarding -->
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
<string name="statistics_sheet_p_min_altitude">Lowest waypoint:</string>
|
<string name="statistics_sheet_p_min_altitude">Lowest waypoint:</string>
|
||||||
<string name="statistics_sheet_p_positive_elevation">Elevation (uphill):</string>
|
<string name="statistics_sheet_p_positive_elevation">Elevation (uphill):</string>
|
||||||
<string name="statistics_sheet_p_negative_elevation">Elevation (downhill):</string>
|
<string name="statistics_sheet_p_negative_elevation">Elevation (downhill):</string>
|
||||||
|
<string name="statistics_sheet_p_velocity">Average velocity:</string>
|
||||||
<!-- Recording Quick Settings Tile -->
|
<!-- Recording Quick Settings Tile -->
|
||||||
<string name="quick_settings_tile_title_default">Recording</string>
|
<string name="quick_settings_tile_title_default">Recording</string>
|
||||||
<string name="quick_settings_tile_title_start">Start Recording</string>
|
<string name="quick_settings_tile_title_start">Start Recording</string>
|
||||||
|
|
Loading…
Reference in a new issue