Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/main/java/com/alamkanak/weekview/Renderers.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alamkanak.weekview

import android.graphics.Canvas
import java.util.Calendar

internal interface Updater {
fun update()
Expand All @@ -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)
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/com/alamkanak/weekview/ViewState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 24 additions & 22 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<T> : WeekView.SimpleAdapter<T>() {
final override fun onEmptyViewClick(time: Calendar) {
onEmptyViewClick(time.toLocalDateTime())
Expand Down Expand Up @@ -67,6 +69,7 @@ abstract class WeekViewSimpleAdapterJodaTime<T> : WeekView.SimpleAdapter<T>() {
*
* @param T The type of elements that are displayed in the corresponding [WeekView].
*/
@PublicApi
abstract class WeekViewPagingAdapterJodaTime<T> : WeekView.PagingAdapter<T>() {

final override fun onEmptyViewClick(time: Calendar) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T : Any> WeekViewEntity.Event.Builder<T>.setStartTime(
startTime: LocalDateTime
) = setStartTime(startTime.toCalendar())

@PublicApi
fun <T : Any> WeekViewEntity.Event.Builder<T>.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())
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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()

Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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()) }
}
5 changes: 4 additions & 1 deletion jsr310/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<T> : WeekView.SimpleAdapter<T>() {
final override fun onEmptyViewClick(time: Calendar) {
onEmptyViewClick(time.toLocalDateTime())
Expand Down Expand Up @@ -67,7 +69,8 @@ abstract class WeekViewSimpleAdapterJsr310<T> : WeekView.SimpleAdapter<T>() {
*
* @param T The type of elements that are displayed in the corresponding [WeekView].
*/
abstract class WeekViewPagingAdapterJodaTime<T> : WeekView.PagingAdapter<T>() {
@PublicApi
abstract class WeekViewPagingAdapterJsr310<T> : WeekView.PagingAdapter<T>() {

final override fun onEmptyViewClick(time: Calendar) {
onEmptyViewClick(time.toLocalDateTime())
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T : Any> WeekViewEntity.Event.Builder<T>.setStartTime(
startTime: LocalDateTime
) = setStartTime(startTime.toCalendar())

@PublicApi
fun <T : Any> WeekViewEntity.Event.Builder<T>.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())
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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()

Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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()) }
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<T> : WeekView.SimpleAdapter<T>() {

final override fun onEmptyViewClick(time: Calendar) {
Expand Down Expand Up @@ -68,6 +70,7 @@ abstract class WeekViewSimpleAdapterThreeTenAbp<T> : WeekView.SimpleAdapter<T>()
*
* @param T The type of elements that are displayed in the corresponding [WeekView].
*/
@PublicApi
abstract class WeekViewPagingAdapterThreeTenAbp<T> : WeekView.PagingAdapter<T>() {

final override fun onEmptyViewClick(time: Calendar) {
Expand Down
Loading