Skip to content

Commit c0aabc1

Browse files
Pushed back logic to VM and changed animation
1 parent b91c17a commit c0aabc1

4 files changed

Lines changed: 61 additions & 41 deletions

File tree

app/src/main/java/com/cornellappdev/uplift/ui/components/profile/workouts/HistorySection.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ data class HistoryItem(
3535
val time: String,
3636
val date: String,
3737
val timestamp: Long,
38-
val ago: String
38+
val ago: String,
39+
val shortDate: String
3940
)
4041

4142
@Composable
@@ -164,11 +165,11 @@ fun EmptyHistorySection(){
164165
private fun HistorySectionPreview() {
165166
val now = System.currentTimeMillis()
166167
val historyItems = listOf(
167-
HistoryItem("Morrison", "11:00 PM", "March 29, 2024", now - (1 * 24 * 60 * 60 * 1000), "1 day ago"),
168-
HistoryItem("Noyes", "1:00 PM", "March 29, 2024", now - (3 * 24 * 60 * 60 * 1000), "2 days ago"),
169-
HistoryItem("Teagle Up", "2:00 PM", "March 29, 2024", now - (7 * 24 * 60 * 60 * 1000), "1 day ago"),
170-
HistoryItem("Teagle Down", "12:00 PM", "March 29, 2024", now - (15 * 24 * 60 * 60 * 1000), "1 day ago"),
171-
HistoryItem("Helen Newman", "10:00 AM", "March 29, 2024", now, "Today"),
168+
HistoryItem("Morrison", "11:00 PM", "March 29, 2024", now - (1 * 24 * 60 * 60 * 1000), "1 day ago", "Mar 28"),
169+
HistoryItem("Noyes", "1:00 PM", "March 29, 2024", now - (3 * 24 * 60 * 60 * 1000), "2 days ago", "Mar 26"),
170+
HistoryItem("Teagle Up", "2:00 PM", "March 29, 2024", now - (7 * 24 * 60 * 60 * 1000), "1 week ago", "Mar 22"),
171+
HistoryItem("Teagle Down", "12:00 PM", "March 29, 2024", now - (15 * 24 * 60 * 60 * 1000), "2 weeks ago", "Mar 14"),
172+
HistoryItem("Helen Newman", "10:00 AM", "March 29, 2024", now, "Today", "Mar 29"),
172173
)
173174
Column(
174175
modifier = Modifier

app/src/main/java/com/cornellappdev/uplift/ui/screens/profile/ProfileScreen.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ private fun ProfileScreenTopBar(
170170
private fun ProfileScreenContentPreview() {
171171
val now = System.currentTimeMillis()
172172
val historyItems = listOf(
173-
HistoryItem("Morrison", "11:00 PM", "March 29, 2024", now - (1 * 24 * 60 * 60 * 1000), "1 day ago"),
174-
HistoryItem("Noyes", "1:00 PM", "March 29, 2024", now - (3 * 24 * 60 * 60 * 1000), "2 days ago"),
175-
HistoryItem("Teagle Up", "2:00 PM", "March 29, 2024", now - (7 * 24 * 60 * 60 * 1000), "1 day ago"),
176-
HistoryItem("Teagle Down", "12:00 PM", "March 29, 2024", now - (15 * 24 * 60 * 60 * 1000), "1 day ago"),
177-
HistoryItem("Helen Newman", "10:00 AM", "March 29, 2024", now, "Today"),
173+
HistoryItem("Morrison", "11:00 PM", "March 29, 2024", now, "Today", "Mar 29"),
174+
HistoryItem("Noyes", "1:00 PM", "March 28, 2024", now - 86400000L, "Yesterday", "Mar 28"),
175+
HistoryItem("Teagle Up", "2:00 PM", "February 15, 2024", now - 4000000000L, "1 month ago", "Feb 15"),
176+
HistoryItem("Helen Newman", "9:30 AM", "February 10, 2024", now - 4430000000L, "1 month ago", "Feb 10"),
177+
HistoryItem("Morrison", "6:45 PM", "February 3, 2024", now - 5030000000L, "1 month ago", "Feb 3")
178178
)
179179
ProfileScreenContent(
180180
uiState = ProfileUiState(

app/src/main/java/com/cornellappdev/uplift/ui/screens/profile/WorkoutHistoryScreen.kt

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ package com.cornellappdev.uplift.ui.screens.profile
22

33
import androidx.compose.animation.AnimatedContent
44
import androidx.compose.animation.AnimatedVisibility
5+
import androidx.compose.animation.animateContentSize
6+
import androidx.compose.animation.core.FastOutSlowInEasing
7+
import androidx.compose.animation.core.tween
58
import androidx.compose.animation.expandVertically
69
import androidx.compose.animation.fadeIn
710
import androidx.compose.animation.fadeOut
811
import androidx.compose.animation.shrinkVertically
12+
import androidx.compose.animation.togetherWith
913
import androidx.compose.foundation.background
1014
import androidx.compose.foundation.border
1115
import androidx.compose.foundation.clickable
@@ -332,7 +336,6 @@ private fun WorkoutHistoryCalendarView(workoutDates: Map<LocalDate,List<HistoryI
332336
if (date != null) {
333337
val hasWorkout = workoutDates.containsKey(date)
334338
val isToday = date == LocalDate.now()
335-
val isSelected = selectedDate == date
336339

337340
CalendarDayCell(
338341
day = date.dayOfMonth.toString(),
@@ -352,26 +355,40 @@ private fun WorkoutHistoryCalendarView(workoutDates: Map<LocalDate,List<HistoryI
352355
// Dropdown
353356
val selectedInThisWeek = week.find { it == selectedDate }
354357

355-
AnimatedVisibility(
356-
visible = selectedInThisWeek != null,
357-
enter = fadeIn() + expandVertically(),
358-
exit = fadeOut() + shrinkVertically()
358+
Column(
359+
modifier = Modifier.animateContentSize(
360+
animationSpec = tween(450)
361+
)
359362
) {
360-
selectedInThisWeek?.let { selected ->
361-
val workouts = workoutDates[selected] ?: emptyList()
362-
val dayOfWeekIndex = week.indexOf(selected)
363-
364-
Column {
365-
Spacer(modifier = Modifier.height(12.dp))
366-
workouts.forEach { workout ->
367-
WorkoutCalendarDropdown(
368-
historyItem = workout,
369-
dayOfWeekIndex = dayOfWeekIndex
370-
)
363+
AnimatedVisibility(
364+
visible = selectedInThisWeek != null,
365+
enter = fadeIn(tween(300)) + expandVertically(
366+
expandFrom = Alignment.Top,
367+
animationSpec = tween(350)
368+
),
369+
exit = fadeOut(tween(800)) + shrinkVertically(
370+
shrinkTowards = Alignment.Top,
371+
animationSpec = tween(700)
372+
)
373+
) {
374+
selectedInThisWeek?.let { selected ->
375+
val workouts = workoutDates[selected] ?: emptyList()
376+
val dayOfWeekIndex = week.indexOf(selected)
377+
378+
Column {
379+
Spacer(modifier = Modifier.height(12.dp))
380+
381+
workouts.forEach { workout ->
382+
WorkoutCalendarDropdown(
383+
historyItem = workout,
384+
dayOfWeekIndex = dayOfWeekIndex
385+
)
386+
}
371387
}
372388
}
373389
}
374390
}
391+
375392
}
376393
}
377394
}
@@ -380,7 +397,7 @@ private fun WorkoutHistoryCalendarView(workoutDates: Map<LocalDate,List<HistoryI
380397
}
381398

382399

383-
@Composable
400+
@Composable
384401
private fun WorkoutCalendarDropdown(
385402
historyItem: HistoryItem,
386403
dayOfWeekIndex: Int
@@ -476,14 +493,9 @@ private fun WorkoutCalendarDropdown(
476493
.background(GRAY04, CircleShape)
477494
)
478495
Spacer(modifier = Modifier.width(4.dp))
479-
val shortDate = remember(historyItem.timestamp) {
480-
Instant.ofEpochMilli(historyItem.timestamp)
481-
.atZone(ZoneId.systemDefault())
482-
.toLocalDate()
483-
.format(DateTimeFormatter.ofPattern("MMM d", Locale.US))
484-
}
496+
485497
Text(
486-
text = shortDate,
498+
text = historyItem.shortDate,
487499
fontFamily = montserratFamily,
488500
fontSize = 12.sp,
489501
fontWeight = FontWeight.Medium,
@@ -553,11 +565,11 @@ private fun CalendarDayCell(
553565
private fun WorkoutHistoryScreenPreview() {
554566
val now = System.currentTimeMillis()
555567
val historyItems = listOf(
556-
HistoryItem("Morrison", "11:00 PM", "March 29, 2024", now, "Today"),
557-
HistoryItem("Noyes", "1:00 PM", "March 28, 2024", now - 86400000L, "Yesterday"),
558-
HistoryItem("Teagle Up", "2:00 PM", "February 15, 2024", now - 4000000000L, "1 month ago"),
559-
HistoryItem("Helen Newman", "9:30 AM", "February 10, 2024", now - 4430000000L, "1 month ago"),
560-
HistoryItem("Morrison", "6:45 PM", "February 3, 2024", now - 5030000000L, "1 month ago")
568+
HistoryItem("Morrison", "11:00 PM", "March 29, 2024", now, "Today", "Mar 29"),
569+
HistoryItem("Noyes", "1:00 PM", "March 28, 2024", now - 86400000L, "Yesterday", "Mar 28"),
570+
HistoryItem("Teagle Up", "2:00 PM", "February 15, 2024", now - 4000000000L, "1 month ago", "Feb 15"),
571+
HistoryItem("Helen Newman", "9:30 AM", "February 10, 2024", now - 4430000000L, "1 month ago", "Feb 10"),
572+
HistoryItem("Morrison", "6:45 PM", "February 3, 2024", now - 5030000000L, "1 month ago", "Feb 3")
561573
)
562574

563575
val listItems = buildList {

app/src/main/java/com/cornellappdev/uplift/ui/viewmodels/profile/ProfileViewModel.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import java.time.Instant
1717
import java.time.LocalDate
1818
import java.time.ZoneId
1919
import java.time.format.DateTimeFormatter
20+
import java.time.temporal.TemporalQueries.localDate
2021
import java.util.Locale
2122
import javax.inject.Inject
2223

@@ -87,7 +88,8 @@ class ProfileViewModel @Inject constructor(
8788
time = formatTime.format(workoutInstant),
8889
date = formatDate.format(workoutInstant),
8990
timestamp = it.timestamp,
90-
ago = calendar.timeAgoString()
91+
ago = calendar.timeAgoString(),
92+
shortDate = shortDateFormatter.format(workoutInstant)
9193
)
9294
}
9395

@@ -196,4 +198,9 @@ class ProfileViewModel @Inject constructor(
196198
.ofPattern("EEE")
197199
.withLocale(Locale.US)
198200
.withZone(ZoneId.systemDefault())
201+
202+
private val shortDateFormatter = DateTimeFormatter
203+
.ofPattern("MMM, d")
204+
.withLocale(Locale.US)
205+
.withZone(ZoneId.systemDefault())
199206
}

0 commit comments

Comments
 (0)