From 5ff48ba310c44664551a816d4d63df3e2419a657 Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Mon, 6 May 2019 10:38:05 +0200 Subject: [PATCH] Update README.md --- README.md | 77 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 88a20d6b9..a781926d4 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,13 @@ Usage // build.gradle (project-level) allprojects { repositories { - ... + // ... maven { url 'https://jitpack.io' } } } // build.gradle (app-level) -implementation 'com.github.thellmund:Android-Week-View:3.3' +implementation 'com.github.thellmund:Android-Week-View:3.4' ``` 2. Add `WeekView` in your XML layout. @@ -35,6 +35,7 @@ implementation 'com.github.thellmund:Android-Week-View:3.3' android:id="@+id/weekView" android:layout_width="match_parent" android:layout_height="match_parent" + app:defaultEventColor="@color/primaryColor" app:eventTextColor="@color/white" app:timeColumnTextSize="12sp" app:hourHeight="60dp" @@ -50,50 +51,52 @@ implementation 'com.github.thellmund:Android-Week-View:3.3' ``` 3. Prepare the class of objects that you want to display in `WeekView` by implementing `WeekViewDisplayable`. -```java -public class CalendarItem implements WeekViewDisplayable { - - private long id; - private String title; - private DateTime startTime; - private DateTime endTime; - private String location; - private int color; - - /* ... */ - - @Override - public WeekViewEvent toWeekViewEvent() { - // Note: It's important to pass "this" as the last argument to WeekViewEvent's constructor. - // This way, the EventClickListener can return this object in its onEventClick() method. - boolean isAllDay = DateUtils.isAllDay(startTime, endTime); - return new WeekViewEvent<>( - id, title, startTime.toGregorianCalendar(), - endTime.toGregorianCalendar(), location, color, isAllDay, this - ); +```kotlin +class Event( + val id: Long, + val title: String, + val startTime: Calendar, + val endTime: Calendar, + val location: String, + val color: Int, + val isAllDay: Boolean, + val isCanceled: Boolean +) : WeekViewDisplayable { + + override fun toWeekViewEvent(): WeekViewEvent { + val style = WeekViewEvent.Style.Builder() + .setBackgroundColor(color) + .setTextStrikeThrough(isCanceled) + .build() + + return WeekViewEvent.Builder() + .setId(id) + .setTitle(title) + .setStartTime(startTime) + .setEndTime(endTime) + .setLocation(location) + .setAllDay(isAllDay) + .setStyle(style) + .setData(this) // This is necessary for onEventClick(data) to work + .build() } } + ``` 4. Configure `WeekView` in code. -```java -WeekView weekView = (WeekView) findViewById(R.id.weekView); -weekView.setOnEventClickListener(new EventClickListener() { - @Override - public void onEventClick(CalendarItem event, RectF eventRect) { - // Do something with the CalendarItem - } -}); +```kotlin +val weekView = findViewById(R.id.weekView) +weekView.setOnEventClickListener { calendarItem, eventRect -> + // ... +} // WeekView has infinite horizontal scrolling. Therefore, you need to provide the events // of a month whenever that the currently displayed month changes. -weekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() { - @Override - public List> onMonthChange(Calendar startDate, Calendar endDate) { - return mDatabase.getCalendarItemsInRange(startDate, endDate); - } -}); +weekView.setMonthChangeListener { startDate, endDate -> + database.getCalendarItemsInRange(startDate, endDate) +} ``` ---