From eac1dabbd744ebee8c9410f3dbf353ec69ad4cc0 Mon Sep 17 00:00:00 2001 From: Ankit Suda Date: Tue, 22 Nov 2022 16:26:28 +0530 Subject: [PATCH] Change exercise history order --- .../java/com/ankitsuda/rebound/data/db/daos/ExercisesDao.kt | 2 +- .../ui/exercise_details/ExerciseDetailScreenViewModel.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core-data/src/main/java/com/ankitsuda/rebound/data/db/daos/ExercisesDao.kt b/modules/core-data/src/main/java/com/ankitsuda/rebound/data/db/daos/ExercisesDao.kt index 0739bf5a..43e042ad 100644 --- a/modules/core-data/src/main/java/com/ankitsuda/rebound/data/db/daos/ExercisesDao.kt +++ b/modules/core-data/src/main/java/com/ankitsuda/rebound/data/db/daos/ExercisesDao.kt @@ -40,7 +40,7 @@ interface ExercisesDao { fun getAllLogEntries(exerciseId: String): Flow> @Transaction - @Query("SELECT exercise_workout_junctions.* FROM exercise_workout_junctions JOIN workouts WHERE exercise_id = :exerciseId AND workouts.id = workout_id AND workouts.is_hidden = 0 AND workouts.in_progress = 0 ORDER BY start_at") + @Query("SELECT exercise_workout_junctions.* FROM exercise_workout_junctions JOIN workouts WHERE exercise_id = :exerciseId AND workouts.id = workout_id AND workouts.is_hidden = 0 AND workouts.in_progress = 0 ORDER BY start_at DESC") fun getVisibleLogEntries(exerciseId: String): Flow> @Transaction diff --git a/modules/ui-exercise-details/src/main/java/com/ankitsuda/rebound/ui/exercise_details/ExerciseDetailScreenViewModel.kt b/modules/ui-exercise-details/src/main/java/com/ankitsuda/rebound/ui/exercise_details/ExerciseDetailScreenViewModel.kt index 8e381474..3babc621 100644 --- a/modules/ui-exercise-details/src/main/java/com/ankitsuda/rebound/ui/exercise_details/ExerciseDetailScreenViewModel.kt +++ b/modules/ui-exercise-details/src/main/java/com/ankitsuda/rebound/ui/exercise_details/ExerciseDetailScreenViewModel.kt @@ -17,6 +17,7 @@ package com.ankitsuda.rebound.ui.exercise_details import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ankitsuda.base.utils.toEpochMillis import com.ankitsuda.navigation.EXERCISE_ID_KEY import com.ankitsuda.rebound.data.repositories.ExercisesRepository import com.ankitsuda.rebound.domain.entities.LogEntriesWithWorkout @@ -54,7 +55,8 @@ class ExerciseDetailScreenViewModel @Inject constructor( val maxWeights = arrayListOf() val totalVolumes = arrayListOf() - val entriesGroup = entriesWithWorkout.groupBy { it.workout.createdAt?.toLocalDate() } + val entriesGroup = entriesWithWorkout.sortedBy { it.workout.startAt?.toEpochMillis() } + .groupBy { it.workout.createdAt?.toLocalDate() } for (group in entriesGroup) { val label = group.key?.format(DateTimeFormatter.ofPattern("MMM d")) ?: ""