mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
fix(calendar): the RSVP strip drops its time label past a week
The "Going" strip's right side is a relative label ("in 3 days"), but Android's formatter
falls back to a plain date for anything over a week away, so for most RSVPs the strip said
"October 31" right above the OCT 31 badge and the "Sat, Oct 31" line. The label now only
shows for events that have started or start within a week. Checked on the tablet: RSVPs to
events 11 and 33 days out show just "Going".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6904bba33c
commit
45b3be97fa
+14
-1
@@ -61,6 +61,7 @@ import com.vitorpamplona.quartz.nip52Calendar.appt.day.CalendarDateSlotEvent
|
||||
import com.vitorpamplona.quartz.nip52Calendar.appt.tags.RSVPStatusTag
|
||||
import com.vitorpamplona.quartz.nip52Calendar.appt.time.CalendarTimeSlotEvent
|
||||
import com.vitorpamplona.quartz.nip52Calendar.rsvp.CalendarRSVPEvent
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
/**
|
||||
* Entry for a NIP-52 calendar RSVP: decodes the [Note], makes sure the appointment it answers is
|
||||
@@ -138,10 +139,13 @@ private fun RsvpWithAppointment(
|
||||
val range = remember(appointmentEvent) { formatCalendarRange(appointment, context) }
|
||||
val relative = rememberRelativeTimeLabel(view, appointmentEvent?.id)
|
||||
val route = remember(appointment) { detailRouteFor(appointment) }
|
||||
// Past a week the relative formatter falls back to a plain date ("October 31"), which the
|
||||
// badge and the time line right below already show, so the strip says nothing instead.
|
||||
val startsWithinAWeek = remember(view.startSeconds) { startsWithinAWeek(view.startSeconds, TimeUtils.now()) }
|
||||
|
||||
CalendarRsvpCard(
|
||||
event = event,
|
||||
statusDetail = relative,
|
||||
statusDetail = relative?.takeIf { startsWithinAWeek },
|
||||
onClick = { nav.nav(route) },
|
||||
) {
|
||||
val image = view.image
|
||||
@@ -171,6 +175,15 @@ private fun RsvpWithAppointment(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether [startSeconds] is close enough for "in 3 days" to say something the date does not:
|
||||
* anything that has started, or starts within a week. A missing start has no phrase at all.
|
||||
*/
|
||||
internal fun startsWithinAWeek(
|
||||
startSeconds: Long?,
|
||||
nowSeconds: Long,
|
||||
): Boolean = startSeconds != null && startSeconds - nowSeconds <= TimeUtils.ONE_WEEK
|
||||
|
||||
private val CoverImageModifier = Modifier.fillMaxWidth().aspectRatio(2f)
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.note.types
|
||||
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* The RSVP strip's "in 3 days" label only shows while it says something the date does not: past
|
||||
* a week the formatter falls back to the same date the badge already shows.
|
||||
*/
|
||||
class CalendarRsvpStripLabelTest {
|
||||
private val now = 1_800_000_000L
|
||||
|
||||
@Test
|
||||
fun showsForAnEventWithinAWeek() {
|
||||
assertTrue(startsWithinAWeek(now + 3 * TimeUtils.ONE_DAY, now))
|
||||
assertTrue(startsWithinAWeek(now + TimeUtils.ONE_WEEK, now))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun showsForAnEventThatAlreadyStarted() {
|
||||
assertTrue(startsWithinAWeek(now - TimeUtils.ONE_HOUR, now))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun hidesPastAWeekAndWithoutAStart() {
|
||||
assertFalse(startsWithinAWeek(now + TimeUtils.ONE_WEEK + 1, now))
|
||||
assertFalse(startsWithinAWeek(now + 33 * TimeUtils.ONE_DAY, now))
|
||||
assertFalse(startsWithinAWeek(null, now))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user