Skip to content

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thellmund committed Apr 15, 2022
1 parent 6cfadf2 commit b3b5e8e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/com/alamkanak/weekview/CalendarExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ internal fun Calendar.plusDays(days: Int): Calendar {
}
}

internal fun Calendar.plusHours(hours: Int): Calendar {
return copy().apply {
add(Calendar.HOUR_OF_DAY, hours)
}
}

internal fun Calendar.addDays(days: Int) {
add(Calendar.DATE, days)
}
Expand All @@ -53,6 +59,12 @@ internal fun Calendar.minusDays(days: Int): Calendar {
}
}

internal fun Calendar.minusHours(hours: Int): Calendar {
return copy().apply {
add(Calendar.HOUR_OF_DAY, hours * -1)
}
}

internal fun Calendar.plusMillis(millis: Int): Calendar {
return copy().apply {
add(Calendar.MILLISECOND, millis)
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/alamkanak/weekview/WeekView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class WeekView @JvmOverloads constructor(
var headerBottomShadowColor: Int
@RequiresApi(api = 29)
get() = viewState.headerBackgroundWithShadowPaint.shadowLayerColor
@RequiresApi(api = 29)
set(value) {
val paint = viewState.headerBackgroundWithShadowPaint
paint.setShadowLayer(headerBottomShadowRadius.toFloat(), 0f, 0f, value)
Expand All @@ -367,6 +368,7 @@ class WeekView @JvmOverloads constructor(
var headerBottomShadowRadius: Int
@RequiresApi(api = 29)
get() = viewState.headerBackgroundWithShadowPaint.shadowLayerRadius.roundToInt()
@RequiresApi(api = 29)
set(value) {
val paint = viewState.headerBackgroundWithShadowPaint
paint.setShadowLayer(value.toFloat(), 0f, 0f, headerBottomShadowColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class WeekViewEventSplitterTest {
whenever(viewState.maxHour).thenReturn(24)

val startTime = today().withHour(11)
val endTime = startTime + Hours(2)
val endTime = startTime.plusHours(2)
val event = Mocks.weekViewItem(startTime, endTime)

val results = event.split(viewState)
Expand Down Expand Up @@ -51,7 +51,7 @@ class WeekViewEventSplitterTest {

val event = Mocks.weekViewItem(
startTime = today().withHour(22),
endTime = today().plus(Days(1)).withHour(6)
endTime = today().plusDays(1).withHour(6)
)

val results = event.split(viewState)
Expand Down Expand Up @@ -107,7 +107,7 @@ class WeekViewEventSplitterTest {
whenever(viewState.maxHour).thenReturn(24)

val startTime = today().withHour(11)
val endTime = (startTime + Days(1)).withHour(2)
val endTime = (startTime.plusDays(1)).withHour(2)

val event = Mocks.weekViewItem(startTime, endTime)
val results = event.split(viewState)
Expand All @@ -132,12 +132,12 @@ class WeekViewEventSplitterTest {
whenever(viewState.maxHour).thenReturn(maxHour)

val startTime = today().withHour(5)
val endTime = (startTime + Days(2)).withHour(23)
val endTime = (startTime.plusDays(2)).withHour(23)

val event = Mocks.weekViewItem(startTime, endTime)
val results = event.split(viewState)

val tomorrow = today() + Days(1)
val tomorrow = today().plusDays(1)
val expected = listOf(
Event(startTime.withHour(minHour), startTime.withTimeAtEndOfPeriod(maxHour)),
Event(tomorrow.withHour(minHour), tomorrow.withTimeAtEndOfPeriod(maxHour)),
Expand All @@ -159,7 +159,7 @@ class WeekViewEventSplitterTest {
whenever(viewState.maxHour).thenReturn(maxHour)

val startTime = today().withHour(8)
val endTime = (startTime + Days(1)).withHour(5)
val endTime = (startTime.plusDays(1)).withHour(5)

val event = Mocks.weekViewItem(startTime, endTime)
val results = event.split(viewState)
Expand All @@ -183,7 +183,7 @@ class WeekViewEventSplitterTest {
whenever(viewState.maxHour).thenReturn(maxHour)

val startTime = today().withHour(22)
val endTime = (startTime + Days(1)).withHour(9)
val endTime = (startTime.plusDays(1)).withHour(9)

val event = Mocks.weekViewItem(startTime, endTime)
val results = event.split(viewState)
Expand All @@ -204,12 +204,12 @@ class WeekViewEventSplitterTest {
whenever(viewState.maxHour).thenReturn(24)

val startTime = today().withHour(11)
val endTime = (startTime + Days(2)).withHour(2)
val endTime = (startTime.plusDays(2)).withHour(2)

val event = Mocks.weekViewItem(startTime, endTime)
val results = event.split(viewState)

val intermediateDate = startTime + Days(1)
val intermediateDate = startTime.plusDays(1)
val expected = listOf(
Event(startTime, startTime.atEndOfDay),
Event(intermediateDate.atStartOfDay, intermediateDate.atEndOfDay),
Expand Down
28 changes: 14 additions & 14 deletions core/src/test/java/com/alamkanak/weekview/WeekViewEventTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class WeekViewEventTest {

@Test
fun `single-day event is recognized correctly`() {
val startTime = (today() + Days(1)).withHour(6).withMinutes(0)
val endTime = startTime + Hours(10)
val startTime = (today().plusDays(1)).withHour(6).withMinutes(0)
val endTime = startTime.plusHours(10)

val originalEvent = Mocks.weekViewItem(startTime, endTime)

Expand All @@ -39,8 +39,8 @@ class WeekViewEventTest {

@Test
fun `two-day event is recognized correctly`() {
val startTime = (today() + Days(1)).withHour(14).withMinutes(0)
val endTime = (today() + Days(2)).withHour(14).withMinutes(0)
val startTime = (today().plusDays(1)).withHour(14).withMinutes(0)
val endTime = (today().plusDays(2)).withHour(14).withMinutes(0)

val originalEvent = Mocks.weekViewItem(startTime, endTime)
val eventChips = factory.create(listOf(originalEvent), viewState)
Expand All @@ -58,8 +58,8 @@ class WeekViewEventTest {

@Test
fun `multi-day event is recognized correctly`() {
val startTime = (today() + Days(1)).withHour(14).withMinutes(0)
val endTime = (today() + Days(3)).withHour(1).withMinutes(0)
val startTime = (today().plusDays(1)).withHour(14).withMinutes(0)
val endTime = (today().plusDays(3)).withHour(1).withMinutes(0)

val originalEvent = Mocks.weekViewItem(startTime, endTime)
val eventChips = factory.create(listOf(originalEvent), viewState)
Expand All @@ -79,11 +79,11 @@ class WeekViewEventTest {
@Test
fun `non-colliding events are recognized correctly`() {
val firstStartTime = now()
val firstEndTime = firstStartTime + Hours(1)
val firstEndTime = firstStartTime.plusHours(1)
val first = Mocks.weekViewItem(firstStartTime, firstEndTime)

val secondStartTime = firstStartTime + Hours(2)
val secondEndTime = secondStartTime + Hours(1)
val secondStartTime = firstStartTime.plusHours(2)
val secondEndTime = secondStartTime.plusHours(1)
val second = Mocks.weekViewItem(secondStartTime, secondEndTime)

assertFalse(first.collidesWith(second))
Expand All @@ -92,11 +92,11 @@ class WeekViewEventTest {
@Test
fun `overlapping events are recognized as colliding`() {
val firstStartTime = now()
val firstEndTime = firstStartTime + Hours(1)
val firstEndTime = firstStartTime.plusHours(1)
val first = Mocks.weekViewItem(firstStartTime, firstEndTime)

val secondStartTime = firstStartTime - Hours(1)
val secondEndTime = firstEndTime + Hours(1)
val secondStartTime = firstStartTime.minusHours(1)
val secondEndTime = firstEndTime.plusHours(1)
val second = Mocks.weekViewItem(secondStartTime, secondEndTime)

assertTrue(first.collidesWith(second))
Expand All @@ -105,11 +105,11 @@ class WeekViewEventTest {
@Test
fun `partly-overlapping events are recognized as colliding`() {
val firstStartTime = now().withMinutes(0)
val firstEndTime = firstStartTime + Hours(1)
val firstEndTime = firstStartTime.plusHours(1)
val first = Mocks.weekViewItem(firstStartTime, firstEndTime)

val secondStartTime = firstStartTime.withMinutes(30)
val secondEndTime = secondStartTime + Hours(1)
val secondEndTime = secondStartTime.plusHours(1)
val second = Mocks.weekViewItem(secondStartTime, secondEndTime)

assertTrue(first.collidesWith(second))
Expand Down

0 comments on commit b3b5e8e

Please sign in to comment.