diff --git a/core/src/main/java/com/alamkanak/weekview/Renderers.kt b/core/src/main/java/com/alamkanak/weekview/Renderers.kt index f0180e907..6ab607666 100644 --- a/core/src/main/java/com/alamkanak/weekview/Renderers.kt +++ b/core/src/main/java/com/alamkanak/weekview/Renderers.kt @@ -1,6 +1,7 @@ package com.alamkanak.weekview import android.graphics.Canvas +import java.util.Calendar internal interface Updater { fun update() @@ -10,10 +11,14 @@ internal interface Drawer { fun draw(canvas: Canvas) } +typealias DateFormatter = (Calendar) -> String + internal interface DateFormatterDependent { fun onDateFormatterChanged(formatter: DateFormatter) } +typealias TimeFormatter = (Int) -> String + internal interface TimeFormatterDependent { fun onTimeFormatterChanged(formatter: TimeFormatter) } diff --git a/core/src/main/java/com/alamkanak/weekview/ViewState.kt b/core/src/main/java/com/alamkanak/weekview/ViewState.kt index 9f866c957..da126a43b 100644 --- a/core/src/main/java/com/alamkanak/weekview/ViewState.kt +++ b/core/src/main/java/com/alamkanak/weekview/ViewState.kt @@ -13,9 +13,6 @@ import kotlin.math.ceil import kotlin.math.max import kotlin.math.min -typealias DateFormatter = (Calendar) -> String -typealias TimeFormatter = (Int) -> String - internal class ViewState { // View diff --git a/dependencies.gradle b/dependencies.gradle index 9c7941332..3d2ec55aa 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -3,34 +3,36 @@ ext { buildConfig = [ minSdk : 15, - minSdkJsr310: 26, + minSdkJsr310: 21, compileSdk : 30, targetSdk : 30, ] versions = [ - androidxjUnit : '1.1.1', - androidxTestRunner: '1.2.0', - appCompat : '1.1.0', - emoji : '1.1.0', - jodaTime : '2.10.6', - jodaTimeAndroid : '2.10.6', - jUnit : '4.13', - kotlin : '1.4.21', - mockito : '3.3.3', - robolectric : '4.3.1', - startup : '1.0.0', - threeTen : '1.4.4', - threeTenAbp : '1.2.4', + androidxjUnit : '1.1.1', + androidxTestRunner : '1.2.0', + appCompat : '1.1.0', + coreLibraryDesugaring: '1.1.1', + emoji : '1.1.0', + jodaTime : '2.10.6', + jodaTimeAndroid : '2.10.6', + jUnit : '4.13', + kotlin : '1.4.21', + mockito : '3.3.3', + robolectric : '4.3.1', + startup : '1.0.0', + threeTen : '1.4.4', + threeTenAbp : '1.2.4', ] libraries = [ - appCompat : "androidx.appcompat:appcompat:${versions.appCompat}", - emoji : "androidx.emoji:emoji-bundled:${versions.emoji}", - jodaTime : "joda-time:joda-time:${versions.jodaTime}", - jodaTimeAndroid: "net.danlew:android.joda:${versions.jodaTimeAndroid}", - kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}", - startup : "androidx.startup:startup-runtime:${versions.startup}", - threeTen : "org.threeten:threetenbp:${versions.threeTen}", - threeTenAbp : "com.jakewharton.threetenabp:threetenabp:${versions.threeTenAbp}", + appCompat : "androidx.appcompat:appcompat:${versions.appCompat}", + coreLibraryDesugaring: "com.android.tools:desugar_jdk_libs:${versions.coreLibraryDesugaring}", + emoji : "androidx.emoji:emoji-bundled:${versions.emoji}", + jodaTime : "joda-time:joda-time:${versions.jodaTime}", + jodaTimeAndroid : "net.danlew:android.joda:${versions.jodaTimeAndroid}", + kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}", + startup : "androidx.startup:startup-runtime:${versions.startup}", + threeTen : "org.threeten:threetenbp:${versions.threeTen}", + threeTenAbp : "com.jakewharton.threetenabp:threetenabp:${versions.threeTenAbp}", ] testing = [ androidxjUnit : "androidx.test.ext:junit:${versions.androidxjUnit}", diff --git a/jodatime/src/main/java/com/alamkanak/weekview/jodatime/JodaTimeAdapters.kt b/jodatime/src/main/java/com/alamkanak/weekview/jodatime/JodaTimeAdapters.kt index fced040e7..adc4a685a 100644 --- a/jodatime/src/main/java/com/alamkanak/weekview/jodatime/JodaTimeAdapters.kt +++ b/jodatime/src/main/java/com/alamkanak/weekview/jodatime/JodaTimeAdapters.kt @@ -1,5 +1,6 @@ package com.alamkanak.weekview.jodatime +import com.alamkanak.weekview.PublicApi import com.alamkanak.weekview.WeekView import java.util.Calendar import org.joda.time.LocalDate @@ -15,6 +16,7 @@ import org.joda.time.LocalDateTime * * @param T The type of elements that are displayed in the corresponding [WeekView]. */ +@PublicApi abstract class WeekViewSimpleAdapterJodaTime : WeekView.SimpleAdapter() { final override fun onEmptyViewClick(time: Calendar) { onEmptyViewClick(time.toLocalDateTime()) @@ -67,6 +69,7 @@ abstract class WeekViewSimpleAdapterJodaTime : WeekView.SimpleAdapter() { * * @param T The type of elements that are displayed in the corresponding [WeekView]. */ +@PublicApi abstract class WeekViewPagingAdapterJodaTime : WeekView.PagingAdapter() { final override fun onEmptyViewClick(time: Calendar) { diff --git a/jodatime/src/main/java/com/alamkanak/weekview/jodatime/WeekViewExtensions.kt b/jodatime/src/main/java/com/alamkanak/weekview/jodatime/WeekViewExtensions.kt index d805ba11a..4f22a9e14 100644 --- a/jodatime/src/main/java/com/alamkanak/weekview/jodatime/WeekViewExtensions.kt +++ b/jodatime/src/main/java/com/alamkanak/weekview/jodatime/WeekViewExtensions.kt @@ -1,23 +1,28 @@ package com.alamkanak.weekview.jodatime +import com.alamkanak.weekview.PublicApi import com.alamkanak.weekview.WeekView import com.alamkanak.weekview.WeekViewEntity import org.joda.time.LocalDate import org.joda.time.LocalDateTime import org.joda.time.LocalTime +@PublicApi fun WeekViewEntity.Event.Builder.setStartTime( startTime: LocalDateTime ) = setStartTime(startTime.toCalendar()) +@PublicApi fun WeekViewEntity.Event.Builder.setEndTime( endTime: LocalDateTime ) = setEndTime(endTime.toCalendar()) +@PublicApi fun WeekViewEntity.BlockedTime.Builder.setStartTime( startTime: LocalDateTime ) = setStartTime(startTime.toCalendar()) +@PublicApi fun WeekViewEntity.BlockedTime.Builder.setEndTime( endTime: LocalDateTime ) = setEndTime(endTime.toCalendar()) @@ -26,6 +31,7 @@ fun WeekViewEntity.BlockedTime.Builder.setEndTime( * Returns the minimum date that [WeekView] will display as a [LocalDate], or null if none is set. * Events before this date will not be shown. */ +@PublicApi var WeekView.minDateAsLocalDate: LocalDate? get() = minDate?.toLocalDate() set(value) { @@ -36,6 +42,7 @@ var WeekView.minDateAsLocalDate: LocalDate? * Returns the maximum date that [WeekView] will display as a [LocalDate], or null if none is set. * Events after this date will not be shown. */ +@PublicApi var WeekView.maxDateAsLocalDate: LocalDate? get() = maxDate?.toLocalDate() set(value) { @@ -45,12 +52,14 @@ var WeekView.maxDateAsLocalDate: LocalDate? /** * Returns the first visible date as a [LocalDate]. */ +@PublicApi val WeekView.firstVisibleDateAsLocalDate: LocalDate get() = firstVisibleDate.toLocalDate() /** * Returns the last visible date as a [LocalDate]. */ +@PublicApi val WeekView.lastVisibleDateAsLocalDate: LocalDate get() = lastVisibleDate.toLocalDate() @@ -74,6 +83,7 @@ fun WeekView.goToDate(date: LocalDate) { * * @param date The [LocalDate] to scroll to. */ +@PublicApi fun WeekView.scrollToDate(date: LocalDate) { scrollToDate(date.toCalendar()) } @@ -85,6 +95,7 @@ fun WeekView.scrollToDate(date: LocalDate) { * * @param dateTime The [LocalDateTime] to scroll to. */ +@PublicApi fun WeekView.scrollToDateTime(dateTime: LocalDateTime) { scrollToDateTime(dateTime.toCalendar()) } @@ -95,10 +106,12 @@ fun WeekView.scrollToDateTime(dateTime: LocalDateTime) { * * @param time The [LocalTime] to scroll to. */ +@PublicApi fun WeekView.scrollToTime(time: LocalTime) { scrollToTime(time.hourOfDay, time.secondOfMinute) } +@PublicApi fun WeekView.setDateFormatter(formatter: (LocalDate) -> String) { setDateFormatter { formatter(it.toLocalDate()) } } diff --git a/jsr310/build.gradle b/jsr310/build.gradle index 5c407b54e..cbdbc2cdb 100644 --- a/jsr310/build.gradle +++ b/jsr310/build.gradle @@ -10,19 +10,22 @@ android { defaultConfig { minSdkVersion buildConfig.minSdkJsr310 targetSdkVersion buildConfig.targetSdk + multiDexEnabled true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 + coreLibraryDesugaringEnabled true } } dependencies { implementation project(':core') - implementation libraries.kotlin implementation libraries.appCompat + coreLibraryDesugaring libraries.coreLibraryDesugaring + testImplementation testing.jUnit testImplementation testing.mockitoCore testImplementation testing.mockitoInline diff --git a/jsr310/src/main/java/com/alamkanak/weekview/jsr310/Jsr310Adapters.kt b/jsr310/src/main/java/com/alamkanak/weekview/jsr310/Jsr310Adapters.kt index 242ac09de..973f79243 100644 --- a/jsr310/src/main/java/com/alamkanak/weekview/jsr310/Jsr310Adapters.kt +++ b/jsr310/src/main/java/com/alamkanak/weekview/jsr310/Jsr310Adapters.kt @@ -1,5 +1,6 @@ package com.alamkanak.weekview.jsr310 +import com.alamkanak.weekview.PublicApi import com.alamkanak.weekview.WeekView import java.time.LocalDate import java.time.LocalDateTime @@ -15,6 +16,7 @@ import java.util.Calendar * * @param T The type of elements that are displayed in the corresponding [WeekView]. */ +@PublicApi abstract class WeekViewSimpleAdapterJsr310 : WeekView.SimpleAdapter() { final override fun onEmptyViewClick(time: Calendar) { onEmptyViewClick(time.toLocalDateTime()) @@ -67,7 +69,8 @@ abstract class WeekViewSimpleAdapterJsr310 : WeekView.SimpleAdapter() { * * @param T The type of elements that are displayed in the corresponding [WeekView]. */ -abstract class WeekViewPagingAdapterJodaTime : WeekView.PagingAdapter() { +@PublicApi +abstract class WeekViewPagingAdapterJsr310 : WeekView.PagingAdapter() { final override fun onEmptyViewClick(time: Calendar) { onEmptyViewClick(time.toLocalDateTime()) diff --git a/jsr310/src/main/java/com/alamkanak/weekview/jsr310/WeekViewExtensions.kt b/jsr310/src/main/java/com/alamkanak/weekview/jsr310/WeekViewExtensions.kt index 548e69eb1..a6f7c2725 100644 --- a/jsr310/src/main/java/com/alamkanak/weekview/jsr310/WeekViewExtensions.kt +++ b/jsr310/src/main/java/com/alamkanak/weekview/jsr310/WeekViewExtensions.kt @@ -1,23 +1,28 @@ package com.alamkanak.weekview.jsr310 +import com.alamkanak.weekview.PublicApi import com.alamkanak.weekview.WeekView import com.alamkanak.weekview.WeekViewEntity import java.time.LocalDate import java.time.LocalDateTime import java.time.LocalTime +@PublicApi fun WeekViewEntity.Event.Builder.setStartTime( startTime: LocalDateTime ) = setStartTime(startTime.toCalendar()) +@PublicApi fun WeekViewEntity.Event.Builder.setEndTime( endTime: LocalDateTime ) = setEndTime(endTime.toCalendar()) +@PublicApi fun WeekViewEntity.BlockedTime.Builder.setStartTime( startTime: LocalDateTime ) = setStartTime(startTime.toCalendar()) +@PublicApi fun WeekViewEntity.BlockedTime.Builder.setEndTime( endTime: LocalDateTime ) = setEndTime(endTime.toCalendar()) @@ -26,6 +31,7 @@ fun WeekViewEntity.BlockedTime.Builder.setEndTime( * Returns the minimum date that [WeekView] will display as a [LocalDate], or null if none is set. * Events before this date will not be shown. */ +@PublicApi var WeekView.minDateAsLocalDate: LocalDate? get() = minDate?.toLocalDate() set(value) { @@ -36,6 +42,7 @@ var WeekView.minDateAsLocalDate: LocalDate? * Returns the maximum date that [WeekView] will display as a [LocalDate], or null if none is set. * Events after this date will not be shown. */ +@PublicApi var WeekView.maxDateAsLocalDate: LocalDate? get() = maxDate?.toLocalDate() set(value) { @@ -45,12 +52,14 @@ var WeekView.maxDateAsLocalDate: LocalDate? /** * Returns the first visible date as a [LocalDate]. */ +@PublicApi val WeekView.firstVisibleDateAsLocalDate: LocalDate get() = firstVisibleDate.toLocalDate() /** * Returns the last visible date as a [LocalDate]. */ +@PublicApi val WeekView.lastVisibleDateAsLocalDate: LocalDate get() = lastVisibleDate.toLocalDate() @@ -74,6 +83,7 @@ fun WeekView.goToDate(date: LocalDate) { * * @param date The [LocalDate] to scroll to. */ +@PublicApi fun WeekView.scrollToDate(date: LocalDate) { scrollToDate(date.toCalendar()) } @@ -85,6 +95,7 @@ fun WeekView.scrollToDate(date: LocalDate) { * * @param dateTime The [LocalDateTime] to scroll to. */ +@PublicApi fun WeekView.scrollToDateTime(dateTime: LocalDateTime) { scrollToDateTime(dateTime.toCalendar()) } @@ -95,10 +106,12 @@ fun WeekView.scrollToDateTime(dateTime: LocalDateTime) { * * @param time The [LocalTime] to scroll to. */ +@PublicApi fun WeekView.scrollToTime(time: LocalTime) { scrollToTime(time.hour, time.minute) } +@PublicApi fun WeekView.setDateFormatter(formatter: (LocalDate) -> String) { setDateFormatter { formatter(it.toLocalDate()) } } diff --git a/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/ThreeTenAbpAdapters.kt b/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/ThreeTenAbpAdapters.kt index 475fcc160..bec8eff29 100644 --- a/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/ThreeTenAbpAdapters.kt +++ b/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/ThreeTenAbpAdapters.kt @@ -1,5 +1,6 @@ package com.alamkanak.weekview.threetenabp +import com.alamkanak.weekview.PublicApi import com.alamkanak.weekview.WeekView import java.util.Calendar import org.threeten.bp.LocalDate @@ -15,6 +16,7 @@ import org.threeten.bp.LocalDateTime * * @param T The type of elements that are displayed in the corresponding [WeekView]. */ +@PublicApi abstract class WeekViewSimpleAdapterThreeTenAbp : WeekView.SimpleAdapter() { final override fun onEmptyViewClick(time: Calendar) { @@ -68,6 +70,7 @@ abstract class WeekViewSimpleAdapterThreeTenAbp : WeekView.SimpleAdapter() * * @param T The type of elements that are displayed in the corresponding [WeekView]. */ +@PublicApi abstract class WeekViewPagingAdapterThreeTenAbp : WeekView.PagingAdapter() { final override fun onEmptyViewClick(time: Calendar) { diff --git a/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/WeekViewExtensions.kt b/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/WeekViewExtensions.kt index d343b8450..6bdab77e0 100644 --- a/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/WeekViewExtensions.kt +++ b/threetenabp/src/main/java/com/alamkanak/weekview/threetenabp/WeekViewExtensions.kt @@ -1,23 +1,28 @@ package com.alamkanak.weekview.threetenabp +import com.alamkanak.weekview.PublicApi import com.alamkanak.weekview.WeekView import com.alamkanak.weekview.WeekViewEntity import org.threeten.bp.LocalDate import org.threeten.bp.LocalDateTime import org.threeten.bp.LocalTime +@PublicApi fun WeekViewEntity.Event.Builder.setStartTime( startTime: LocalDateTime ) = setStartTime(startTime.toCalendar()) +@PublicApi fun WeekViewEntity.Event.Builder.setEndTime( endTime: LocalDateTime ) = setEndTime(endTime.toCalendar()) +@PublicApi fun WeekViewEntity.BlockedTime.Builder.setStartTime( startTime: LocalDateTime ) = setStartTime(startTime.toCalendar()) +@PublicApi fun WeekViewEntity.BlockedTime.Builder.setEndTime( endTime: LocalDateTime ) = setEndTime(endTime.toCalendar()) @@ -26,6 +31,7 @@ fun WeekViewEntity.BlockedTime.Builder.setEndTime( * Returns the minimum date that [WeekView] will display as a [LocalDate], or null if none is set. * Events before this date will not be shown. */ +@PublicApi var WeekView.minDateAsLocalDate: LocalDate? get() = minDate?.toLocalDate() set(value) { @@ -36,6 +42,7 @@ var WeekView.minDateAsLocalDate: LocalDate? * Returns the maximum date that [WeekView] will display as a [LocalDate], or null if none is set. * Events after this date will not be shown. */ +@PublicApi var WeekView.maxDateAsLocalDate: LocalDate? get() = maxDate?.toLocalDate() set(value) { @@ -45,12 +52,14 @@ var WeekView.maxDateAsLocalDate: LocalDate? /** * Returns the first visible date as a [LocalDate]. */ +@PublicApi val WeekView.firstVisibleDateAsLocalDate: LocalDate get() = firstVisibleDate.toLocalDate() /** * Returns the last visible date as a [LocalDate]. */ +@PublicApi val WeekView.lastVisibleDateAsLocalDate: LocalDate get() = lastVisibleDate.toLocalDate() @@ -74,6 +83,7 @@ fun WeekView.goToDate(date: LocalDate) { * * @param date The [LocalDate] to scroll to. */ +@PublicApi fun WeekView.scrollToDate(date: LocalDate) { scrollToDate(date.toCalendar()) } @@ -85,6 +95,7 @@ fun WeekView.scrollToDate(date: LocalDate) { * * @param dateTime The [LocalDateTime] to scroll to. */ +@PublicApi fun WeekView.scrollToDateTime(dateTime: LocalDateTime) { scrollToDateTime(dateTime.toCalendar()) } @@ -95,10 +106,12 @@ fun WeekView.scrollToDateTime(dateTime: LocalDateTime) { * * @param time The [LocalTime] to scroll to. */ +@PublicApi fun WeekView.scrollToTime(time: LocalTime) { scrollToTime(time.hour, time.minute) } +@PublicApi fun WeekView.setDateFormatter(formatter: (LocalDate) -> String) { setDateFormatter { formatter(it.toLocalDate()) } }